-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathtest_pipes.py
More file actions
167 lines (146 loc) · 4.79 KB
/
test_pipes.py
File metadata and controls
167 lines (146 loc) · 4.79 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import pytest
from tests.utils.syncify import syncify
from workos.pipes import AsyncPipes, Pipes
@pytest.mark.sync_and_async(Pipes, AsyncPipes)
class TestPipes:
@pytest.fixture
def mock_access_token(self):
return {
"object": "access_token",
"access_token": "test_access_token_123",
"expires_at": "2026-01-09T12:00:00.000Z",
"scopes": ["read:users", "write:users"],
"missing_scopes": [],
}
def test_get_access_token_success_with_expiry(
self,
module_instance,
mock_access_token,
capture_and_mock_http_client_request,
):
response_body = {
"active": True,
"access_token": mock_access_token,
}
request_kwargs = capture_and_mock_http_client_request(
module_instance._http_client, response_body, 200
)
result = syncify(
module_instance.get_access_token(
provider="test-provider",
user_id="user_123",
)
)
assert request_kwargs["url"].endswith("data-integrations/test-provider/token")
assert request_kwargs["method"] == "post"
assert request_kwargs["json"]["user_id"] == "user_123"
assert result.active is True
assert result.access_token.access_token == mock_access_token["access_token"]
assert result.access_token.scopes == mock_access_token["scopes"]
def test_get_access_token_success_without_expiry(
self,
module_instance,
capture_and_mock_http_client_request,
):
response_body = {
"active": True,
"access_token": {
"object": "access_token",
"access_token": "test_token",
"expires_at": None,
"scopes": ["read"],
"missing_scopes": [],
},
}
capture_and_mock_http_client_request(
module_instance._http_client, response_body, 200
)
result = syncify(
module_instance.get_access_token(
provider="test-provider",
user_id="user_123",
)
)
assert result.active is True
assert result.access_token.expires_at is None
def test_get_access_token_with_organization_id(
self,
module_instance,
mock_access_token,
capture_and_mock_http_client_request,
):
response_body = {
"active": True,
"access_token": mock_access_token,
}
request_kwargs = capture_and_mock_http_client_request(
module_instance._http_client, response_body, 200
)
syncify(
module_instance.get_access_token(
provider="test-provider",
user_id="user_123",
organization_id="org_456",
)
)
assert request_kwargs["json"]["organization_id"] == "org_456"
def test_get_access_token_without_organization_id(
self,
module_instance,
mock_access_token,
capture_and_mock_http_client_request,
):
response_body = {
"active": True,
"access_token": mock_access_token,
}
request_kwargs = capture_and_mock_http_client_request(
module_instance._http_client, response_body, 200
)
syncify(
module_instance.get_access_token(
provider="test-provider",
user_id="user_123",
)
)
assert "organization_id" not in request_kwargs["json"]
def test_get_access_token_not_installed(
self,
module_instance,
capture_and_mock_http_client_request,
):
response_body = {
"active": False,
"error": "not_installed",
}
capture_and_mock_http_client_request(
module_instance._http_client, response_body, 200
)
result = syncify(
module_instance.get_access_token(
provider="test-provider",
user_id="user_123",
)
)
assert result.active is False
assert result.error == "not_installed"
def test_get_access_token_needs_reauthorization(
self,
module_instance,
capture_and_mock_http_client_request,
):
response_body = {
"active": False,
"error": "needs_reauthorization",
}
capture_and_mock_http_client_request(
module_instance._http_client, response_body, 200
)
result = syncify(
module_instance.get_access_token(
provider="test-provider",
user_id="user_123",
)
)
assert result.active is False
assert result.error == "needs_reauthorization"