-
Notifications
You must be signed in to change notification settings - Fork 47
/
fixtures_webhook.py
90 lines (72 loc) · 2.74 KB
/
fixtures_webhook.py
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
import os
import pytest
from up42.webhooks import Webhook, Webhooks
from .fixtures_globals import API_HOST, JSON_WEBHOOK, WEBHOOK_ID
@pytest.fixture()
def webhook_mock(auth_mock, requests_mock):
# webhook info
url_webhook_info = f"{API_HOST}/workspaces/{auth_mock.workspace_id}/webhooks/{WEBHOOK_ID}"
requests_mock.get(url=url_webhook_info, json=JSON_WEBHOOK)
# test event
url_test_event = f"{API_HOST}/workspaces/{auth_mock.workspace_id}/webhooks/{WEBHOOK_ID}/tests"
json_test_event = {
"data": {
"startedAt": "2022-06-20T04:33:48.770826Z",
"testsRun": 2,
"testsSucceeded": 0,
}
}
requests_mock.post(url=url_test_event, json=json_test_event)
# update
url_update = f"{API_HOST}/workspaces/{auth_mock.workspace_id}/webhooks/{WEBHOOK_ID}"
requests_mock.put(url=url_update, json=JSON_WEBHOOK)
# delete
url_delete = f"{API_HOST}/workspaces/{auth_mock.workspace_id}/webhooks/{WEBHOOK_ID}"
requests_mock.delete(url=url_delete)
return Webhook(auth=auth_mock, webhook_id=WEBHOOK_ID)
@pytest.fixture()
def webhook_live(auth_live):
webhook_id = os.getenv("TEST_UP42_WEBHOOK_ID")
assert isinstance(webhook_id, str)
return Webhook(auth=auth_live, webhook_id=webhook_id)
@pytest.fixture()
def webhooks_mock(auth_mock, requests_mock):
# events
url_events = f"{API_HOST}/webhooks/events"
events_json = {"data": [{"name": "job.status"}], "error": None}
requests_mock.get(url=url_events, json=events_json)
# get webhooks
url_webhooks = f"{API_HOST}/workspaces/{auth_mock.workspace_id}/webhooks"
webhooks_json = {
"data": [
{
"url": "a.com",
"name": "a",
"active": True,
"events": ["job.status"],
"id": "123",
"secret": "foobar2k",
"createdAt": "2022-04-13T19:19:19.357571Z",
"updatedAt": "2022-04-13T19:19:19.357571Z",
},
{
"url": "b.com",
"name": "b",
"active": True,
"events": ["order.status"],
"id": "d6971221-846c-48a1-bb0d-c00d49a4ba70",
"secret": "foobar2k",
"createdAt": "2022-04-13T19:19:40.68348Z",
"updatedAt": "2022-04-13T19:19:40.68348Z",
},
],
"error": None,
}
requests_mock.get(url=url_webhooks, json=webhooks_json)
# create webhook
url_create_webhook = f"{API_HOST}/workspaces/{auth_mock.workspace_id}/webhooks"
requests_mock.post(url=url_create_webhook, json=JSON_WEBHOOK)
return Webhooks(auth=auth_mock)
@pytest.fixture()
def webhooks_live(auth_live):
return Webhooks(auth=auth_live)