2222from reportportal_client import OutputType
2323
2424from examples .test_rp_logging import LOG_MESSAGE
25- from tests import REPORT_PORTAL_SERVICE
25+ from tests import REPORT_PORTAL_SERVICE , REQUESTS_SERVICE
2626from tests .helpers import utils
2727
2828TEST_LAUNCH_ID = 'test_launch_id'
2929
3030
31- @mock .patch (REPORT_PORTAL_SERVICE )
32- def test_rp_launch_id (mock_client_init ):
31+ @mock .patch (REQUESTS_SERVICE )
32+ def test_rp_launch_id (mock_requests_init ):
3333 """Verify that RP plugin does not start/stop launch if 'rp_launch_id' set.
3434
35- :param mock_client_init: Pytest fixture
35+ :param mock_requests_init: mocked requests lib
3636 """
3737 variables = dict ()
3838 variables ['rp_launch_id' ] = TEST_LAUNCH_ID
3939 variables .update (utils .DEFAULT_VARIABLES .items ())
40- result = utils .run_pytest_tests (tests = ['examples/test_simple.py' ],
41- variables = variables )
42-
40+ result = utils .run_pytest_tests (tests = ['examples/test_simple.py' ], variables = variables )
4341 assert int (result ) == 0 , 'Exit code should be 0 (no errors)'
4442
45- expect (
46- mock_client_init .call_args_list [0 ][1 ]['launch_id' ] == TEST_LAUNCH_ID )
47-
48- mock_client = mock_client_init .return_value
49- expect (mock_client .start_launch .call_count == 0 ,
50- '"start_launch" method was called' )
51- expect (mock_client .finish_launch .call_count == 0 ,
52- '"finish_launch" method was called' )
53-
54- start_call_args = mock_client .start_test_item .call_args_list
55- finish_call_args = mock_client .finish_test_item .call_args_list
56-
57- expect (len (start_call_args ) == len (finish_call_args ))
58- assert_expectations ()
43+ mock_requests = mock_requests_init .return_value
44+ assert mock_requests .post .call_count == 1
45+ item_start = mock_requests .post .call_args_list [0 ]
46+ assert item_start [0 ][0 ].endswith ('/item' )
47+ assert item_start [1 ]['json' ]['launchUuid' ] == TEST_LAUNCH_ID
5948
6049
6150@mock .patch (REPORT_PORTAL_SERVICE )
@@ -68,8 +57,7 @@ def test_rp_parent_item_id(mock_client_init):
6857 variables = dict ()
6958 variables ['rp_parent_item_id' ] = parent_id
7059 variables .update (utils .DEFAULT_VARIABLES .items ())
71- result = utils .run_pytest_tests (tests = ['examples/test_simple.py' ],
72- variables = variables )
60+ result = utils .run_pytest_tests (tests = ['examples/test_simple.py' ], variables = variables )
7361
7462 assert int (result ) == 0 , 'Exit code should be 0 (no errors)'
7563
@@ -87,34 +75,26 @@ def test_rp_parent_item_id(mock_client_init):
8775 assert_expectations ()
8876
8977
90- @mock .patch (REPORT_PORTAL_SERVICE )
91- def test_rp_parent_item_id_and_rp_launch_id (mock_client_init ):
78+ @mock .patch (REQUESTS_SERVICE )
79+ def test_rp_parent_item_id_and_rp_launch_id (mock_requests_init ):
9280 """Verify RP handles both conf props 'rp_parent_item_id' & 'rp_launch_id'.
9381
94- :param mock_client_init: Pytest fixture
82+ :param mock_requests_init: mocked requests lib
9583 """
9684 parent_id = "parent_id"
9785 variables = dict ()
9886 variables ['rp_parent_item_id' ] = parent_id
99- variables ['rp_launch_id' ] = "test_launch_id"
87+ variables ['rp_launch_id' ] = TEST_LAUNCH_ID
10088 variables .update (utils .DEFAULT_VARIABLES .items ())
101- result = utils .run_pytest_tests (tests = ['examples/test_simple.py' ],
102- variables = variables )
103-
89+ result = utils .run_pytest_tests (tests = ['examples/test_simple.py' ],variables = variables )
10490 assert int (result ) == 0 , 'Exit code should be 0 (no errors)'
10591
106- mock_client = mock_client_init .return_value
107- expect (mock_client .start_launch .call_count == 0 ,
108- '"start_launch" method was called' )
109- expect (mock_client .finish_launch .call_count == 0 ,
110- '"finish_launch" method was called' )
111-
112- start_call_args = mock_client .start_test_item .call_args_list
113- finish_call_args = mock_client .finish_test_item .call_args_list
92+ mock_requests = mock_requests_init .return_value
93+ assert mock_requests .post .call_count == 1
94+ item_start = mock_requests .post .call_args_list [0 ]
95+ assert item_start [0 ][0 ].endswith (f'/item/{ parent_id } ' )
96+ assert item_start [1 ]['json' ]['launchUuid' ] == TEST_LAUNCH_ID
11497
115- expect (len (start_call_args ) == len (finish_call_args ))
116- expect (start_call_args [0 ][1 ]["parent_item_id" ] == parent_id )
117- assert_expectations ()
11898
11999
120100@mock .patch (REPORT_PORTAL_SERVICE )
0 commit comments