Skip to content

Commit 32a7844

Browse files
authored
Add update organization method (#76)
1 parent 603c400 commit 32a7844

File tree

3 files changed

+67
-1
lines changed

3 files changed

+67
-1
lines changed

tests/test_organizations.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@ def mock_organization(self):
2727
],
2828
}
2929

30+
@pytest.fixture
31+
def mock_organization_updated(self):
32+
return {
33+
"name": "Example Organization",
34+
"object": "organization",
35+
"id": "org_01EHT88Z8J8795GZNQ4ZP1J81T",
36+
"domains": [
37+
{
38+
"domain": "example.io",
39+
"object": "organization_domain",
40+
"id": "org_domain_01EHT88Z8WZEFWYPM6EC9BX2R8",
41+
}
42+
],
43+
}
44+
3045
@pytest.fixture
3146
def mock_organizations(self):
3247
return {
@@ -90,3 +105,26 @@ def test_create_organization(self, mock_organization, mock_request_method):
90105

91106
assert subject["id"] == "org_01EHT88Z8J8795GZNQ4ZP1J81T"
92107
assert subject["name"] == "Test Organization"
108+
109+
def test_update_organization(self, mock_organization_updated, mock_request_method):
110+
mock_response = Response()
111+
mock_response.status_code = 201
112+
mock_response.response_dict = mock_organization_updated
113+
mock_request_method("put", mock_response, 201)
114+
115+
result = self.organizations.update_organization(
116+
organization="org_01EHT88Z8J8795GZNQ4ZP1J81T",
117+
name="Example Organization",
118+
domains=["example.io"],
119+
)
120+
subject = result.response_dict
121+
122+
assert subject["id"] == "org_01EHT88Z8J8795GZNQ4ZP1J81T"
123+
assert subject["name"] == "Example Organization"
124+
assert subject["domains"] == [
125+
{
126+
"domain": "example.io",
127+
"object": "organization_domain",
128+
"id": "org_domain_01EHT88Z8WZEFWYPM6EC9BX2R8",
129+
}
130+
]

workos/organizations.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import workos
2-
from workos.utils.request import RequestHelper, REQUEST_METHOD_GET, REQUEST_METHOD_POST
2+
from workos.utils.request import (
3+
RequestHelper,
4+
REQUEST_METHOD_GET,
5+
REQUEST_METHOD_POST,
6+
REQUEST_METHOD_PUT,
7+
)
38
from workos.utils.validation import ORGANIZATIONS_MODULE, validate_settings
49

510
ORGANIZATIONS_PATH = "organizations"
@@ -74,3 +79,25 @@ def create_organization(self, organization):
7479
params=organization,
7580
token=workos.api_key,
7681
)
82+
83+
def update_organization(self, organization, name, domains=None):
84+
"""Update an organization
85+
86+
Args:
87+
organization(str) - Organization's unique identifier.
88+
name (str) - A unique, descriptive name for the organization.
89+
domains (list) - List of domains that belong to the organization. (Optional)
90+
91+
Returns:
92+
dict: Updated Organization response from WorkOS.
93+
"""
94+
params = {
95+
"domains": domains,
96+
"name": name,
97+
}
98+
return self.request_helper.request(
99+
"organizations/{organization}".format(organization=organization),
100+
method=REQUEST_METHOD_PUT,
101+
params=params,
102+
token=workos.api_key,
103+
)

workos/utils/request.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
REQUEST_METHOD_DELETE = "delete"
1818
REQUEST_METHOD_GET = "get"
1919
REQUEST_METHOD_POST = "post"
20+
REQUEST_METHOD_PUT = "put"
2021

2122

2223
class RequestHelper(object):

0 commit comments

Comments
 (0)