Skip to content

Commit 3877b2b

Browse files
authored
Merge pull request #296 from reportportal/issue-report-test
Issue report test
2 parents dd0c09f + 338eff3 commit 3877b2b

File tree

5 files changed

+160
-4
lines changed

5 files changed

+160
-4
lines changed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ The following parameters are optional:
110110
- :code:`rp_hierarchy_parametrize = True` - Enables hierarchy parametrized tests, default `False`. Doesn't support 'xdist' plugin.
111111
- :code:`rp_hierarchy_dirs_level = 0` - Directory starting hierarchy level (from pytest.ini level) (default `0`)
112112
- :code:`rp_issue_marks = 'xfail' 'issue'` - Pytest marks that could be used to get issue information (id, type, reason)
113-
- :code:`rp_issue_system_url = http://bugzilla.some.com/show_bug.cgi?id={issue_id}` - issue URL (issue_id will be filled by parameter from pytest mark)
113+
- :code:`rp_issue_system_url = https://bugzilla.some.com/show_bug.cgi?id={issue_id}` - issue URL (issue_id will be filled by parameter from pytest mark)
114114
- :code:`rp_issue_id_marks = True` - Enables adding marks for issue ids (e.g. "issue:123456")
115115
- :code:`rp_verify_ssl = True` - Verify SSL when connecting to the server
116116
- :code:`rp_display_suite_test_file = True` - In case of True, include the suite's relative file path in the launch name as a convention of "<RELATIVE_FILE_PATH>::<SUITE_NAME>". In case of False, set the launch name to be the suite name only - this flag is relevant only when "rp_hierarchy_module" flag is set to False

examples/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""This package contains integration test examples for the project.
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+
"""

examples/test_issue_id.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright (c) 2022 https://reportportal.io .
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# https://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License
13+
14+
import pytest
15+
16+
ID = 'ABC-1234'
17+
REASON = 'some_bug'
18+
TYPE = 'PB'
19+
20+
21+
@pytest.mark.issue(issue_id=ID, reason=REASON, issue_type=TYPE)
22+
def test_issue_id():
23+
assert False

tests/helpers/utils.py

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,68 @@
2020

2121
DEFAULT_VARIABLES = {
2222
'rp_launch': 'Pytest',
23-
'rp_endpoint': "http://localhost:8080",
24-
'rp_project': "default_personal",
25-
'rp_uuid': "test_uuid",
23+
'rp_endpoint': 'http://localhost:8080',
24+
'rp_project': 'default_personal',
25+
'rp_uuid': 'test_uuid',
2626
'rp_hierarchy_dir_path_separator': '/'
2727
}
2828

29+
DEFAULT_PROJECT_SETTINGS = {
30+
'project': 2,
31+
'subTypes': {
32+
'NO_DEFECT': [
33+
{
34+
'id': 4,
35+
'locator': 'nd001',
36+
'typeRef': 'NO_DEFECT',
37+
'longName': 'No Defect',
38+
'shortName': 'ND',
39+
'color': "#777777"
40+
}
41+
],
42+
'TO_INVESTIGATE': [
43+
{
44+
'id': 1,
45+
'locator': 'ti001',
46+
'typeRef': 'TO_INVESTIGATE',
47+
'longName': 'To Investigate',
48+
'shortName': 'TI',
49+
'color': '#ffb743'
50+
}
51+
],
52+
'AUTOMATION_BUG': [
53+
{
54+
'id': 2,
55+
'locator': 'ab001',
56+
'typeRef': 'AUTOMATION_BUG',
57+
'longName': 'Automation Bug',
58+
'shortName': 'AB',
59+
'color': '#f7d63e'
60+
}
61+
],
62+
'PRODUCT_BUG': [
63+
{
64+
'id': 3,
65+
'locator': 'pb001',
66+
'typeRef': 'PRODUCT_BUG',
67+
'longName': 'Product Bug',
68+
'shortName': 'PB',
69+
'color': '#ec3900'
70+
}
71+
],
72+
'SYSTEM_ISSUE': [
73+
{
74+
'id': 5,
75+
'locator': 'si001',
76+
'typeRef': 'SYSTEM_ISSUE',
77+
'longName': 'System Issue',
78+
'shortName': 'SI',
79+
'color': '#0274d1'
80+
}
81+
]
82+
}
83+
}
84+
2985

3086
def run_pytest_tests(tests=None, variables=None):
3187
"""Run specific pytest tests.
@@ -52,3 +108,7 @@ def run_pytest_tests(tests=None, variables=None):
52108
def item_id_gen(**kwargs):
53109
return "{}-{}-{}".format(kwargs['name'], str(round(time.time() * 1000)),
54110
random.randint(0, 9999))
111+
112+
113+
def project_settings(**kwargs):
114+
return DEFAULT_PROJECT_SETTINGS
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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

Comments
 (0)