1
1
"""This modules includes unit tests for the service.py module."""
2
2
3
-
4
3
from datetime import datetime
5
- from six . moves import mock
4
+ from pkg_resources import DistributionNotFound
6
5
7
6
from delayed_assert import expect , assert_expectations
7
+ import pytest
8
+ from six .moves import mock
8
9
9
10
from reportportal_client .service import (
10
11
_convert_string ,
12
+ _dict_to_payload ,
11
13
_get_data ,
12
14
_get_id ,
13
15
_get_json ,
14
16
_get_messages ,
15
17
_get_msg ,
16
- _list_to_payload
18
+ ReportPortalService
17
19
)
18
20
19
21
@@ -26,12 +28,13 @@ def test_check_convert_to_string(self):
26
28
expect (lambda : isinstance (_convert_string ("Hello world" ), str ))
27
29
assert_expectations ()
28
30
29
- def test_list_to_payload (self ):
30
- """Test convert dict to list of dicts."""
31
- initial_dict = {'key' : "value" , 'key1' : 'value1' }
32
- expected_list = [{'key' : 'key' , 'value' : 'value' },
33
- {'key' : 'key1' , 'value' : 'value1' }]
34
- assert _list_to_payload (initial_dict ) == expected_list
31
+ @pytest .mark .parametrize ('system' , [True , False ])
32
+ def test_dict_to_payload_with_system_key (self , system ):
33
+ """Test convert dict to list of dicts with key system."""
34
+ initial_dict = {"aa" : 1 , "b" : 2 , "system" : system }
35
+ expected_list = [{'key' : 'aa' , 'value' : '1' , 'system' : system },
36
+ {'key' : 'b' , 'value' : '2' , 'system' : system }]
37
+ assert _dict_to_payload (initial_dict ) == expected_list
35
38
36
39
def test_get_id (self , response ):
37
40
"""Test for the get_id function."""
@@ -82,3 +85,37 @@ def test_finish_launch(self, mock_get, rp_service):
82
85
mock_get .return_value = {"id" : 111 }
83
86
_get_msg = rp_service .finish_launch ('name' , datetime .now ().isoformat ())
84
87
assert _get_msg == {"id" : 111 }
88
+
89
+ @mock .patch ('platform.system' , mock .Mock (return_value = 'linux' ))
90
+ @mock .patch ('platform.machine' , mock .Mock (return_value = 'Windows-PC' ))
91
+ @mock .patch ('platform.processor' , mock .Mock (return_value = 'amd' ))
92
+ @mock .patch ('pkg_resources.get_distribution' ,
93
+ mock .Mock (return_value = 'pytest 5.0' ))
94
+ def test_get_system_information (self ):
95
+ """Test for validate get_system_information."""
96
+
97
+ expected_result = {'agent' : 'pytest-pytest 5.0' ,
98
+ 'cpu' : 'amd' ,
99
+ 'machine' : 'Windows-PC' ,
100
+ 'os' : 'linux' }
101
+
102
+ cond = (ReportPortalService .get_system_information ('pytest' )
103
+ == expected_result )
104
+ assert cond
105
+
106
+ @mock .patch ('platform.system' , mock .Mock (return_value = 'linux' ))
107
+ @mock .patch ('platform.machine' , mock .Mock (return_value = 'Windows-PC' ))
108
+ @mock .patch ('platform.processor' , mock .Mock (return_value = 'amd' ))
109
+ @mock .patch ('pkg_resources.get_distribution' ,
110
+ mock .Mock (side_effect = DistributionNotFound ))
111
+ def test_get_system_information_without_pkg (self ):
112
+ """Test in negative form for validate get_system_information."""
113
+
114
+ expected_result = {'agent' : 'not found' ,
115
+ 'cpu' : 'amd' ,
116
+ 'machine' : 'Windows-PC' ,
117
+ 'os' : 'linux' }
118
+
119
+ cond = (ReportPortalService .get_system_information ('pytest' )
120
+ == expected_result )
121
+ assert cond
0 commit comments