2020from requests import Response
2121from requests .exceptions import ReadTimeout
2222
23+ from conftest import DummyResponse
2324from reportportal_client import RPClient
2425from reportportal_client .core .rp_requests import RPRequestLog
2526from reportportal_client .helpers import timestamp
@@ -38,7 +39,7 @@ def response_error(*args, **kwargs):
3839
3940def invalid_response (* args , ** kwargs ):
4041 result = Response ()
41- result ._content = "<html><head><title>Hello World!</title></head></html>"
42+ result ._content = "<html><head><title>Hello World!</title></head></html>" . encode ( "ASCII" )
4243 result .status_code = 200
4344 return result
4445
@@ -60,6 +61,7 @@ def invalid_response(*args, **kwargs):
6061)
6162def test_connection_errors (rp_client , requests_method , client_method , client_params ):
6263 rp_client ._RPClient__launch_uuid = "test_launch_id"
64+ rp_client .session .get .return_value = DummyResponse ()
6365 getattr (rp_client .session , requests_method ).side_effect = connection_error
6466 result = getattr (rp_client , client_method )(* client_params )
6567 assert result is None
@@ -105,20 +107,20 @@ def get_call(*args, **kwargs):
105107
106108@mock .patch ("reportportal_client.client.getenv" )
107109@mock .patch ("reportportal_client.client.send_event" )
108- def test_skip_statistics (send_event , getenv ):
110+ def test_skip_statistics (send_event , getenv , rp_client ):
109111 getenv .return_value = "1"
110112 client = RPClient ("http://endpoint" , "project" , "api_key" )
111- client .session = mock . Mock ()
113+ client .session = rp_client . session
112114 client .start_launch ("Test Launch" , timestamp ())
113115 assert mock .call ("start_launch" , None , None ) not in send_event .mock_calls
114116
115117
116118@mock .patch ("reportportal_client.client.getenv" )
117119@mock .patch ("reportportal_client.client.send_event" )
118- def test_statistics (send_event , getenv ):
120+ def test_statistics (send_event , getenv , rp_client ):
119121 getenv .return_value = ""
120122 client = RPClient ("http://endpoint" , "project" , "api_key" )
121- client .session = mock . Mock ()
123+ client .session = rp_client . session
122124 client .start_launch ("Test Launch" , timestamp ())
123125 assert mock .call ("start_launch" , None , None ) in send_event .mock_calls
124126
@@ -186,20 +188,20 @@ def test_empty_api_key_argument(warn):
186188 assert client .api_key == api_key
187189
188190
189- def test_launch_uuid_print ():
191+ def test_launch_uuid_print (rp_client ):
190192 str_io = StringIO ()
191193 output_mock = mock .Mock ()
192194 output_mock .get_output .side_effect = lambda : str_io
193195 client = RPClient (
194196 endpoint = "http://endpoint" , project = "project" , api_key = "test" , launch_uuid_print = True , print_output = output_mock
195197 )
196- client .session = mock . Mock ()
197- client ._skip_analytics = True
198+ client .session = rp_client . session
199+ client ._skip_analytics = " True"
198200 client .start_launch ("Test Launch" , timestamp ())
199201 assert "ReportPortal Launch UUID: " in str_io .getvalue ()
200202
201203
202- def test_no_launch_uuid_print ():
204+ def test_no_launch_uuid_print (rp_client ):
203205 str_io = StringIO ()
204206 output_mock = mock .Mock ()
205207 output_mock .get_output .side_effect = lambda : str_io
@@ -210,27 +212,27 @@ def test_no_launch_uuid_print():
210212 launch_uuid_print = False ,
211213 print_output = output_mock ,
212214 )
213- client .session = mock . Mock ()
214- client ._skip_analytics = True
215+ client .session = rp_client . session
216+ client ._skip_analytics = " True"
215217 client .start_launch ("Test Launch" , timestamp ())
216218 assert "ReportPortal Launch UUID: " not in str_io .getvalue ()
217219
218220
219221@mock .patch ("reportportal_client.client.sys.stdout" , new_callable = StringIO )
220- def test_launch_uuid_print_default_io (mock_stdout ):
222+ def test_launch_uuid_print_default_io (mock_stdout , rp_client ):
221223 client = RPClient (endpoint = "http://endpoint" , project = "project" , api_key = "test" , launch_uuid_print = True )
222- client .session = mock . Mock ()
223- client ._skip_analytics = True
224+ client .session = rp_client . session
225+ client ._skip_analytics = " True"
224226 client .start_launch ("Test Launch" , timestamp ())
225227
226228 assert "ReportPortal Launch UUID: " in mock_stdout .getvalue ()
227229
228230
229231@mock .patch ("reportportal_client.client.sys.stdout" , new_callable = StringIO )
230- def test_launch_uuid_print_default_print (mock_stdout ):
232+ def test_launch_uuid_print_default_print (mock_stdout , rp_client ):
231233 client = RPClient (endpoint = "http://endpoint" , project = "project" , api_key = "test" )
232- client .session = mock . Mock ()
233- client ._skip_analytics = True
234+ client .session = rp_client . session
235+ client ._skip_analytics = " True"
234236 client .start_launch ("Test Launch" , timestamp ())
235237
236238 assert "ReportPortal Launch UUID: " not in mock_stdout .getvalue ()
@@ -256,6 +258,7 @@ def test_client_pickling():
256258def test_attribute_truncation (rp_client : RPClient , method , call_method , arguments ):
257259 # noinspection PyTypeChecker
258260 session : mock .Mock = rp_client .session
261+ session .get .return_value = DummyResponse ()
259262 if method != "start_launch" :
260263 rp_client ._RPClient__launch_uuid = "test_launch_id"
261264
@@ -285,8 +288,11 @@ def test_http_timeout_bypass(method, call_method, arguments):
285288 http_timeout = (35.1 , 33.3 )
286289 rp_client = RPClient ("http://endpoint" , "project" , "api_key" , http_timeout = http_timeout , log_batch_size = 1 )
287290 session : mock .Mock = mock .Mock ()
291+ session .get .return_value = DummyResponse ()
292+ session .post .return_value = DummyResponse ()
293+ session .put .return_value = DummyResponse ()
288294 rp_client .session = session
289- rp_client ._skip_analytics = True
295+ rp_client ._skip_analytics = " True"
290296
291297 if method != "start_launch" :
292298 rp_client ._RPClient__launch_uuid = "test_launch_id"
0 commit comments