Skip to content

Commit 3486d2d

Browse files
authored
Code reference bypass
1 parent f918ed0 commit 3486d2d

File tree

4 files changed

+91
-15
lines changed

4 files changed

+91
-15
lines changed

reportportal_client/service.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ def start_test_item(self,
258258
parameters=None,
259259
parent_item_id=None,
260260
has_stats=True,
261+
code_ref=None,
261262
**kwargs):
262263
"""
263264
Item_type can be.
@@ -287,7 +288,8 @@ def start_test_item(self,
287288
"launchUuid": self.launch_id,
288289
"type": item_type,
289290
"parameters": parameters,
290-
"hasStats": has_stats
291+
"hasStats": has_stats,
292+
"codeRef": code_ref
291293
}
292294
if parent_item_id:
293295
url = uri_join(self.base_url_v2, "item", parent_item_id)

requirements.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
requests>=2.23.0
2+
six
3+
pytest
4+
delayed-assert

setup.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
__version__ = '5.0.4'
66

7+
with open('requirements.txt') as f:
8+
requirements = f.read().splitlines()
9+
710
setup(
811
name='reportportal-client',
912
packages=find_packages(),
@@ -22,5 +25,5 @@
2225
'Programming Language :: Python :: 3.7',
2326
'Programming Language :: Python :: 3.8'
2427
],
25-
install_requires=['requests>=2.4.2', 'six']
28+
install_requires=requirements
2629
)

tests/test_service.py

Lines changed: 80 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"""This modules includes unit tests for the service.py module."""
22

33
from datetime import datetime
4-
from pkg_resources import DistributionNotFound
54

6-
from delayed_assert import assert_expectations, expect
75
import pytest
6+
from delayed_assert import assert_expectations, expect
7+
from pkg_resources import DistributionNotFound
88
from six.moves import mock
99

1010
from reportportal_client.service import (
@@ -24,40 +24,40 @@ class TestServiceFunctions:
2424

2525
def test_check_convert_to_string(self):
2626
"""Test for support and convert strings to utf-8."""
27-
expect(_convert_string("Hello world") == 'Hello world')
28-
expect(lambda: isinstance(_convert_string("Hello world"), str))
27+
expect(_convert_string('Hello world') == 'Hello world')
28+
expect(lambda: isinstance(_convert_string('Hello world'), str))
2929
assert_expectations()
3030

3131
@pytest.mark.parametrize('system', [True, False])
3232
def test_dict_to_payload_with_system_key(self, system):
3333
"""Test convert dict to list of dicts with key system."""
34-
initial_dict = {"aa": 1, "b": 2, "system": system}
34+
initial_dict = {'aa': 1, 'b': 2, 'system': system}
3535
expected_list = [{'key': 'aa', 'value': '1', 'system': system},
3636
{'key': 'b', 'value': '2', 'system': system}]
3737
assert _dict_to_payload(initial_dict) == expected_list
3838

3939
def test_get_id(self, response):
4040
"""Test for the get_id function."""
41-
assert _get_id(response(200, {"id": 123})) == 123
41+
assert _get_id(response(200, {'id': 123})) == 123
4242

4343
def test_get_msg(self, response):
4444
"""Test for the get_msg function."""
45-
fake_json = {"id": 123}
45+
fake_json = {'id': 123}
4646
assert _get_msg(response(200, fake_json)) == fake_json
4747

4848
def test_get_data(self, response):
4949
"""Test for the get_data function."""
50-
fake_json = {"id": 123}
50+
fake_json = {'id': 123}
5151
assert _get_data(response(200, fake_json)) == fake_json
5252

5353
def test_get_json(self, response):
5454
"""Test for the get_json function."""
55-
fake_json = {"id": 123}
55+
fake_json = {'id': 123}
5656
assert _get_json(response(200, fake_json)) == fake_json
5757

5858
def test_get_messages(self):
5959
"""Test for the get_messages function."""
60-
data = {"responses": [{"errorCode": 422, "message": "error"}]}
60+
data = {'responses': [{'errorCode': 422, 'message': 'error'}]}
6161
assert _get_messages(data) == ['422: error']
6262

6363

@@ -71,7 +71,7 @@ def test_start_launch(self, mock_get, rp_service):
7171
:param mock_get: Mocked _get_data() function
7272
:param rp_service: Pytest fixture
7373
"""
74-
mock_get.return_value = {"id": 111}
74+
mock_get.return_value = {'id': 111}
7575
launch_id = rp_service.start_launch('name', datetime.now().isoformat())
7676
assert launch_id == 111
7777

