Skip to content

Commit

Permalink
Add Users.send_verification_email() method
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatascastro12 committed Aug 22, 2023
1 parent 37959fe commit 0a88555
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
12 changes: 12 additions & 0 deletions tests/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,3 +324,15 @@ def test_complete_password_reset(self, capture_and_mock_request, mock_user):
assert response["id"] == "user_01H7ZGXFP5C6BBQY6Z7277ZCT0"
assert request["json"]["token"] == token
assert request["json"]["new_password"] == new_password

def test_send_verification_email(self, capture_and_mock_request, mock_user):
user = "user_01H7ZGXFP5C6BBQY6Z7277ZCT0"

url, _ = capture_and_mock_request("post", mock_user, 200)

response = self.users.send_verification_email(user=user)

assert url[0].endswith(
"users/user_01H7ZGXFP5C6BBQY6Z7277ZCT0/send_verification_email"
)
assert response["id"] == "user_01H7ZGXFP5C6BBQY6Z7277ZCT0"
27 changes: 26 additions & 1 deletion workos/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
USER_SESSION_TOKEN_PATH = "users/session/token"
USER_PASSWORD_RESET_CHALLENGE_PATH = "users/password_reset_challenge"
USER_PASSWORD_RESET_PATH = "users/password_reset"
USER_SEND_VERIFICATION_EMAIL_PATH = "users/{0}/send_verification_email"

RESPONSE_LIMIT = 10

Expand Down Expand Up @@ -390,7 +391,7 @@ def complete_password_reset(
new_password (str): The new password to be set for the user.
Returns:
dict: User response from WorkOS.
dict: User response from WorkOS.
"""

headers = {}
Expand All @@ -409,3 +410,27 @@ def complete_password_reset(
)

return WorkOSUser.construct_from_response(response).to_dict()

def send_verification_email(
self,
user,
):
"""Sends a verification email to the provided user.
Kwargs:
user (str): The unique ID of the User whose email address will be verified.
Returns:
dict: User response from WorkOS.
"""

headers = {}

response = self.request_helper.request(
USER_SEND_VERIFICATION_EMAIL_PATH.format(user),
method=REQUEST_METHOD_POST,
headers=headers,
token=workos.api_key,
)

return WorkOSUser.construct_from_response(response).to_dict()

0 comments on commit 0a88555

Please sign in to comment.