1717from unittest import mock
1818
1919import pytest
20-
2120from delayed_assert import expect , assert_expectations
2221from reportportal_client import OutputType
2322
2423from examples .test_rp_logging import LOG_MESSAGE
25- from tests import REPORT_PORTAL_SERVICE
24+ from tests import REPORT_PORTAL_SERVICE , REQUESTS_SERVICE
2625from tests .helpers import utils
2726
2827TEST_LAUNCH_ID = 'test_launch_id'
2928
3029
31- @mock .patch (REPORT_PORTAL_SERVICE )
32- def test_rp_launch_id (mock_client_init ):
30+ @mock .patch (REQUESTS_SERVICE )
31+ def test_rp_launch_id (mock_requests_init ):
3332 """Verify that RP plugin does not start/stop launch if 'rp_launch_id' set.
3433
35- :param mock_client_init: Pytest fixture
34+ :param mock_requests_init: mocked requests lib
3635 """
3736 variables = dict ()
3837 variables ['rp_launch_id' ] = TEST_LAUNCH_ID
3938 variables .update (utils .DEFAULT_VARIABLES .items ())
40- result = utils .run_pytest_tests (tests = ['examples/test_simple.py' ],
41- variables = variables )
42-
39+ result = utils .run_pytest_tests (tests = ['examples/test_simple.py' ], variables = variables )
4340 assert int (result ) == 0 , 'Exit code should be 0 (no errors)'
4441
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 ()
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
5947
6048
6149@mock .patch (REPORT_PORTAL_SERVICE )
@@ -68,8 +56,7 @@ def test_rp_parent_item_id(mock_client_init):
6856 variables = dict ()
6957 variables ['rp_parent_item_id' ] = parent_id
7058 variables .update (utils .DEFAULT_VARIABLES .items ())
71- result = utils .run_pytest_tests (tests = ['examples/test_simple.py' ],
72- variables = variables )
59+ result = utils .run_pytest_tests (tests = ['examples/test_simple.py' ], variables = variables )
7360
7461 assert int (result ) == 0 , 'Exit code should be 0 (no errors)'
7562
@@ -87,34 +74,25 @@ def test_rp_parent_item_id(mock_client_init):
8774 assert_expectations ()
8875
8976
90- @mock .patch (REPORT_PORTAL_SERVICE )
91- def test_rp_parent_item_id_and_rp_launch_id (mock_client_init ):
77+ @mock .patch (REQUESTS_SERVICE )
78+ def test_rp_parent_item_id_and_rp_launch_id (mock_requests_init ):
9279 """Verify RP handles both conf props 'rp_parent_item_id' & 'rp_launch_id'.
9380
94- :param mock_client_init: Pytest fixture
81+ :param mock_requests_init: mocked requests lib
9582 """
9683 parent_id = "parent_id"
9784 variables = dict ()
9885 variables ['rp_parent_item_id' ] = parent_id
99- variables ['rp_launch_id' ] = "test_launch_id"
86+ variables ['rp_launch_id' ] = TEST_LAUNCH_ID
10087 variables .update (utils .DEFAULT_VARIABLES .items ())
101- result = utils .run_pytest_tests (tests = ['examples/test_simple.py' ],
102- variables = variables )
103-
88+ result = utils .run_pytest_tests (tests = ['examples/test_simple.py' ], variables = variables )
10489 assert int (result ) == 0 , 'Exit code should be 0 (no errors)'
10590
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
114-
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 ()
91+ mock_requests = mock_requests_init .return_value
92+ assert mock_requests .post .call_count == 1
93+ item_start = mock_requests .post .call_args_list [0 ]
94+ assert item_start [0 ][0 ].endswith (f'/item/{ parent_id } ' )
95+ assert item_start [1 ]['json' ]['launchUuid' ] == TEST_LAUNCH_ID
11896
11997
12098@mock .patch (REPORT_PORTAL_SERVICE )
0 commit comments