Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix get_user, list_users, and delete_user methods #215

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions tests/test_user_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def mock_users(self):
"list_metadata": {"before": None, "after": None},
"metadata": {
"params": {
"organization": None,
"organization_id": None,
"email": None,
"limit": None,
"before": None,
Expand All @@ -45,7 +45,7 @@ def mock_users_with_limit(self):
"metadata": {
"params": {
"type": None,
"organization": None,
"organization_id": None,
"email": None,
"limit": 4,
"before": None,
Expand All @@ -67,7 +67,7 @@ def mock_users_with_default_limit(self):
"metadata": {
"params": {
"type": None,
"organization": None,
"organization_id": None,
"email": None,
"limit": None,
"before": None,
Expand Down Expand Up @@ -143,7 +143,7 @@ def test_get_user(self, mock_user, capture_and_mock_request):

user = self.user_management.get_user("user_01H7ZGXFP5C6BBQY6Z7277ZCT0")

assert url[0].endswith("users/user_01H7ZGXFP5C6BBQY6Z7277ZCT0")
assert url[0].endswith("user_management/users/user_01H7ZGXFP5C6BBQY6Z7277ZCT0")
assert user["id"] == "user_01H7ZGXFP5C6BBQY6Z7277ZCT0"

def test_list_users_auto_pagination(
Expand Down Expand Up @@ -179,19 +179,19 @@ def test_list_users_returns_metadata(

users = self.user_management.list_users(
email="[email protected]",
organization="foo-corp.com",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ooh boy we misunderstood this param haha 🤦‍♀️

organization_id="org_12345",
)

dict_users = users.to_dict()
assert dict_users["metadata"]["params"]["email"] == "[email protected]"
assert dict_users["metadata"]["params"]["organization"] == "foo-corp.com"
assert dict_users["metadata"]["params"]["organization_id"] == "org_12345"

def test_delete_user(self, capture_and_mock_request):
url, request_kwargs = capture_and_mock_request("delete", None, 200)

user = self.user_management.delete_user("user_01H7ZGXFP5C6BBQY6Z7277ZCT0")

assert url[0].endswith("users/user_01H7ZGXFP5C6BBQY6Z7277ZCT0")
assert url[0].endswith("user_management/users/user_01H7ZGXFP5C6BBQY6Z7277ZCT0")
assert user is None

def test_update_user(self, mock_user, capture_and_mock_request):
Expand Down
10 changes: 5 additions & 5 deletions workos/user_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
)
from workos.utils.validation import validate_settings, USER_MANAGEMENT_MODULE

USER_PATH = "users"
USER_DETAIL_PATH = "users/{0}"
USER_PATH = "user_management/users"
USER_DETAIL_PATH = "user_management/users/{0}"
USER_ORGANIZATION_PATH = "users/{0}/organization/{1}"
USER_PASSWORD_PATH = "users/{0}/password"
USER_AUTHENTICATE_PATH = "users/authenticate"
Expand Down Expand Up @@ -90,7 +90,7 @@ def get_user(self, user):
def list_users(
self,
email=None,
organization=None,
organization_id=None,
limit=None,
before=None,
after=None,
Expand All @@ -100,7 +100,7 @@ def list_users(

Kwargs:
email (str): Filter Users by their email. (Optional)
organization (list): Filter Users by the organization they are members of. (Optional)
organization_id (str): Filter Users by the organization they are members of. (Optional)
limit (int): Maximum number of records to return. (Optional)
before (str): Pagination cursor to receive records before a provided User ID. (Optional)
after (str): Pagination cursor to receive records after a provided User ID. (Optional)
Expand All @@ -118,7 +118,7 @@ def list_users(

params = {
"email": email,
"organization": organization,
"organization_id": organization_id,
"limit": limit,
"before": before,
"after": after,
Expand Down