@@ -82,10 +82,10 @@ def test_finish_launch(self, mock_get, rp_service):
8282
:param mock_get: Mocked _get_msg() function
8383
:param rp_service: Pytest fixture
8484
"""
85-
mock_get.return_value = {"id": 111}
85+
mock_get.return_value = {'id': 111}
8686
_get_msg = rp_service.finish_launch(
8787
'name', datetime.now().isoformat())
88-
assert _get_msg == {"id": 111}
88+
assert _get_msg == {'id': 111}
8989

9090
@mock.patch('platform.system', mock.Mock(return_value='linux'))
9191
@mock.patch('platform.machine', mock.Mock(return_value='Windows-PC'))
@@ -131,3 +131,70 @@ def test_get_system_information_without_pkg(self):
131131
cond = (ReportPortalService.get_system_information('pytest')
132132
== expected_result)
133133
assert cond
134+
135+
@mock.patch('reportportal_client.service._get_data',
136+
mock.Mock(return_value={'id': 123}))
137+
def test_start_item(self, rp_service):
138+
"""Test for validate start_test_item.
139+
140+
:param: rp_service: fixture of ReportPortal
141+
"""
142+
rp_start = rp_service.start_test_item(name='name',
143+
start_time=1591032041348,
144+
item_type='STORY')
145+
expected_result = dict(json={'name': 'name',
146+
'description': None,
147+
'attributes': None,
148+
'startTime': 1591032041348,
149+
'launchUuid': 111,
150+
'type': 'STORY', 'parameters': None,
151+
'hasStats': True,
152+
'codeRef': None},
153+
url='http://endpoint/api/v2/project/item',
154+
verify=True)
155+
156+
rp_service.session.post.assert_called_with(**expected_result)
157+
assert rp_start == 123
158+
159+
start_item_optional = [
160+
('code_ref', '/path/to/test - test_item', 'codeRef',
161+
'/path/to/test - test_item'),
162+
('attributes', {'attr1': True}, 'attributes',
163+
[{'key': 'attr1', 'value': 'True', 'system': False}])
164+
]
165+
166+
@pytest.mark.parametrize(
167+
'field_name,field_value,expected_name,expected_value',
168+
start_item_optional)
169+
@mock.patch('reportportal_client.service._get_data',
170+
mock.Mock(return_value={'id': 123}))
171+
def test_start_item_code_optional_params(self, rp_service, field_name,
172+
field_value, expected_name,
173+
expected_value):
174+
"""Test for validate different fields in start_test_item.
175+
176+
:param: rp_service: fixture of ReportPortal
177+
:param: field_name: a name of a field bypassed to
178+
rp_service.start_test_item method
179+
:param: field_value: a value of a field bypassed to
180+
rp_service.start_test_item method
181+
:param: expected_name: a name of a field which should be in the result
182+
JSON request
183+
:param: expected_value: an exact value of a field which should be in
184+
the result JSON request
185+
"""
186+
rp_service.start_test_item(name='name', start_time=1591032041348,
187+
item_type='STORY',
188+
**{field_name: field_value})
189+
expected_result = dict(json={'name': 'name',
190+
'description': None,
191+
'attributes': None,
192+
'startTime': 1591032041348,
193+
'launchUuid': 111,
194+
'type': 'STORY', 'parameters': None,
195+
'hasStats': True,
196+
'codeRef': None},
197+
url='http://endpoint/api/v2/project/item',
198+
verify=True)
199+
expected_result['json'][expected_name] = expected_value
200+
rp_service.session.post.assert_called_with(**expected_result)

0 commit comments

Comments
 (0)