-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathtest_client.py
122 lines (90 loc) · 4 KB
/
test_client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import os
import pytest
from workos import AsyncWorkOSClient, WorkOSClient
class TestClient:
@pytest.fixture
def default_client(self):
return WorkOSClient(
api_key="sk_test", client_id="client_b27needthisforssotemxo"
)
def test_client_without_api_key(self):
with pytest.raises(ValueError) as error:
WorkOSClient(client_id="client_b27needthisforssotemxo")
assert (
"WorkOS API key must be provided when instantiating the client or via the WORKOS_API_KEY environment variable."
== str(error.value)
)
def test_client_without_client_id(self):
with pytest.raises(ValueError) as error:
WorkOSClient(api_key="sk_test")
assert (
"WorkOS client ID must be provided when instantiating the client or via the WORKOS_CLIENT_ID environment variable."
== str(error.value)
)
def test_client_with_api_key_and_client_id_environment_variables(self):
os.environ["WORKOS_API_KEY"] = "sk_test"
os.environ["WORKOS_CLIENT_ID"] = "client_b27needthisforssotemxo"
assert bool(WorkOSClient())
os.environ.pop("WORKOS_API_KEY")
os.environ.pop("WORKOS_CLIENT_ID")
def test_initialize_sso(self, default_client):
assert bool(default_client.sso)
def test_initialize_audit_logs(self, default_client):
assert bool(default_client.audit_logs)
def test_initialize_directory_sync(self, default_client):
assert bool(default_client.directory_sync)
def test_initialize_events(self, default_client):
assert bool(default_client.events)
def test_initialize_mfa(self, default_client):
assert bool(default_client.mfa)
def test_initialize_organizations(self, default_client):
assert bool(default_client.organizations)
def test_initialize_passwordless(self, default_client):
assert bool(default_client.passwordless)
def test_initialize_portal(self, default_client):
assert bool(default_client.portal)
def test_initialize_user_management(self, default_client):
assert bool(default_client.user_management)
def test_initialize_widgets(self, default_client):
assert bool(default_client.widgets)
def test_enforce_trailing_slash_for_base_url(
self,
):
client = WorkOSClient(
api_key="sk_test",
client_id="client_b27needthisforssotemxo",
base_url="https://api.workos.com",
)
assert client.base_url == "https://api.workos.com/"
class TestAsyncClient:
@pytest.fixture
def default_client(self):
return AsyncWorkOSClient(
api_key="sk_test", client_id="client_b27needthisforssotemxo"
)
def test_client_without_api_key(self):
with pytest.raises(ValueError) as error:
AsyncWorkOSClient(client_id="client_b27needthisforssotemxo")
assert (
"WorkOS API key must be provided when instantiating the client or via the WORKOS_API_KEY environment variable."
== str(error.value)
)
def test_client_without_client_id(self):
with pytest.raises(ValueError) as error:
AsyncWorkOSClient(api_key="sk_test")
assert (
"WorkOS client ID must be provided when instantiating the client or via the WORKOS_CLIENT_ID environment variable."
== str(error.value)
)
def test_client_with_api_key_and_client_id_environment_variables(self):
os.environ["WORKOS_API_KEY"] = "sk_test"
os.environ["WORKOS_CLIENT_ID"] = "client_b27needthisforssotemxo"
assert bool(AsyncWorkOSClient())
os.environ.pop("WORKOS_API_KEY")
os.environ.pop("WORKOS_CLIENT_ID")
def test_initialize_directory_sync(self, default_client):
assert bool(default_client.directory_sync)
def test_initialize_events(self, default_client):
assert bool(default_client.events)
def test_initialize_sso(self, default_client):
assert bool(default_client.sso)