-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add methods and events for email verification and password reset
- Loading branch information
1 parent
5789a21
commit 65d28b7
Showing
6 changed files
with
219 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,11 @@ | |
import workos | ||
|
||
from tests.utils.fixtures.mock_auth_factor_totp import MockAuthFactorTotp | ||
from tests.utils.fixtures.mock_email_verification import MockEmailVerification | ||
from tests.utils.fixtures.mock_invitation import MockInvitation | ||
from tests.utils.fixtures.mock_magic_auth import MockMagicAuth | ||
from tests.utils.fixtures.mock_organization_membership import MockOrganizationMembership | ||
from tests.utils.fixtures.mock_password_reset import MockPasswordReset | ||
from tests.utils.fixtures.mock_session import MockSession | ||
from tests.utils.fixtures.mock_user import MockUser | ||
from workos.user_management import UserManagement | ||
|
@@ -213,10 +215,18 @@ def mock_auth_factors(self): | |
} | ||
return dict_response | ||
|
||
@pytest.fixture | ||
def mock_email_verification(self): | ||
return MockEmailVerification("email_verification_ABCDE").to_dict() | ||
|
||
@pytest.fixture | ||
def mock_magic_auth(self): | ||
return MockMagicAuth("magic_auth_ABCDE").to_dict() | ||
|
||
@pytest.fixture | ||
def mock_password_reset(self): | ||
return MockPasswordReset("password_reset_ABCDE").to_dict() | ||
|
||
@pytest.fixture | ||
def mock_invitation(self): | ||
return MockInvitation("invitation_ABCDE").to_dict() | ||
|
@@ -869,16 +879,37 @@ def test_get_logout_url(self): | |
|
||
assert expected == result | ||
|
||
def test_get_password_reset(self, mock_password_reset, capture_and_mock_request): | ||
url, request_kwargs = capture_and_mock_request("get", mock_password_reset, 200) | ||
|
||
password_reset = self.user_management.get_password_reset("password_reset_ABCDE") | ||
|
||
assert url[0].endswith("user_management/password_reset/password_reset_ABCDE") | ||
assert password_reset["id"] == "password_reset_ABCDE" | ||
|
||
def test_create_password_reset(self, capture_and_mock_request, mock_password_reset): | ||
email = "[email protected]" | ||
url, _ = capture_and_mock_request("post", mock_password_reset, 201) | ||
|
||
password_reset = self.user_management.create_password_reset(email=email) | ||
|
||
assert url[0].endswith("user_management/password_reset") | ||
assert password_reset["email"] == email | ||
|
||
def test_send_password_reset_email(self, capture_and_mock_request): | ||
email = "[email protected]" | ||
password_reset_url = "https://foo-corp.com/reset-password" | ||
|
||
url, request = capture_and_mock_request("post", None, 200) | ||
|
||
response = self.user_management.send_password_reset_email( | ||
email=email, | ||
password_reset_url=password_reset_url, | ||
) | ||
with pytest.warns( | ||
DeprecationWarning, | ||
match="'send_password_reset_email' is deprecated. Please use 'create_password_reset' instead. This method will be removed in a future major version.", | ||
): | ||
response = self.user_management.send_password_reset_email( | ||
email=email, | ||
password_reset_url=password_reset_url, | ||
) | ||
|
||
assert url[0].endswith("user_management/password_reset/send") | ||
assert request["json"]["email"] == email | ||
|
@@ -901,6 +932,22 @@ def test_reset_password(self, capture_and_mock_request, mock_user): | |
assert request["json"]["token"] == token | ||
assert request["json"]["new_password"] == new_password | ||
|
||
def test_get_email_verification( | ||
self, mock_email_verification, capture_and_mock_request | ||
): | ||
url, request_kwargs = capture_and_mock_request( | ||
"get", mock_email_verification, 200 | ||
) | ||
|
||
email_verification = self.user_management.get_email_verification( | ||
"email_verification_ABCDE" | ||
) | ||
|
||
assert url[0].endswith( | ||
"user_management/email_verification/email_verification_ABCDE" | ||
) | ||
assert email_verification["id"] == "email_verification_ABCDE" | ||
|
||
def test_send_verification_email(self, capture_and_mock_request, mock_user): | ||
user_id = "user_01H7ZGXFP5C6BBQY6Z7277ZCT0" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import datetime | ||
from workos.resources.base import WorkOSBaseResource | ||
|
||
|
||
class MockEmailVerification(WorkOSBaseResource): | ||
def __init__(self, id): | ||
self.id = id | ||
self.user_id = "user_01HWZBQAY251RZ9BKB4RZW4D4A" | ||
self.email = "[email protected]" | ||
self.expires_at = datetime.datetime.now() | ||
self.code = "123456" | ||
self.created_at = datetime.datetime.now() | ||
self.updated_at = datetime.datetime.now() | ||
|
||
OBJECT_FIELDS = [ | ||
"id", | ||
"user_id", | ||
"email", | ||
"expires_at", | ||
"code", | ||
"created_at", | ||
"updated_at", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import datetime | ||
from workos.resources.base import WorkOSBaseResource | ||
|
||
|
||
class MockPasswordReset(WorkOSBaseResource): | ||
def __init__(self, id): | ||
self.id = id | ||
self.user_id = "user_01HWZBQAY251RZ9BKB4RZW4D4A" | ||
self.email = "[email protected]" | ||
self.password_reset_token = "Z1uX3RbwcIl5fIGJJJCXXisdI" | ||
self.password_reset_url = ( | ||
"https://your-app.com/reset-password?token=Z1uX3RbwcIl5fIGJJJCXXisdI" | ||
) | ||
self.expires_at = datetime.datetime.now() | ||
self.created_at = datetime.datetime.now() | ||
|
||
OBJECT_FIELDS = [ | ||
"id", | ||
"user_id", | ||
"email", | ||
"password_reset_token", | ||
"password_reset_url", | ||
"expires_at", | ||
"created_at", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters