-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathapi_keys_test.py
More file actions
138 lines (122 loc) · 4.72 KB
/
api_keys_test.py
File metadata and controls
138 lines (122 loc) · 4.72 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
import resend
from resend.exceptions import NoContentError
from tests.conftest import ResendBaseTest
# flake8: noqa
class TestResendApiKeys(ResendBaseTest):
def test_api_keys_create(self) -> None:
self.set_mock_json(
{
"id": "dacf4072-4119-4d88-932f-6202748ac7c8",
"token": "re_c1tpEyD8_NKFusih9vKVQknRAQfmFcWCv",
}
)
params: resend.ApiKeys.CreateParams = {
"name": "prod",
}
key: resend.ApiKeys.CreateApiKeyResponse = resend.ApiKeys.create(params)
assert key["id"] == "dacf4072-4119-4d88-932f-6202748ac7c8"
def test_should_create_api_key_raise_exception_when_no_content(self) -> None:
self.set_mock_json(None)
params: resend.ApiKeys.CreateParams = {
"name": "prod",
}
with self.assertRaises(NoContentError):
_ = resend.ApiKeys.create(params)
def test_api_keys_list(self) -> None:
self.set_mock_json(
{
"object": "list",
"has_more": False,
"data": [
{
"id": "91f3200a-df72-4654-b0cd-f202395f5354",
"name": "Production",
"created_at": "2023-04-08T00:11:13.110779+00:00",
"last_used_at": "2023-04-08T12:00:00.000000+00:00",
}
],
}
)
keys: resend.ApiKeys.ListResponse = resend.ApiKeys.list()
assert keys["object"] == "list"
assert keys["has_more"] is False
for key in keys["data"]:
assert key["id"] == "91f3200a-df72-4654-b0cd-f202395f5354"
assert key["name"] == "Production"
assert key["created_at"] == "2023-04-08T00:11:13.110779+00:00"
assert key["last_used_at"] == "2023-04-08T12:00:00.000000+00:00"
def test_api_keys_list_last_used_at_none(self) -> None:
self.set_mock_json(
{
"object": "list",
"has_more": False,
"data": [
{
"id": "91f3200a-df72-4654-b0cd-f202395f5354",
"name": "Production",
"created_at": "2023-04-08T00:11:13.110779+00:00",
"last_used_at": None,
}
],
}
)
keys: resend.ApiKeys.ListResponse = resend.ApiKeys.list()
assert keys["data"][0]["last_used_at"] is None
def test_should_list_api_key_raise_exception_when_no_content(self) -> None:
self.set_mock_json(None)
with self.assertRaises(NoContentError):
_ = resend.ApiKeys.list()
def test_api_keys_list_with_pagination_params(self) -> None:
self.set_mock_json(
{
"object": "list",
"has_more": True,
"data": [
{
"id": "test-key-1",
"name": "Test Key 1",
"created_at": "2023-04-08T00:11:13.110779+00:00",
},
{
"id": "test-key-2",
"name": "Test Key 2",
"created_at": "2023-04-09T00:11:13.110779+00:00",
},
],
}
)
params: resend.ApiKeys.ListParams = {"limit": 10, "after": "previous-key-id"}
keys: resend.ApiKeys.ListResponse = resend.ApiKeys.list(params=params)
assert keys["object"] == "list"
assert keys["has_more"] is True
assert len(keys["data"]) == 2
assert keys["data"][0]["id"] == "test-key-1"
assert keys["data"][1]["id"] == "test-key-2"
def test_api_keys_list_with_before_param(self) -> None:
self.set_mock_json(
{
"object": "list",
"has_more": False,
"data": [
{
"id": "test-key-3",
"name": "Test Key 3",
"created_at": "2023-04-07T00:11:13.110779+00:00",
}
],
}
)
params: resend.ApiKeys.ListParams = {"limit": 5, "before": "later-key-id"}
keys: resend.ApiKeys.ListResponse = resend.ApiKeys.list(params=params)
assert keys["object"] == "list"
assert keys["has_more"] is False
assert len(keys["data"]) == 1
assert keys["data"][0]["id"] == "test-key-3"
def test_api_keys_remove(self) -> None:
self.set_mock_text("")
assert (
resend.ApiKeys.remove(
api_key_id="4ef9a417-02e9-4d39-ad75-9611e0fcc33c",
)
is None
)