diff --git a/tests/test_organizations.py b/tests/test_organizations.py index d37aa5ac..ecfa9fe2 100644 --- a/tests/test_organizations.py +++ b/tests/test_organizations.py @@ -27,6 +27,21 @@ def mock_organization(self): ], } + @pytest.fixture + def mock_organization_updated(self): + return { + "name": "Example Organization", + "object": "organization", + "id": "org_01EHT88Z8J8795GZNQ4ZP1J81T", + "domains": [ + { + "domain": "example.io", + "object": "organization_domain", + "id": "org_domain_01EHT88Z8WZEFWYPM6EC9BX2R8", + } + ], + } + @pytest.fixture def mock_organizations(self): return { @@ -90,3 +105,26 @@ def test_create_organization(self, mock_organization, mock_request_method): assert subject["id"] == "org_01EHT88Z8J8795GZNQ4ZP1J81T" assert subject["name"] == "Test Organization" + + def test_update_organization(self, mock_organization_updated, mock_request_method): + mock_response = Response() + mock_response.status_code = 201 + mock_response.response_dict = mock_organization_updated + mock_request_method("put", mock_response, 201) + + result = self.organizations.update_organization( + organization="org_01EHT88Z8J8795GZNQ4ZP1J81T", + name="Example Organization", + domains=["example.io"], + ) + subject = result.response_dict + + assert subject["id"] == "org_01EHT88Z8J8795GZNQ4ZP1J81T" + assert subject["name"] == "Example Organization" + assert subject["domains"] == [ + { + "domain": "example.io", + "object": "organization_domain", + "id": "org_domain_01EHT88Z8WZEFWYPM6EC9BX2R8", + } + ] diff --git a/workos/organizations.py b/workos/organizations.py index a548a38a..7c4555c1 100644 --- a/workos/organizations.py +++ b/workos/organizations.py @@ -1,5 +1,10 @@ import workos -from workos.utils.request import RequestHelper, REQUEST_METHOD_GET, REQUEST_METHOD_POST +from workos.utils.request import ( + RequestHelper, + REQUEST_METHOD_GET, + REQUEST_METHOD_POST, + REQUEST_METHOD_PUT, +) from workos.utils.validation import ORGANIZATIONS_MODULE, validate_settings ORGANIZATIONS_PATH = "organizations" @@ -74,3 +79,25 @@ def create_organization(self, organization): params=organization, token=workos.api_key, ) + + def update_organization(self, organization, name, domains=None): + """Update an organization + + Args: + organization(str) - Organization's unique identifier. + name (str) - A unique, descriptive name for the organization. + domains (list) - List of domains that belong to the organization. (Optional) + + Returns: + dict: Updated Organization response from WorkOS. + """ + params = { + "domains": domains, + "name": name, + } + return self.request_helper.request( + "organizations/{organization}".format(organization=organization), + method=REQUEST_METHOD_PUT, + params=params, + token=workos.api_key, + ) diff --git a/workos/utils/request.py b/workos/utils/request.py index cd114eca..2e5fb147 100644 --- a/workos/utils/request.py +++ b/workos/utils/request.py @@ -17,6 +17,7 @@ REQUEST_METHOD_DELETE = "delete" REQUEST_METHOD_GET = "get" REQUEST_METHOD_POST = "post" +REQUEST_METHOD_PUT = "put" class RequestHelper(object):