-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathtest_webhooks.py
More file actions
51 lines (42 loc) · 1.66 KB
/
Copy pathtest_webhooks.py
File metadata and controls
51 lines (42 loc) · 1.66 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
from ._framework import ApiTestCase
class TestWebhooksApi(ApiTestCase):
def setUp(self):
super().setUp()
def test_get_all(self):
response = self._get("webhooks")
self._assert_status_code_is(response, 200)
webhook_objs = self._assert_are_webhooks(response)
ids = self._get_webhook_ids(webhook_objs)
for expected_id in [
"history_test1",
"history_test2",
"masthead_test",
"phdcomics",
"trans_object",
"xkcd",
"gtn",
"iframe",
]:
assert expected_id in ids
def test_get_data(self):
response = self._get("webhooks/trans_object/data")
self._assert_status_code_is(response, 200)
self._assert_has_keys(response.json(), "username")
def test_iframe_data_unconfigured(self):
# When center_panel_url is not set the endpoint must return an empty
# dict so the client-side script can silently skip rendering.
response = self._get("webhooks/iframe/data")
self._assert_status_code_is(response, 200)
assert response.json() == {}
def _assert_are_webhooks(self, response):
response_list = response.json()
assert isinstance(response_list, list)
for obj in response_list:
self._assert_is_webhook(obj)
return response_list
def _assert_is_webhook(self, obj):
assert isinstance(obj, dict)
self._assert_has_keys(obj, "id", "type", "activate", "weight", "script", "styles", "config")
def _get_webhook_ids(self, webhook_objs):
names = [w.get("id") for w in webhook_objs]
return names