2121from reportportal_client import OutputType
2222
2323from examples .test_rp_logging import LOG_MESSAGE
24- from tests import REPORT_PORTAL_SERVICE , REQUESTS_SERVICE
24+ from tests import REPORT_PORTAL_SERVICE
2525from tests .helpers import utils
2626
2727TEST_LAUNCH_ID = "test_launch_id"
2828
2929
30- @mock .patch (REQUESTS_SERVICE )
31- def test_rp_launch_id ( mock_requests_init ):
30+ @mock .patch (REPORT_PORTAL_SERVICE )
31+ def test_rp_launch_uuid ( mock_client_init ):
3232 """Verify that RP plugin does not start/stop launch if 'rp_launch_id' set.
3333
34- :param mock_requests_init : mocked requests lib
34+ :param mock_client_init : mocked client class
3535 """
3636 variables = dict ()
3737 variables ["rp_launch_id" ] = TEST_LAUNCH_ID
3838 variables .update (utils .DEFAULT_VARIABLES .items ())
3939 result = utils .run_pytest_tests (tests = ["examples/test_simple.py" ], variables = variables )
4040 assert int (result ) == 0 , "Exit code should be 0 (no errors)"
4141
42- mock_requests = mock_requests_init .return_value
43- assert mock_requests .post .call_count == 1
44- item_start = mock_requests .post .call_args_list [0 ]
45- assert item_start [0 ][0 ].endswith ("/item" )
46- assert item_start [1 ]["json" ]["launchUuid" ] == TEST_LAUNCH_ID
42+ assert mock_client_init .call_count == 1
43+ constructor_call = mock_client_init .call_args_list [0 ]
44+ assert "launch_uuid" in constructor_call [1 ]
45+ assert constructor_call [1 ]["launch_uuid" ] == TEST_LAUNCH_ID
4746
4847
4948@mock .patch (REPORT_PORTAL_SERVICE )
@@ -72,11 +71,11 @@ def test_rp_parent_item_id(mock_client_init):
7271 assert_expectations ()
7372
7473
75- @mock .patch (REQUESTS_SERVICE )
76- def test_rp_parent_item_id_and_rp_launch_id (mock_requests_init ):
74+ @mock .patch (REPORT_PORTAL_SERVICE )
75+ def test_rp_parent_item_id_and_rp_launch_id (mock_client_init ):
7776 """Verify RP handles both conf props 'rp_parent_item_id' & 'rp_launch_id'.
7877
79- :param mock_requests_init : mocked requests lib
78+ :param mock_client_init : mocked client class
8079 """
8180 parent_id = "parent_id"
8281 variables = dict ()
@@ -86,11 +85,18 @@ def test_rp_parent_item_id_and_rp_launch_id(mock_requests_init):
8685 result = utils .run_pytest_tests (tests = ["examples/test_simple.py" ], variables = variables )
8786 assert int (result ) == 0 , "Exit code should be 0 (no errors)"
8887
89- mock_requests = mock_requests_init .return_value
90- assert mock_requests .post .call_count == 1
91- item_start = mock_requests .post .call_args_list [0 ]
92- assert item_start [0 ][0 ].endswith (f"/item/{ parent_id } " )
93- assert item_start [1 ]["json" ]["launchUuid" ] == TEST_LAUNCH_ID
88+ assert mock_client_init .call_count == 1
89+ constructor_call = mock_client_init .call_args_list [0 ]
90+ assert "launch_uuid" in constructor_call [1 ]
91+ assert constructor_call [1 ]["launch_uuid" ] == TEST_LAUNCH_ID
92+
93+ mock_client = mock_client_init .return_value
94+
95+ assert mock_client .start_test_item .call_count > 0
96+ item_create = mock_client .start_test_item .call_args_list [0 ]
97+ call_kwargs = item_create [1 ]
98+ assert "parent_item_id" in call_kwargs
99+ assert call_kwargs ["parent_item_id" ] == parent_id
94100
95101
96102@mock .patch (REPORT_PORTAL_SERVICE )
@@ -112,9 +118,9 @@ def test_rp_log_format(mock_client_init):
112118
113119
114120@mock .patch (REPORT_PORTAL_SERVICE )
115- def test_rp_log_batch_payload_size (mock_client_init ):
121+ def test_rp_log_batch_payload_limit (mock_client_init ):
116122 log_size = 123456
117- variables = {"rp_log_batch_payload_size " : log_size }
123+ variables = {"rp_log_batch_payload_limit " : log_size }
118124 variables .update (utils .DEFAULT_VARIABLES .items ())
119125
120126 result = utils .run_pytest_tests (["examples/test_rp_logging.py" ], variables = variables )
@@ -123,7 +129,7 @@ def test_rp_log_batch_payload_size(mock_client_init):
123129 expect (mock_client_init .call_count == 1 )
124130
125131 constructor_args = mock_client_init .call_args_list [0 ][1 ]
126- expect (constructor_args ["log_batch_payload_size " ] == log_size )
132+ expect (constructor_args ["log_batch_payload_limit " ] == log_size )
127133 assert_expectations ()
128134
129135
@@ -156,56 +162,13 @@ def test_rp_api_key(mock_client_init):
156162 assert_expectations ()
157163
158164
159- @mock .patch (REPORT_PORTAL_SERVICE )
160- def test_rp_uuid (mock_client_init ):
161- api_key = "rp_api_key"
162- variables = dict (utils .DEFAULT_VARIABLES )
163- del variables ["rp_api_key" ]
164- variables .update ({"rp_uuid" : api_key }.items ())
165-
166- with warnings .catch_warnings (record = True ) as w :
167- result = utils .run_pytest_tests (["examples/test_rp_logging.py" ], variables = variables )
168- assert int (result ) == 0 , "Exit code should be 0 (no errors)"
169-
170- expect (mock_client_init .call_count == 1 )
171-
172- constructor_args = mock_client_init .call_args_list [0 ][1 ]
173- expect (constructor_args ["api_key" ] == api_key )
174- expect (len (filter_agent_calls (w )) == 1 )
175- assert_expectations ()
176-
177-
178- @mock .patch (REPORT_PORTAL_SERVICE )
179- def test_rp_api_key_priority (mock_client_init ):
180- api_key = "rp_api_key"
181- variables = dict (utils .DEFAULT_VARIABLES )
182- variables .update ({"rp_api_key" : api_key , "rp_uuid" : "rp_uuid" }.items ())
183-
184- with warnings .catch_warnings (record = True ) as w :
185- result = utils .run_pytest_tests (["examples/test_rp_logging.py" ], variables = variables )
186- assert int (result ) == 0 , "Exit code should be 0 (no errors)"
187-
188- expect (mock_client_init .call_count == 1 )
189-
190- constructor_args = mock_client_init .call_args_list [0 ][1 ]
191- expect (constructor_args ["api_key" ] == api_key )
192- expect (len (filter_agent_calls (w )) == 0 )
193- assert_expectations ()
194-
195-
196- @mock .patch (REPORT_PORTAL_SERVICE )
197- def test_rp_api_key_empty (mock_client_init ):
165+ def test_rp_api_key_empty ():
198166 api_key = ""
199167 variables = dict (utils .DEFAULT_VARIABLES )
200168 variables .update ({"rp_api_key" : api_key }.items ())
201169
202- with warnings .catch_warnings (record = True ) as w :
203- result = utils .run_pytest_tests (["examples/test_rp_logging.py" ], variables = variables )
204- assert int (result ) == 0 , "Exit code should be 0 (no errors)"
205-
206- expect (mock_client_init .call_count == 0 )
207- expect (len (filter_agent_calls (w )) == 1 )
208- assert_expectations ()
170+ result = utils .run_pytest_tests (["examples/test_rp_logging.py" ], variables = variables )
171+ assert int (result ) == 3 , "Exit code should be 3 (exited with internal error)"
209172
210173
211174@mock .patch (REPORT_PORTAL_SERVICE )
0 commit comments