-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathtest_httpclient.py
More file actions
139 lines (128 loc) · 5.8 KB
/
Copy pathtest_httpclient.py
File metadata and controls
139 lines (128 loc) · 5.8 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
139
"""HTTPClient test module."""
from splitio.api import client
class HttpClientTests(object):
"""Http Client test cases."""
def test_get(self, mocker):
"""Test HTTP GET verb requests."""
response_mock = mocker.Mock()
response_mock.status_code = 200
response_mock.text = 'ok'
get_mock = mocker.Mock()
get_mock.return_value = response_mock
mocker.patch('splitio.api.client.requests.get', new=get_mock)
httpclient = client.HttpClient()
response = httpclient.get('sdk', '/test1', 'some_api_key', {'param1': 123}, {'h1': 'abc'})
call = mocker.call(
client.HttpClient.SDK_URL + '/test1',
headers={'Authorization': 'Bearer some_api_key', 'h1': 'abc', 'Content-Type': 'application/json'},
params={'param1': 123},
timeout=None
)
assert response.status_code == 200
assert response.body == 'ok'
assert get_mock.mock_calls == [call]
get_mock.reset_mock()
response = httpclient.get('events', '/test1', 'some_api_key', {'param1': 123}, {'h1': 'abc'})
call = mocker.call(
client.HttpClient.EVENTS_URL + '/test1',
headers={'Authorization': 'Bearer some_api_key', 'h1': 'abc', 'Content-Type': 'application/json'},
params={'param1': 123},
timeout=None
)
assert get_mock.mock_calls == [call]
assert response.status_code == 200
assert response.body == 'ok'
def test_get_custom_urls(self, mocker):
"""Test HTTP GET verb requests."""
response_mock = mocker.Mock()
response_mock.status_code = 200
response_mock.text = 'ok'
get_mock = mocker.Mock()
get_mock.return_value = response_mock
mocker.patch('splitio.api.client.requests.get', new=get_mock)
httpclient = client.HttpClient(sdk_url='https://sdk.com', events_url='https://events.com')
response = httpclient.get('sdk', '/test1', 'some_api_key', {'param1': 123}, {'h1': 'abc'})
call = mocker.call(
'https://sdk.com/test1',
headers={'Authorization': 'Bearer some_api_key', 'h1': 'abc', 'Content-Type': 'application/json'},
params={'param1': 123},
timeout=None
)
assert get_mock.mock_calls == [call]
assert response.status_code == 200
assert response.body == 'ok'
get_mock.reset_mock()
response = httpclient.get('events', '/test1', 'some_api_key', {'param1': 123}, {'h1': 'abc'})
call = mocker.call(
'https://events.com/test1',
headers={'Authorization': 'Bearer some_api_key', 'h1': 'abc', 'Content-Type': 'application/json'},
params={'param1': 123},
timeout=None
)
assert response.status_code == 200
assert response.body == 'ok'
assert get_mock.mock_calls == [call]
def test_post(self, mocker):
"""Test HTTP GET verb requests."""
response_mock = mocker.Mock()
response_mock.status_code = 200
response_mock.text = 'ok'
get_mock = mocker.Mock()
get_mock.return_value = response_mock
mocker.patch('splitio.api.client.requests.post', new=get_mock)
httpclient = client.HttpClient()
response = httpclient.post('sdk', '/test1', 'some_api_key', {'p1': 'a'}, {'param1': 123}, {'h1': 'abc'})
call = mocker.call(
client.HttpClient.SDK_URL + '/test1',
json={'p1': 'a'},
headers={'Authorization': 'Bearer some_api_key', 'h1': 'abc', 'Content-Type': 'application/json'},
params={'param1': 123},
timeout=None
)
assert response.status_code == 200
assert response.body == 'ok'
assert get_mock.mock_calls == [call]
get_mock.reset_mock()
response = httpclient.post('events', '/test1', 'some_api_key', {'p1': 'a'}, {'param1': 123}, {'h1': 'abc'})
call = mocker.call(
client.HttpClient.EVENTS_URL + '/test1',
json={'p1': 'a'},
headers={'Authorization': 'Bearer some_api_key', 'h1': 'abc', 'Content-Type': 'application/json'},
params={'param1': 123},
timeout=None
)
assert response.status_code == 200
assert response.body == 'ok'
assert get_mock.mock_calls == [call]
def test_post_custom_urls(self, mocker):
"""Test HTTP GET verb requests."""
response_mock = mocker.Mock()
response_mock.status_code = 200
response_mock.text = 'ok'
get_mock = mocker.Mock()
get_mock.return_value = response_mock
mocker.patch('splitio.api.client.requests.post', new=get_mock)
httpclient = client.HttpClient(sdk_url='https://sdk.com', events_url='https://events.com')
response = httpclient.post('sdk', '/test1', 'some_api_key', {'p1': 'a'}, {'param1': 123}, {'h1': 'abc'})
call = mocker.call(
'https://sdk.com' + '/test1',
json={'p1': 'a'},
headers={'Authorization': 'Bearer some_api_key', 'h1': 'abc', 'Content-Type': 'application/json'},
params={'param1': 123},
timeout=None
)
assert response.status_code == 200
assert response.body == 'ok'
assert get_mock.mock_calls == [call]
get_mock.reset_mock()
response = httpclient.post('events', '/test1', 'some_api_key', {'p1': 'a'}, {'param1': 123}, {'h1': 'abc'})
call = mocker.call(
'https://events.com' + '/test1',
json={'p1': 'a'},
headers={'Authorization': 'Bearer some_api_key', 'h1': 'abc', 'Content-Type': 'application/json'},
params={'param1': 123},
timeout=None
)
assert response.status_code == 200
assert response.body == 'ok'
assert get_mock.mock_calls == [call]