forked from pact-foundation/pact-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_http_proxy.py
More file actions
88 lines (73 loc) · 2.25 KB
/
test_http_proxy.py
File metadata and controls
88 lines (73 loc) · 2.25 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
from unittest import TestCase
from pact.http_proxy import app
from fastapi.testclient import TestClient
client = TestClient(app)
class HttpProxyTestCase(TestCase):
def test_ping(self):
res = client.get('/ping')
self.assertEqual(res.status_code, 200)
assert res.json() == {"ping": "pong"}
def test_handle_http_error(self):
res = client.get(
'/something_does_not_exist'
)
self.assertEqual(res.status_code, 404)
json_res = res.json()
json_res['code'] = 404
json_res['name'] = 'Not Found'
def test_setup(self):
payload = {'anyPayload': 'really'}
res = client.post(
'/setup',
json=payload
)
self.assertEqual(res.status_code, 201)
json_res = res.json()
assert json_res == payload
def setup_state(self, payload):
setup_res = client.post(
'/setup',
json=payload
)
self.assertEqual(setup_res.status_code, 201)
def test_home_should_return_expected_response(self):
message = {
'event': 'ObjectCreated:Put',
'bucket': 'bucket_name',
'key': 'path_to_file_in_s3.pdf',
'documentType': 'application/pdf'
}
data = {
'messageHandlers': {
'A document created successfully': message
}
}
self.setup_state(data)
payload = {
'providerStates': [{'name': 'A document created successfully'}]
}
res = client.post(
'/',
json=payload
)
self.assertEqual(res.json(), {'contents': message})
def test_home_raise_runtime_error_if_no_matched(self):
data = {
'messageHandlers': {
'A document created successfully': {
'event': 'ObjectCreated:Put'
}
}
}
self.setup_state(data)
payload = {
'providerStates': [{'name': 'New state to raise RuntimeError'}]
}
res = client.post(
'/',
json=payload
)
self.assertEqual(res.status_code, 500)
assert res.json() == {
'detail': 'No matched handler.'
}