|
| 1 | +"""This module includes integration test for issue type reporting.""" |
| 2 | + |
| 3 | +# Copyright (c) 2022 https://reportportal.io . |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License |
| 15 | + |
| 16 | +from delayed_assert import expect, assert_expectations |
| 17 | +from six.moves import mock |
| 18 | + |
| 19 | +from examples import test_issue_id |
| 20 | +from tests import REPORT_PORTAL_SERVICE |
| 21 | +from tests.helpers import utils |
| 22 | + |
| 23 | +ISSUE_PLACEHOLDER = '{issue_id}' |
| 24 | +ISSUE_URL_PATTERN = 'https://bugzilla.some.com/show_bug.cgi?id=' + \ |
| 25 | + ISSUE_PLACEHOLDER |
| 26 | + |
| 27 | + |
| 28 | +@mock.patch(REPORT_PORTAL_SERVICE) |
| 29 | +def test_issue_report(mock_client_init): |
| 30 | + """Verify agent reports issue ids and defect type. |
| 31 | +
|
| 32 | + :param mock_client_init: Pytest fixture |
| 33 | + """ |
| 34 | + mock_client = mock_client_init.return_value |
| 35 | + mock_client.start_test_item.side_effect = utils.item_id_gen |
| 36 | + mock_client.get_project_settings.side_effect = utils.project_settings |
| 37 | + |
| 38 | + variables = dict() |
| 39 | + variables['rp_issue_system_url'] = ISSUE_URL_PATTERN |
| 40 | + variables['rp_issue_id_marks'] = True |
| 41 | + variables['rp_issue_marks'] = 'issue' |
| 42 | + variables.update(utils.DEFAULT_VARIABLES.items()) |
| 43 | + result = utils.run_pytest_tests(tests=['examples/test_issue_id.py'], |
| 44 | + variables=variables) |
| 45 | + assert int(result) == 1, 'Exit code should be 1 (test failed)' |
| 46 | + |
| 47 | + call_args = mock_client.finish_test_item.call_args_list |
| 48 | + finish_test_step = call_args[0][1] |
| 49 | + issue = finish_test_step['issue'] |
| 50 | + expect(issue['issueType'] == 'pb001') |
| 51 | + expect(issue['comment'] is not None) |
| 52 | + assert_expectations() |
| 53 | + comments = issue['comment'].split('\n') |
| 54 | + assert len(comments) == 1 |
| 55 | + comment = comments[0] |
| 56 | + assert comment == "* {}: [{}]({})" \ |
| 57 | + .format(test_issue_id.REASON, test_issue_id.ID, |
| 58 | + ISSUE_URL_PATTERN.replace(ISSUE_PLACEHOLDER, test_issue_id.ID)) |
0 commit comments