Skip to content
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
38 changes: 38 additions & 0 deletions tests/test_organizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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",
}
]
29 changes: 28 additions & 1 deletion workos/organizations.py
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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,
)
1 change: 1 addition & 0 deletions workos/utils/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
REQUEST_METHOD_DELETE = "delete"
REQUEST_METHOD_GET = "get"
REQUEST_METHOD_POST = "post"
REQUEST_METHOD_PUT = "put"


class RequestHelper(object):
Expand Down