forked from workos/workos-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_api_keys.py
More file actions
70 lines (58 loc) · 2 KB
/
test_api_keys.py
File metadata and controls
70 lines (58 loc) · 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
# type: ignore
import pytest
from tests.utils.fixtures.mock_api_key import MockApiKey
from tests.utils.syncify import syncify
from workos.api_keys import (
API_KEYS_PATH,
API_KEY_VALIDATION_PATH,
ApiKeys,
AsyncApiKeys,
)
@pytest.mark.sync_and_async(ApiKeys, AsyncApiKeys)
class TestApiKeys:
@pytest.fixture
def mock_api_key(self):
return MockApiKey().dict()
@pytest.fixture
def api_key(self):
return "sk_my_api_key"
def test_validate_api_key_with_valid_key(
self,
module_instance,
api_key,
mock_api_key,
capture_and_mock_http_client_request,
):
response_body = {"api_key": mock_api_key}
request_kwargs = capture_and_mock_http_client_request(
module_instance._http_client, response_body, 200
)
api_key_details = syncify(module_instance.validate_api_key(value=api_key))
assert request_kwargs["url"].endswith(API_KEY_VALIDATION_PATH)
assert request_kwargs["method"] == "post"
assert api_key_details.id == mock_api_key["id"]
assert api_key_details.name == mock_api_key["name"]
assert api_key_details.object == "api_key"
def test_validate_api_key_with_invalid_key(
self,
module_instance,
mock_http_client_with_response,
):
mock_http_client_with_response(
module_instance._http_client,
{"api_key": None},
200,
)
assert syncify(module_instance.validate_api_key(value="invalid-key")) is None
def test_delete_api_key(
self,
module_instance,
capture_and_mock_http_client_request,
):
api_key_id = "api_key_01234567890"
request_kwargs = capture_and_mock_http_client_request(
module_instance._http_client, {}, 204
)
syncify(module_instance.delete_api_key(api_key_id))
assert request_kwargs["url"].endswith(f"{API_KEYS_PATH}/{api_key_id}")
assert request_kwargs["method"] == "delete"