30
30
31
31
32
32
def test_remote_status_success ():
33
- with mock .patch ("umapi_client.connection.requests.get" ) as mock_get :
33
+ with mock .patch ("umapi_client.connection.requests.Session. get" ) as mock_get :
34
34
mock_get .return_value = MockResponse (200 , body = {"build" : "2559" , "version" : "2.1.54" , "state" :"LIVE" })
35
35
conn = Connection (** mock_connection_params )
36
36
_ , remote_status = conn .status (remote = True )
37
37
assert remote_status == {"endpoint" : "https://test/" , "build" : "2559" , "version" : "2.1.54" , "state" :"LIVE" }
38
38
39
39
40
40
def test_remote_status_failure ():
41
- with mock .patch ("umapi_client.connection.requests.get" ) as mock_get :
41
+ with mock .patch ("umapi_client.connection.requests.Session. get" ) as mock_get :
42
42
mock_get .return_value = MockResponse (404 , text = "404 Not Found" )
43
43
conn = Connection (** mock_connection_params )
44
44
_ , remote_status = conn .status (remote = True )
45
45
assert remote_status ["status" ].startswith ("Unexpected" )
46
46
47
47
48
48
def test_remote_status_timeout ():
49
- with mock .patch ("umapi_client.connection.requests.get" ) as mock_get :
49
+ with mock .patch ("umapi_client.connection.requests.Session. get" ) as mock_get :
50
50
mock_get .side_effect = requests .Timeout
51
51
conn = Connection (** mock_connection_params )
52
52
_ , remote_status = conn .status (remote = True )
53
53
assert remote_status ["status" ].startswith ("Unreachable" )
54
54
55
55
56
56
def test_get_success ():
57
- with mock .patch ("umapi_client.connection.requests.get" ) as mock_get :
57
+ with mock .patch ("umapi_client.connection.requests.Session. get" ) as mock_get :
58
58
mock_get .return_value = MockResponse (200 , body = ["test" , "body" ])
59
59
conn = Connection (** mock_connection_params )
60
60
assert conn .make_call ("" ).json () == ["test" , "body" ]
61
61
62
62
63
+ def test_get_success_test_mode ():
64
+ with mock .patch ("umapi_client.connection.requests.Session.get" ) as mock_get :
65
+ mock_get .return_value = MockResponse (200 , body = ["test" , "body" ])
66
+ conn = Connection (test_mode = True , ** mock_connection_params )
67
+ assert conn .make_call ("" ).json () == ["test" , "body" ]
68
+
69
+
63
70
def test_post_success ():
64
- with mock .patch ("umapi_client.connection.requests.post" ) as mock_post :
71
+ with mock .patch ("umapi_client.connection.requests.Session. post" ) as mock_post :
65
72
mock_post .return_value = MockResponse (200 , body = ["test" , "body" ])
66
73
conn = Connection (** mock_connection_params )
67
74
assert conn .make_call ("" , [3 , 5 ]).json () == ["test" , "body" ]
68
75
69
76
77
+ def test_post_success_test_mode ():
78
+ with mock .patch ("umapi_client.connection.requests.Session.post" ) as mock_post :
79
+ mock_post .return_value = MockResponse (200 , body = ["test" , "body" ])
80
+ conn = Connection (test_mode = True , ** mock_connection_params )
81
+ assert conn .make_call ("" , [3 , 5 ]).json () == ["test" , "body" ]
82
+
83
+
70
84
def test_get_timeout ():
71
- with mock .patch ("umapi_client.connection.requests.get" ) as mock_get :
85
+ with mock .patch ("umapi_client.connection.requests.Session. get" ) as mock_get :
72
86
mock_get .side_effect = requests .Timeout
73
87
conn = Connection (** mock_connection_params )
74
88
pytest .raises (UnavailableError , conn .make_call , "" )
75
89
76
90
77
91
def test_post_timeout ():
78
- with mock .patch ("umapi_client.connection.requests.post" ) as mock_post :
92
+ with mock .patch ("umapi_client.connection.requests.Session. post" ) as mock_post :
79
93
mock_post .side_effect = requests .Timeout
80
94
conn = Connection (** mock_connection_params )
81
95
pytest .raises (UnavailableError , conn .make_call , "" , [3 , 5 ])
82
96
83
97
84
98
def test_get_retry_header_1 ():
85
- with mock .patch ("umapi_client.connection.requests.get" ) as mock_get :
99
+ with mock .patch ("umapi_client.connection.requests.Session. get" ) as mock_get :
86
100
mock_get .return_value = MockResponse (429 , headers = {"Retry-After" : "1" })
87
101
conn = Connection (** mock_connection_params )
88
102
pytest .raises (UnavailableError , conn .make_call , "" )
89
103
90
104
91
105
def test_post_retry_header_1 ():
92
- with mock .patch ("umapi_client.connection.requests.post" ) as mock_post :
106
+ with mock .patch ("umapi_client.connection.requests.Session. post" ) as mock_post :
93
107
mock_post .return_value = MockResponse (429 , headers = {"Retry-After" : "1" })
94
108
conn = Connection (** mock_connection_params )
95
109
pytest .raises (UnavailableError , conn .make_call , "" , "[3, 5]" )
96
110
97
111
98
112
def test_get_retry_header_time_2 ():
99
- with mock .patch ("umapi_client.connection.requests.get" ) as mock_get :
113
+ with mock .patch ("umapi_client.connection.requests.Session. get" ) as mock_get :
100
114
mock_get .return_value = MockResponse (502 , headers = {"Retry-After" : formatdate (time .time () + 2.5 )})
101
115
conn = Connection (** mock_connection_params )
102
116
pytest .raises (UnavailableError , conn .make_call , "" )
103
117
104
118
105
119
def test_post_retry_header_time_2 ():
106
- with mock .patch ("umapi_client.connection.requests.post" ) as mock_post :
120
+ with mock .patch ("umapi_client.connection.requests.Session. post" ) as mock_post :
107
121
mock_post .return_value = MockResponse (502 , headers = {"Retry-After" : formatdate (time .time () + 2.5 )})
108
122
conn = Connection (** mock_connection_params )
109
123
pytest .raises (UnavailableError , conn .make_call , "" , "[3, 5]" )
110
124
111
125
112
126
def test_get_retry_header_0 ():
113
- with mock .patch ("umapi_client.connection.requests.get" ) as mock_get :
127
+ with mock .patch ("umapi_client.connection.requests.Session. get" ) as mock_get :
114
128
mock_get .return_value = MockResponse (503 , headers = {"Retry-After" : "0" })
115
129
conn = Connection (** mock_connection_params )
116
130
pytest .raises (UnavailableError , conn .make_call , "" )
117
131
118
132
119
133
def test_post_retry_header_0 ():
120
- with mock .patch ("umapi_client.connection.requests.post" ) as mock_post :
134
+ with mock .patch ("umapi_client.connection.requests.Session. post" ) as mock_post :
121
135
mock_post .return_value = MockResponse (503 , headers = {"Retry-After" : "0" })
122
136
conn = Connection (** mock_connection_params )
123
137
pytest .raises (UnavailableError , conn .make_call , "" , "[3, 5]" )
124
138
125
139
126
140
def test_get_retry_no_header ():
127
- with mock .patch ("umapi_client.connection.requests.get" ) as mock_get :
141
+ with mock .patch ("umapi_client.connection.requests.Session. get" ) as mock_get :
128
142
mock_get .return_value = MockResponse (504 )
129
143
conn = Connection (** mock_connection_params )
130
144
pytest .raises (UnavailableError , conn .make_call , "" )
131
145
132
146
133
147
def test_post_retry_no_header ():
134
- with mock .patch ("umapi_client.connection.requests.post" ) as mock_post :
148
+ with mock .patch ("umapi_client.connection.requests.Session. post" ) as mock_post :
135
149
mock_post .return_value = MockResponse (504 )
136
150
conn = Connection (** mock_connection_params )
137
151
pytest .raises (UnavailableError , conn .make_call , "" , "[3, 5]" )
138
152
139
153
140
154
# log_stream fixture defined in conftest.py
141
155
def test_get_retry_logging (log_stream ):
142
- with mock .patch ("umapi_client.connection.requests.get" ) as mock_get :
156
+ with mock .patch ("umapi_client.connection.requests.Session. get" ) as mock_get :
143
157
mock_get .return_value = MockResponse (429 , headers = {"Retry-After" : "3" })
144
158
stream , logger = log_stream
145
159
params = dict (mock_connection_params )
@@ -160,7 +174,7 @@ def test_get_retry_logging(log_stream):
160
174
161
175
# log_stream fixture defined in conftest.py
162
176
def test_post_retry_logging (log_stream ):
163
- with mock .patch ("umapi_client.connection.requests.post" ) as mock_post :
177
+ with mock .patch ("umapi_client.connection.requests.Session. post" ) as mock_post :
164
178
mock_post .return_value = MockResponse (429 , headers = {"Retry-After" : "3" })
165
179
stream , logger = log_stream
166
180
params = dict (mock_connection_params )
@@ -180,28 +194,28 @@ def test_post_retry_logging(log_stream):
180
194
181
195
182
196
def test_get_server_fail ():
183
- with mock .patch ("umapi_client.connection.requests.get" ) as mock_get :
197
+ with mock .patch ("umapi_client.connection.requests.Session. get" ) as mock_get :
184
198
mock_get .return_value = MockResponse (500 , text = "500 test server failure" )
185
199
conn = Connection (** mock_connection_params )
186
200
pytest .raises (ServerError , conn .make_call , "" )
187
201
188
202
189
203
def test_post_server_fail ():
190
- with mock .patch ("umapi_client.connection.requests.post" ) as mock_post :
204
+ with mock .patch ("umapi_client.connection.requests.Session. post" ) as mock_post :
191
205
mock_post .return_value = MockResponse (500 , text = "500 test server failure" )
192
206
conn = Connection (** mock_connection_params )
193
207
pytest .raises (ServerError , conn .make_call , "" , "[3, 5]" )
194
208
195
209
196
210
def test_get_request_fail ():
197
- with mock .patch ("umapi_client.connection.requests.get" ) as mock_get :
211
+ with mock .patch ("umapi_client.connection.requests.Session. get" ) as mock_get :
198
212
mock_get .return_value = MockResponse (400 , text = "400 test request failure" )
199
213
conn = Connection (** mock_connection_params )
200
214
pytest .raises (RequestError , conn .make_call , "" )
201
215
202
216
203
217
def test_post_request_fail ():
204
- with mock .patch ("umapi_client.connection.requests.post" ) as mock_post :
218
+ with mock .patch ("umapi_client.connection.requests.Session. post" ) as mock_post :
205
219
mock_post .return_value = MockResponse (400 , text = "400 test request failure" )
206
220
conn = Connection (** mock_connection_params )
207
221
pytest .raises (RequestError , conn .make_call , "" , "[3, 5]" )
0 commit comments