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
63
def test_get_success_test_mode ():
64
- with mock .patch ("umapi_client.connection.requests.get" ) as mock_get :
64
+ with mock .patch ("umapi_client.connection.requests.Session. get" ) as mock_get :
65
65
mock_get .return_value = MockResponse (200 , body = ["test" , "body" ])
66
66
conn = Connection (test_mode = True , ** mock_connection_params )
67
67
assert conn .make_call ("" ).json () == ["test" , "body" ]
68
68
69
69
70
70
def test_post_success ():
71
- with mock .patch ("umapi_client.connection.requests.post" ) as mock_post :
71
+ with mock .patch ("umapi_client.connection.requests.Session. post" ) as mock_post :
72
72
mock_post .return_value = MockResponse (200 , body = ["test" , "body" ])
73
73
conn = Connection (** mock_connection_params )
74
74
assert conn .make_call ("" , [3 , 5 ]).json () == ["test" , "body" ]
75
75
76
76
77
77
def test_post_success_test_mode ():
78
- with mock .patch ("umapi_client.connection.requests.post" ) as mock_post :
78
+ with mock .patch ("umapi_client.connection.requests.Session. post" ) as mock_post :
79
79
mock_post .return_value = MockResponse (200 , body = ["test" , "body" ])
80
80
conn = Connection (test_mode = True , ** mock_connection_params )
81
81
assert conn .make_call ("" , [3 , 5 ]).json () == ["test" , "body" ]
82
82
83
83
84
84
def test_get_timeout ():
85
- with mock .patch ("umapi_client.connection.requests.get" ) as mock_get :
85
+ with mock .patch ("umapi_client.connection.requests.Session. get" ) as mock_get :
86
86
mock_get .side_effect = requests .Timeout
87
87
conn = Connection (** mock_connection_params )
88
88
pytest .raises (UnavailableError , conn .make_call , "" )
89
89
90
90
91
91
def test_post_timeout ():
92
- with mock .patch ("umapi_client.connection.requests.post" ) as mock_post :
92
+ with mock .patch ("umapi_client.connection.requests.Session. post" ) as mock_post :
93
93
mock_post .side_effect = requests .Timeout
94
94
conn = Connection (** mock_connection_params )
95
95
pytest .raises (UnavailableError , conn .make_call , "" , [3 , 5 ])
96
96
97
97
98
98
def test_get_retry_header_1 ():
99
- with mock .patch ("umapi_client.connection.requests.get" ) as mock_get :
99
+ with mock .patch ("umapi_client.connection.requests.Session. get" ) as mock_get :
100
100
mock_get .return_value = MockResponse (429 , headers = {"Retry-After" : "1" })
101
101
conn = Connection (** mock_connection_params )
102
102
pytest .raises (UnavailableError , conn .make_call , "" )
103
103
104
104
105
105
def test_post_retry_header_1 ():
106
- with mock .patch ("umapi_client.connection.requests.post" ) as mock_post :
106
+ with mock .patch ("umapi_client.connection.requests.Session. post" ) as mock_post :
107
107
mock_post .return_value = MockResponse (429 , headers = {"Retry-After" : "1" })
108
108
conn = Connection (** mock_connection_params )
109
109
pytest .raises (UnavailableError , conn .make_call , "" , "[3, 5]" )
110
110
111
111
112
112
def test_get_retry_header_time_2 ():
113
- with mock .patch ("umapi_client.connection.requests.get" ) as mock_get :
113
+ with mock .patch ("umapi_client.connection.requests.Session. get" ) as mock_get :
114
114
mock_get .return_value = MockResponse (502 , headers = {"Retry-After" : formatdate (time .time () + 2.5 )})
115
115
conn = Connection (** mock_connection_params )
116
116
pytest .raises (UnavailableError , conn .make_call , "" )
117
117
118
118
119
119
def test_post_retry_header_time_2 ():
120
- with mock .patch ("umapi_client.connection.requests.post" ) as mock_post :
120
+ with mock .patch ("umapi_client.connection.requests.Session. post" ) as mock_post :
121
121
mock_post .return_value = MockResponse (502 , headers = {"Retry-After" : formatdate (time .time () + 2.5 )})
122
122
conn = Connection (** mock_connection_params )
123
123
pytest .raises (UnavailableError , conn .make_call , "" , "[3, 5]" )
124
124
125
125
126
126
def test_get_retry_header_0 ():
127
- with mock .patch ("umapi_client.connection.requests.get" ) as mock_get :
127
+ with mock .patch ("umapi_client.connection.requests.Session. get" ) as mock_get :
128
128
mock_get .return_value = MockResponse (503 , headers = {"Retry-After" : "0" })
129
129
conn = Connection (** mock_connection_params )
130
130
pytest .raises (UnavailableError , conn .make_call , "" )
131
131
132
132
133
133
def test_post_retry_header_0 ():
134
- with mock .patch ("umapi_client.connection.requests.post" ) as mock_post :
134
+ with mock .patch ("umapi_client.connection.requests.Session. post" ) as mock_post :
135
135
mock_post .return_value = MockResponse (503 , headers = {"Retry-After" : "0" })
136
136
conn = Connection (** mock_connection_params )
137
137
pytest .raises (UnavailableError , conn .make_call , "" , "[3, 5]" )
138
138
139
139
140
140
def test_get_retry_no_header ():
141
- with mock .patch ("umapi_client.connection.requests.get" ) as mock_get :
141
+ with mock .patch ("umapi_client.connection.requests.Session. get" ) as mock_get :
142
142
mock_get .return_value = MockResponse (504 )
143
143
conn = Connection (** mock_connection_params )
144
144
pytest .raises (UnavailableError , conn .make_call , "" )
145
145
146
146
147
147
def test_post_retry_no_header ():
148
- with mock .patch ("umapi_client.connection.requests.post" ) as mock_post :
148
+ with mock .patch ("umapi_client.connection.requests.Session. post" ) as mock_post :
149
149
mock_post .return_value = MockResponse (504 )
150
150
conn = Connection (** mock_connection_params )
151
151
pytest .raises (UnavailableError , conn .make_call , "" , "[3, 5]" )
152
152
153
153
154
154
# log_stream fixture defined in conftest.py
155
155
def test_get_retry_logging (log_stream ):
156
- with mock .patch ("umapi_client.connection.requests.get" ) as mock_get :
156
+ with mock .patch ("umapi_client.connection.requests.Session. get" ) as mock_get :
157
157
mock_get .return_value = MockResponse (429 , headers = {"Retry-After" : "3" })
158
158
stream , logger = log_stream
159
159
params = dict (mock_connection_params )
@@ -174,7 +174,7 @@ def test_get_retry_logging(log_stream):
174
174
175
175
# log_stream fixture defined in conftest.py
176
176
def test_post_retry_logging (log_stream ):
177
- with mock .patch ("umapi_client.connection.requests.post" ) as mock_post :
177
+ with mock .patch ("umapi_client.connection.requests.Session. post" ) as mock_post :
178
178
mock_post .return_value = MockResponse (429 , headers = {"Retry-After" : "3" })
179
179
stream , logger = log_stream
180
180
params = dict (mock_connection_params )
@@ -194,28 +194,28 @@ def test_post_retry_logging(log_stream):
194
194
195
195
196
196
def test_get_server_fail ():
197
- with mock .patch ("umapi_client.connection.requests.get" ) as mock_get :
197
+ with mock .patch ("umapi_client.connection.requests.Session. get" ) as mock_get :
198
198
mock_get .return_value = MockResponse (500 , text = "500 test server failure" )
199
199
conn = Connection (** mock_connection_params )
200
200
pytest .raises (ServerError , conn .make_call , "" )
201
201
202
202
203
203
def test_post_server_fail ():
204
- with mock .patch ("umapi_client.connection.requests.post" ) as mock_post :
204
+ with mock .patch ("umapi_client.connection.requests.Session. post" ) as mock_post :
205
205
mock_post .return_value = MockResponse (500 , text = "500 test server failure" )
206
206
conn = Connection (** mock_connection_params )
207
207
pytest .raises (ServerError , conn .make_call , "" , "[3, 5]" )
208
208
209
209
210
210
def test_get_request_fail ():
211
- with mock .patch ("umapi_client.connection.requests.get" ) as mock_get :
211
+ with mock .patch ("umapi_client.connection.requests.Session. get" ) as mock_get :
212
212
mock_get .return_value = MockResponse (400 , text = "400 test request failure" )
213
213
conn = Connection (** mock_connection_params )
214
214
pytest .raises (RequestError , conn .make_call , "" )
215
215
216
216
217
217
def test_post_request_fail ():
218
- with mock .patch ("umapi_client.connection.requests.post" ) as mock_post :
218
+ with mock .patch ("umapi_client.connection.requests.Session. post" ) as mock_post :
219
219
mock_post .return_value = MockResponse (400 , text = "400 test request failure" )
220
220
conn = Connection (** mock_connection_params )
221
221
pytest .raises (RequestError , conn .make_call , "" , "[3, 5]" )
0 commit comments