20
20
from requests import Response
21
21
from requests .exceptions import ReadTimeout
22
22
23
+ from conftest import DummyResponse
23
24
from reportportal_client import RPClient
24
25
from reportportal_client .core .rp_requests import RPRequestLog
25
26
from reportportal_client .helpers import timestamp
@@ -38,7 +39,7 @@ def response_error(*args, **kwargs):
38
39
39
40
def invalid_response (* args , ** kwargs ):
40
41
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" )
42
43
result .status_code = 200
43
44
return result
44
45
@@ -60,6 +61,7 @@ def invalid_response(*args, **kwargs):
60
61
)
61
62
def test_connection_errors (rp_client , requests_method , client_method , client_params ):
62
63
rp_client ._RPClient__launch_uuid = "test_launch_id"
64
+ rp_client .session .get .return_value = DummyResponse ()
63
65
getattr (rp_client .session , requests_method ).side_effect = connection_error
64
66
result = getattr (rp_client , client_method )(* client_params )
65
67
assert result is None
@@ -105,20 +107,20 @@ def get_call(*args, **kwargs):
105
107
106
108
@mock .patch ("reportportal_client.client.getenv" )
107
109
@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 ):
109
111
getenv .return_value = "1"
110
112
client = RPClient ("http://endpoint" , "project" , "api_key" )
111
- client .session = mock . Mock ()
113
+ client .session = rp_client . session
112
114
client .start_launch ("Test Launch" , timestamp ())
113
115
assert mock .call ("start_launch" , None , None ) not in send_event .mock_calls
114
116
115
117
116
118
@mock .patch ("reportportal_client.client.getenv" )
117
119
@mock .patch ("reportportal_client.client.send_event" )
118
- def test_statistics (send_event , getenv ):
120
+ def test_statistics (send_event , getenv , rp_client ):
119
121
getenv .return_value = ""
120
122
client = RPClient ("http://endpoint" , "project" , "api_key" )
121
- client .session = mock . Mock ()
123
+ client .session = rp_client . session
122
124
client .start_launch ("Test Launch" , timestamp ())
123
125
assert mock .call ("start_launch" , None , None ) in send_event .mock_calls
124
126
@@ -186,20 +188,20 @@ def test_empty_api_key_argument(warn):
186
188
assert client .api_key == api_key
187
189
188
190
189
- def test_launch_uuid_print ():
191
+ def test_launch_uuid_print (rp_client ):
190
192
str_io = StringIO ()
191
193
output_mock = mock .Mock ()
192
194
output_mock .get_output .side_effect = lambda : str_io
193
195
client = RPClient (
194
196
endpoint = "http://endpoint" , project = "project" , api_key = "test" , launch_uuid_print = True , print_output = output_mock
195
197
)
196
- client .session = mock . Mock ()
197
- client ._skip_analytics = True
198
+ client .session = rp_client . session
199
+ client ._skip_analytics = " True"
198
200
client .start_launch ("Test Launch" , timestamp ())
199
201
assert "ReportPortal Launch UUID: " in str_io .getvalue ()
200
202
201
203
202
- def test_no_launch_uuid_print ():
204
+ def test_no_launch_uuid_print (rp_client ):
203
205
str_io = StringIO ()
204
206
output_mock = mock .Mock ()
205
207
output_mock .get_output .side_effect = lambda : str_io
@@ -210,27 +212,27 @@ def test_no_launch_uuid_print():
210
212
launch_uuid_print = False ,
211
213
print_output = output_mock ,
212
214
)
213
- client .session = mock . Mock ()
214
- client ._skip_analytics = True
215
+ client .session = rp_client . session
216
+ client ._skip_analytics = " True"
215
217
client .start_launch ("Test Launch" , timestamp ())
216
218
assert "ReportPortal Launch UUID: " not in str_io .getvalue ()
217
219
218
220
219
221
@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 ):
221
223
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"
224
226
client .start_launch ("Test Launch" , timestamp ())
225
227
226
228
assert "ReportPortal Launch UUID: " in mock_stdout .getvalue ()
227
229
228
230
229
231
@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 ):
231
233
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"
234
236
client .start_launch ("Test Launch" , timestamp ())
235
237
236
238
assert "ReportPortal Launch UUID: " not in mock_stdout .getvalue ()
@@ -256,6 +258,7 @@ def test_client_pickling():
256
258
def test_attribute_truncation (rp_client : RPClient , method , call_method , arguments ):
257
259
# noinspection PyTypeChecker
258
260
session : mock .Mock = rp_client .session
261
+ session .get .return_value = DummyResponse ()
259
262
if method != "start_launch" :
260
263
rp_client ._RPClient__launch_uuid = "test_launch_id"
261
264
@@ -285,8 +288,11 @@ def test_http_timeout_bypass(method, call_method, arguments):
285
288
http_timeout = (35.1 , 33.3 )
286
289
rp_client = RPClient ("http://endpoint" , "project" , "api_key" , http_timeout = http_timeout , log_batch_size = 1 )
287
290
session : mock .Mock = mock .Mock ()
291
+ session .get .return_value = DummyResponse ()
292
+ session .post .return_value = DummyResponse ()
293
+ session .put .return_value = DummyResponse ()
288
294
rp_client .session = session
289
- rp_client ._skip_analytics = True
295
+ rp_client ._skip_analytics = " True"
290
296
291
297
if method != "start_launch" :
292
298
rp_client ._RPClient__launch_uuid = "test_launch_id"
0 commit comments