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
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+
6370def 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 :
6572 mock_post .return_value = MockResponse (200 , body = ["test" , "body" ])
6673 conn = Connection (** mock_connection_params )
6774 assert conn .make_call ("" , [3 , 5 ]).json () == ["test" , "body" ]
6875
6976
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+
7084def 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 :
7286 mock_get .side_effect = requests .Timeout
7387 conn = Connection (** mock_connection_params )
7488 pytest .raises (UnavailableError , conn .make_call , "" )
7589
7690
7791def 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 :
7993 mock_post .side_effect = requests .Timeout
8094 conn = Connection (** mock_connection_params )
8195 pytest .raises (UnavailableError , conn .make_call , "" , [3 , 5 ])
8296
8397
8498def 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 :
86100 mock_get .return_value = MockResponse (429 , headers = {"Retry-After" : "1" })
87101 conn = Connection (** mock_connection_params )
88102 pytest .raises (UnavailableError , conn .make_call , "" )
89103
90104
91105def 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 :
93107 mock_post .return_value = MockResponse (429 , headers = {"Retry-After" : "1" })
94108 conn = Connection (** mock_connection_params )
95109 pytest .raises (UnavailableError , conn .make_call , "" , "[3, 5]" )
96110
97111
98112def 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 :
100114 mock_get .return_value = MockResponse (502 , headers = {"Retry-After" : formatdate (time .time () + 2.5 )})
101115 conn = Connection (** mock_connection_params )
102116 pytest .raises (UnavailableError , conn .make_call , "" )
103117
104118
105119def 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 :
107121 mock_post .return_value = MockResponse (502 , headers = {"Retry-After" : formatdate (time .time () + 2.5 )})
108122 conn = Connection (** mock_connection_params )
109123 pytest .raises (UnavailableError , conn .make_call , "" , "[3, 5]" )
110124
111125
112126def 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 :
114128 mock_get .return_value = MockResponse (503 , headers = {"Retry-After" : "0" })
115129 conn = Connection (** mock_connection_params )
116130 pytest .raises (UnavailableError , conn .make_call , "" )
117131
118132
119133def 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 :
121135 mock_post .return_value = MockResponse (503 , headers = {"Retry-After" : "0" })
122136 conn = Connection (** mock_connection_params )
123137 pytest .raises (UnavailableError , conn .make_call , "" , "[3, 5]" )
124138
125139
126140def 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 :
128142 mock_get .return_value = MockResponse (504 )
129143 conn = Connection (** mock_connection_params )
130144 pytest .raises (UnavailableError , conn .make_call , "" )
131145
132146
133147def 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 :
135149 mock_post .return_value = MockResponse (504 )
136150 conn = Connection (** mock_connection_params )
137151 pytest .raises (UnavailableError , conn .make_call , "" , "[3, 5]" )
138152
139153
140154# log_stream fixture defined in conftest.py
141155def 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 :
143157 mock_get .return_value = MockResponse (429 , headers = {"Retry-After" : "3" })
144158 stream , logger = log_stream
145159 params = dict (mock_connection_params )
@@ -160,7 +174,7 @@ def test_get_retry_logging(log_stream):
160174
161175# log_stream fixture defined in conftest.py
162176def 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 :
164178 mock_post .return_value = MockResponse (429 , headers = {"Retry-After" : "3" })
165179 stream , logger = log_stream
166180 params = dict (mock_connection_params )
@@ -180,28 +194,28 @@ def test_post_retry_logging(log_stream):
180194
181195
182196def 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 :
184198 mock_get .return_value = MockResponse (500 , text = "500 test server failure" )
185199 conn = Connection (** mock_connection_params )
186200 pytest .raises (ServerError , conn .make_call , "" )
187201
188202
189203def 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 :
191205 mock_post .return_value = MockResponse (500 , text = "500 test server failure" )
192206 conn = Connection (** mock_connection_params )
193207 pytest .raises (ServerError , conn .make_call , "" , "[3, 5]" )
194208
195209
196210def 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 :
198212 mock_get .return_value = MockResponse (400 , text = "400 test request failure" )
199213 conn = Connection (** mock_connection_params )
200214 pytest .raises (RequestError , conn .make_call , "" )
201215
202216
203217def 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 :
205219 mock_post .return_value = MockResponse (400 , text = "400 test request failure" )
206220 conn = Connection (** mock_connection_params )
207221 pytest .raises (RequestError , conn .make_call , "" , "[3, 5]" )
0 commit comments