3030
3131
3232def 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 :
3434 mock_get .return_value = MockResponse (200 , body = {"build" : "2559" , "version" : "2.1.54" , "state" :"LIVE" })
3535 conn = Connection (** mock_connection_params )
3636 _ , remote_status = conn .status (remote = True )
3737 assert remote_status == {"endpoint" : "https://test/" , "build" : "2559" , "version" : "2.1.54" , "state" :"LIVE" }
3838
3939
4040def 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 :
4242 mock_get .return_value = MockResponse (404 , text = "404 Not Found" )
4343 conn = Connection (** mock_connection_params )
4444 _ , remote_status = conn .status (remote = True )
4545 assert remote_status ["status" ].startswith ("Unexpected" )
4646
4747
4848def 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 :
5050 mock_get .side_effect = requests .Timeout
5151 conn = Connection (** mock_connection_params )
5252 _ , remote_status = conn .status (remote = True )
5353 assert remote_status ["status" ].startswith ("Unreachable" )
5454
5555
5656def 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 :
5858 mock_get .return_value = MockResponse (200 , body = ["test" , "body" ])
5959 conn = Connection (** mock_connection_params )
6060 assert conn .make_call ("" ).json () == ["test" , "body" ]
6161
6262
6363def 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 :
6565 mock_get .return_value = MockResponse (200 , body = ["test" , "body" ])
6666 conn = Connection (test_mode = True , ** mock_connection_params )
6767 assert conn .make_call ("" ).json () == ["test" , "body" ]
6868
6969
7070def 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 :
7272 mock_post .return_value = MockResponse (200 , body = ["test" , "body" ])
7373 conn = Connection (** mock_connection_params )
7474 assert conn .make_call ("" , [3 , 5 ]).json () == ["test" , "body" ]
7575
7676
7777def 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 :
7979 mock_post .return_value = MockResponse (200 , body = ["test" , "body" ])
8080 conn = Connection (test_mode = True , ** mock_connection_params )
8181 assert conn .make_call ("" , [3 , 5 ]).json () == ["test" , "body" ]
8282
8383
8484def 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 :
8686 mock_get .side_effect = requests .Timeout
8787 conn = Connection (** mock_connection_params )
8888 pytest .raises (UnavailableError , conn .make_call , "" )
8989
9090
9191def 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 :
9393 mock_post .side_effect = requests .Timeout
9494 conn = Connection (** mock_connection_params )
9595 pytest .raises (UnavailableError , conn .make_call , "" , [3 , 5 ])
9696
9797
9898def 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 :
100100 mock_get .return_value = MockResponse (429 , headers = {"Retry-After" : "1" })
101101 conn = Connection (** mock_connection_params )
102102 pytest .raises (UnavailableError , conn .make_call , "" )
103103
104104
105105def 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 :
107107 mock_post .return_value = MockResponse (429 , headers = {"Retry-After" : "1" })
108108 conn = Connection (** mock_connection_params )
109109 pytest .raises (UnavailableError , conn .make_call , "" , "[3, 5]" )
110110
111111
112112def 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 :
114114 mock_get .return_value = MockResponse (502 , headers = {"Retry-After" : formatdate (time .time () + 2.5 )})
115115 conn = Connection (** mock_connection_params )
116116 pytest .raises (UnavailableError , conn .make_call , "" )
117117
118118
119119def 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 :
121121 mock_post .return_value = MockResponse (502 , headers = {"Retry-After" : formatdate (time .time () + 2.5 )})
122122 conn = Connection (** mock_connection_params )
123123 pytest .raises (UnavailableError , conn .make_call , "" , "[3, 5]" )
124124
125125
126126def 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 :
128128 mock_get .return_value = MockResponse (503 , headers = {"Retry-After" : "0" })
129129 conn = Connection (** mock_connection_params )
130130 pytest .raises (UnavailableError , conn .make_call , "" )
131131
132132
133133def 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 :
135135 mock_post .return_value = MockResponse (503 , headers = {"Retry-After" : "0" })
136136 conn = Connection (** mock_connection_params )
137137 pytest .raises (UnavailableError , conn .make_call , "" , "[3, 5]" )
138138
139139
140140def 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 :
142142 mock_get .return_value = MockResponse (504 )
143143 conn = Connection (** mock_connection_params )
144144 pytest .raises (UnavailableError , conn .make_call , "" )
145145
146146
147147def 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 :
149149 mock_post .return_value = MockResponse (504 )
150150 conn = Connection (** mock_connection_params )
151151 pytest .raises (UnavailableError , conn .make_call , "" , "[3, 5]" )
152152
153153
154154# log_stream fixture defined in conftest.py
155155def 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 :
157157 mock_get .return_value = MockResponse (429 , headers = {"Retry-After" : "3" })
158158 stream , logger = log_stream
159159 params = dict (mock_connection_params )
@@ -174,7 +174,7 @@ def test_get_retry_logging(log_stream):
174174
175175# log_stream fixture defined in conftest.py
176176def 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 :
178178 mock_post .return_value = MockResponse (429 , headers = {"Retry-After" : "3" })
179179 stream , logger = log_stream
180180 params = dict (mock_connection_params )
@@ -194,28 +194,28 @@ def test_post_retry_logging(log_stream):
194194
195195
196196def 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 :
198198 mock_get .return_value = MockResponse (500 , text = "500 test server failure" )
199199 conn = Connection (** mock_connection_params )
200200 pytest .raises (ServerError , conn .make_call , "" )
201201
202202
203203def 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 :
205205 mock_post .return_value = MockResponse (500 , text = "500 test server failure" )
206206 conn = Connection (** mock_connection_params )
207207 pytest .raises (ServerError , conn .make_call , "" , "[3, 5]" )
208208
209209
210210def 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 :
212212 mock_get .return_value = MockResponse (400 , text = "400 test request failure" )
213213 conn = Connection (** mock_connection_params )
214214 pytest .raises (RequestError , conn .make_call , "" )
215215
216216
217217def 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 :
219219 mock_post .return_value = MockResponse (400 , text = "400 test request failure" )
220220 conn = Connection (** mock_connection_params )
221221 pytest .raises (RequestError , conn .make_call , "" , "[3, 5]" )
0 commit comments