Skip to content

Commit 4d69c55

Browse files
authored
Add organization domains module (#464)
* Add organization domains module * Formatting * Remove unreleased method * Add backwards compat * address greptile
1 parent 10b70fa commit 4d69c55

17 files changed

+349
-52
lines changed

tests/test_organization_domains.py

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
from typing import Union
2+
import pytest
3+
from tests.utils.syncify import syncify
4+
from workos.organization_domains import AsyncOrganizationDomains, OrganizationDomains
5+
6+
7+
@pytest.mark.sync_and_async(OrganizationDomains, AsyncOrganizationDomains)
8+
class TestOrganizationDomains:
9+
@pytest.fixture(autouse=True)
10+
def setup(
11+
self, module_instance: Union[OrganizationDomains, AsyncOrganizationDomains]
12+
):
13+
self.http_client = module_instance._http_client
14+
self.organization_domains = module_instance
15+
16+
@pytest.fixture
17+
def mock_organization_domain(self):
18+
return {
19+
"object": "organization_domain",
20+
"id": "org_domain_01EHT88Z8WZEFWYPM6EC9BX2R8",
21+
"organization_id": "org_01EHT88Z8J8795GZNQ4ZP1J81T",
22+
"domain": "example.com",
23+
"state": "pending",
24+
"verification_strategy": "dns",
25+
"verification_token": "workos_example_verification_token_12345",
26+
"verification_prefix": "_workos-challenge",
27+
"created_at": "2023-01-01T12:00:00.000Z",
28+
"updated_at": "2023-01-01T12:00:00.000Z",
29+
}
30+
31+
@pytest.fixture
32+
def mock_organization_domain_verified(self):
33+
return {
34+
"object": "organization_domain",
35+
"id": "org_domain_01EHT88Z8WZEFWYPM6EC9BX2R8",
36+
"organization_id": "org_01EHT88Z8J8795GZNQ4ZP1J81T",
37+
"domain": "example.com",
38+
"state": "verified",
39+
"verification_strategy": "dns",
40+
"verification_token": "workos_example_verification_token_12345",
41+
"verification_prefix": "_workos-challenge",
42+
"created_at": "2023-01-01T12:00:00.000Z",
43+
"updated_at": "2023-01-01T12:00:00.000Z",
44+
}
45+
46+
def test_get_organization_domain(
47+
self, capture_and_mock_http_client_request, mock_organization_domain
48+
):
49+
request_kwargs = capture_and_mock_http_client_request(
50+
self.http_client,
51+
mock_organization_domain,
52+
200,
53+
)
54+
55+
organization_domain = syncify(
56+
self.organization_domains.get_organization_domain(
57+
organization_domain_id="org_domain_01EHT88Z8WZEFWYPM6EC9BX2R8"
58+
)
59+
)
60+
61+
assert request_kwargs["url"].endswith(
62+
"/organization_domains/org_domain_01EHT88Z8WZEFWYPM6EC9BX2R8"
63+
)
64+
assert request_kwargs["method"] == "get"
65+
assert organization_domain.id == "org_domain_01EHT88Z8WZEFWYPM6EC9BX2R8"
66+
assert organization_domain.domain == "example.com"
67+
assert organization_domain.state == "pending"
68+
assert organization_domain.verification_strategy == "dns"
69+
70+
def test_create_organization_domain(
71+
self, capture_and_mock_http_client_request, mock_organization_domain
72+
):
73+
request_kwargs = capture_and_mock_http_client_request(
74+
self.http_client,
75+
mock_organization_domain,
76+
201,
77+
)
78+
79+
organization_domain = syncify(
80+
self.organization_domains.create_organization_domain(
81+
organization_id="org_01EHT88Z8J8795GZNQ4ZP1J81T",
82+
domain="example.com",
83+
)
84+
)
85+
86+
assert request_kwargs["url"].endswith("/organization_domains")
87+
assert request_kwargs["method"] == "post"
88+
assert request_kwargs["json"] == {
89+
"organization_id": "org_01EHT88Z8J8795GZNQ4ZP1J81T",
90+
"domain": "example.com",
91+
}
92+
assert organization_domain.id == "org_domain_01EHT88Z8WZEFWYPM6EC9BX2R8"
93+
assert organization_domain.domain == "example.com"
94+
assert organization_domain.organization_id == "org_01EHT88Z8J8795GZNQ4ZP1J81T"
95+
96+
def test_verify_organization_domain(
97+
self, capture_and_mock_http_client_request, mock_organization_domain_verified
98+
):
99+
request_kwargs = capture_and_mock_http_client_request(
100+
self.http_client,
101+
mock_organization_domain_verified,
102+
200,
103+
)
104+
105+
organization_domain = syncify(
106+
self.organization_domains.verify_organization_domain(
107+
organization_domain_id="org_domain_01EHT88Z8WZEFWYPM6EC9BX2R8"
108+
)
109+
)
110+
111+
assert request_kwargs["url"].endswith(
112+
"/organization_domains/org_domain_01EHT88Z8WZEFWYPM6EC9BX2R8/verify"
113+
)
114+
assert request_kwargs["method"] == "post"
115+
assert organization_domain.id == "org_domain_01EHT88Z8WZEFWYPM6EC9BX2R8"
116+
assert organization_domain.state == "verified"
117+
118+
def test_delete_organization_domain(self, capture_and_mock_http_client_request):
119+
request_kwargs = capture_and_mock_http_client_request(
120+
self.http_client,
121+
None,
122+
204,
123+
headers={"content-type": "text/plain; charset=utf-8"},
124+
)
125+
126+
response = syncify(
127+
self.organization_domains.delete_organization_domain(
128+
organization_domain_id="org_domain_01EHT88Z8WZEFWYPM6EC9BX2R8"
129+
)
130+
)
131+
132+
assert request_kwargs["url"].endswith(
133+
"/organization_domains/org_domain_01EHT88Z8WZEFWYPM6EC9BX2R8"
134+
)
135+
assert request_kwargs["method"] == "delete"
136+
assert response is None

tests/test_organizations.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -218,25 +218,6 @@ def test_delete_organization(self, capture_and_mock_http_client_request):
218218
assert request_kwargs["method"] == "delete"
219219
assert response is None
220220

221-
def test_delete_organization_domain(self, capture_and_mock_http_client_request):
222-
request_kwargs = capture_and_mock_http_client_request(
223-
self.http_client,
224-
204,
225-
headers={"content-type": "text/plain; charset=utf-8"},
226-
)
227-
228-
response = syncify(
229-
self.organizations.delete_organization_domain(
230-
organization_domain_id="org_domain_01EHT88Z8WZEFWYPM6EC9BX2R8"
231-
)
232-
)
233-
234-
assert request_kwargs["url"].endswith(
235-
"/organization_domains/org_domain_01EHT88Z8WZEFWYPM6EC9BX2R8"
236-
)
237-
assert request_kwargs["method"] == "delete"
238-
assert response is None
239-
240221
def test_list_organizations_auto_pagination_for_single_page(
241222
self,
242223
mock_organizations_single_page_response,

tests/utils/fixtures/mock_organization.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import datetime
22

33
from workos.types.organizations import Organization
4-
from workos.types.organizations.organization_domain import OrganizationDomain
4+
from workos.types.organization_domains import OrganizationDomain
55

66

77
class MockOrganization(Organization):

workos/_base_client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from workos.events import EventsModule
1212
from workos.mfa import MFAModule
1313
from workos.organizations import OrganizationsModule
14+
from workos.organization_domains import OrganizationDomainsModule
1415
from workos.passwordless import PasswordlessModule
1516
from workos.portal import PortalModule
1617
from workos.sso import SSOModule
@@ -88,6 +89,10 @@ def mfa(self) -> MFAModule: ...
8889
@abstractmethod
8990
def organizations(self) -> OrganizationsModule: ...
9091

92+
@property
93+
@abstractmethod
94+
def organization_domains(self) -> OrganizationDomainsModule: ...
95+
9196
@property
9297
@abstractmethod
9398
def passwordless(self) -> PasswordlessModule: ...

workos/async_client.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from workos.fga import FGAModule
88
from workos.mfa import MFAModule
99
from workos.organizations import AsyncOrganizations
10+
from workos.organization_domains import AsyncOrganizationDomains
1011
from workos.passwordless import PasswordlessModule
1112
from workos.portal import PortalModule
1213
from workos.sso import AsyncSSO
@@ -80,6 +81,14 @@ def organizations(self) -> AsyncOrganizations:
8081
self._organizations = AsyncOrganizations(self._http_client)
8182
return self._organizations
8283

84+
@property
85+
def organization_domains(self) -> AsyncOrganizationDomains:
86+
if not getattr(self, "_organization_domains", None):
87+
self._organization_domains = AsyncOrganizationDomains(
88+
http_client=self._http_client, client_configuration=self
89+
)
90+
return self._organization_domains
91+
8392
@property
8493
def passwordless(self) -> PasswordlessModule:
8594
raise NotImplementedError(

workos/client.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from workos.directory_sync import DirectorySync
66
from workos.fga import FGA
77
from workos.organizations import Organizations
8+
from workos.organization_domains import OrganizationDomains
89
from workos.passwordless import Passwordless
910
from workos.portal import Portal
1011
from workos.sso import SSO
@@ -80,6 +81,14 @@ def organizations(self) -> Organizations:
8081
self._organizations = Organizations(self._http_client)
8182
return self._organizations
8283

84+
@property
85+
def organization_domains(self) -> OrganizationDomains:
86+
if not getattr(self, "_organization_domains", None):
87+
self._organization_domains = OrganizationDomains(
88+
http_client=self._http_client, client_configuration=self
89+
)
90+
return self._organization_domains
91+
8392
@property
8493
def passwordless(self) -> Passwordless:
8594
if not getattr(self, "_passwordless", None):

0 commit comments

Comments
 (0)