forked from workos/workos-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_client.py
More file actions
128 lines (94 loc) · 4.2 KB
/
test_client.py
File metadata and controls
128 lines (94 loc) · 4.2 KB
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
123
124
125
126
127
128
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_api_keys(self, default_client):
assert bool(default_client.api_keys)
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_api_keys(self, default_client):
assert bool(default_client.api_keys)
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)