Skip to content

Commit

Permalink
Fix List Organizations V2 (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatascastro12 authored Aug 17, 2023
1 parent b5a267c commit 2667837
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
13 changes: 3 additions & 10 deletions tests/test_organizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def mock_organization_updated(self):

@pytest.fixture
def mock_organizations(self):

organization_list = [MockOrganization(id=str(i)).to_dict() for i in range(5000)]

return {
Expand All @@ -51,7 +50,6 @@ def mock_organizations(self):

@pytest.fixture
def mock_organizations_v2(self):

organization_list = [MockOrganization(id=str(i)).to_dict() for i in range(5000)]

dict_response = {
Expand All @@ -69,11 +67,10 @@ def mock_organizations_v2(self):
"method": Organizations.list_organizations_v2,
},
}
return self.organizations.construct_from_response(dict_response)
return dict_response

@pytest.fixture
def mock_organizations_with_limit(self):

organization_list = [MockOrganization(id=str(i)).to_dict() for i in range(4)]

return {
Expand All @@ -93,7 +90,6 @@ def mock_organizations_with_limit(self):

@pytest.fixture
def mock_organizations_with_limit_v2(self):

organization_list = [MockOrganization(id=str(i)).to_dict() for i in range(4)]

dict_response = {
Expand All @@ -107,14 +103,13 @@ def mock_organizations_with_limit_v2(self):
"after": None,
"order": None,
},
"method": Organizations.list_organizations,
"method": Organizations.list_organizations_v2,
},
}
return self.organizations.construct_from_response(dict_response)

@pytest.fixture
def mock_organizations_with_default_limit(self):

organization_list = [MockOrganization(id=str(i)).to_dict() for i in range(10)]

return {
Expand All @@ -135,7 +130,6 @@ def mock_organizations_with_default_limit(self):

@pytest.fixture
def mock_organizations_with_default_limit_v2(self):

organization_list = [MockOrganization(id=str(i)).to_dict() for i in range(10)]

dict_response = {
Expand All @@ -150,14 +144,13 @@ def mock_organizations_with_default_limit_v2(self):
"order": None,
"default_limit": True,
},
"method": Organizations.list_organizations,
"method": Organizations.list_organizations_v2,
},
}
return self.organizations.construct_from_response(dict_response)

@pytest.fixture
def mock_organizations_pagination_response(self):

organization_list = [MockOrganization(id=str(i)).to_dict() for i in range(4990)]

return {
Expand Down
12 changes: 5 additions & 7 deletions workos/organizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,20 +141,18 @@ def list_organizations_v2(
token=workos.api_key,
)

dict_response = response.to_dict()

dict_response["metadata"] = {
response["metadata"] = {
"params": params,
"method": Organizations.list_organizations_v2,
}

if "default_limit" in locals():
if "metadata" in dict_response and "params" in dict_response["metadata"]:
dict_response["metadata"]["params"]["default_limit"] = default_limit
if "metadata" in response and "params" in response["metadata"]:
response["metadata"]["params"]["default_limit"] = default_limit
else:
dict_response["metadata"] = {"params": {"default_limit": default_limit}}
response["metadata"] = {"params": {"default_limit": default_limit}}

return self.construct_from_response(dict_response)
return self.construct_from_response(response)

def get_organization(self, organization):
"""Gets details for a single Organization
Expand Down

0 comments on commit 2667837

Please sign in to comment.