-
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
Users.create_password_challenge()
method (#199)
- Loading branch information
1 parent
4212609
commit 04abda5
Showing
3 changed files
with
105 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 |
---|---|---|
@@ -1,6 +1,5 @@ | ||
import pytest | ||
|
||
import workos | ||
from tests.utils.fixtures.mock_session import MockSession | ||
from tests.utils.fixtures.mock_user import MockUser | ||
from workos.users import Users | ||
|
@@ -111,6 +110,15 @@ def mock_auth_response(self): | |
"session": session, | ||
} | ||
|
||
@pytest.fixture | ||
def mock_password_challenge_response(self): | ||
user = MockUser("user_01H7ZGXFP5C6BBQY6Z7277ZCT0").to_dict() | ||
|
||
return { | ||
"user": user, | ||
"token": "token_123", | ||
} | ||
|
||
def test_create_user(self, mock_user, mock_request_method): | ||
mock_request_method("post", mock_user, 201) | ||
|
||
|
@@ -279,3 +287,24 @@ def test_authenticate_with_code(self, capture_and_mock_request, mock_auth_respon | |
assert request["json"]["client_id"] == "client_b27needthisforssotemxo" | ||
assert request["json"]["client_secret"] == "sk_abdsomecharactersm284" | ||
assert request["json"]["grant_type"] == "authorization_code" | ||
|
||
def test_create_password_challenge( | ||
self, capture_and_mock_request, mock_password_challenge_response | ||
): | ||
email = "[email protected]" | ||
password_reset_url = "https://foo-corp.com/reset-password" | ||
|
||
url, request = capture_and_mock_request( | ||
"post", mock_password_challenge_response, 200 | ||
) | ||
|
||
response = self.users.create_password_reset_challenge( | ||
email=email, | ||
password_reset_url=password_reset_url, | ||
) | ||
|
||
assert url[0].endswith("users/password_reset_challenge") | ||
assert response["user"]["id"] == "user_01H7ZGXFP5C6BBQY6Z7277ZCT0" | ||
assert response["token"] == "token_123" | ||
assert request["json"]["email"] == email | ||
assert request["json"]["password_reset_url"] == password_reset_url |
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,33 @@ | ||
from workos.resources.base import WorkOSBaseResource | ||
from workos.resources.session import WorkOSSession | ||
from workos.resources.users import WorkOSUser | ||
|
||
|
||
class WorkOSPasswordChallengeResponse(WorkOSBaseResource): | ||
"""Representation of a User and token response as returned by WorkOS through User Management features. | ||
Attributes: | ||
OBJECT_FIELDS (list): List of fields a WorkOSPasswordChallengeResponse is comprised of. | ||
""" | ||
|
||
OBJECT_FIELDS = [ | ||
"token", | ||
] | ||
|
||
@classmethod | ||
def construct_from_response(cls, response): | ||
challenge_response = super( | ||
WorkOSPasswordChallengeResponse, cls | ||
).construct_from_response(response) | ||
|
||
user = WorkOSUser.construct_from_response(response["user"]) | ||
challenge_response.user = user | ||
|
||
return challenge_response | ||
|
||
def to_dict(self): | ||
challenge_response = super(WorkOSPasswordChallengeResponse, self).to_dict() | ||
|
||
user_dict = self.user.to_dict() | ||
challenge_response["user"] = user_dict | ||
|
||
return challenge_response |
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