19
19
import requests
20
20
from requests .adapters import HTTPAdapter
21
21
22
+ from reportportal_client .core .log_manager import LogManager
23
+ from reportportal_client .core .test_manager import TestManager
22
24
from reportportal_client .core .rp_requests import (
23
25
HttpRequest ,
24
26
LaunchStartRequest ,
25
27
LaunchFinishRequest
26
28
)
27
- from reportportal_client .core .test_manager import TestManager
28
29
from reportportal_client .helpers import uri_join
29
30
30
31
logger = logging .getLogger (__name__ )
@@ -44,51 +45,120 @@ def __init__(self,
44
45
retries = None ,
45
46
max_pool_size = 50 ,
46
47
launch_id = None ,
47
- ):
48
+ ** _ ):
48
49
"""Initialize required attributes.
49
50
50
- :param endpoint: Endpoint of report portal service
51
- :param project: Project name to use for launch names
52
- :param token: authorization token.
53
- :param log_batch_size: option to set the maximum number of
54
- logs
55
- that can be processed in one batch
56
- :param is_skipped_an_issue: option to mark skipped tests as not
57
- 'To Investigate' items on Server side.
58
- :param verify_ssl: option to not verify ssl certificates
59
- :param max_pool_size: option to set the maximum number of
60
- connections to save in the pool.
51
+ :param endpoint: Endpoint of the report portal service
52
+ :param project: Project name to report to
53
+ :param token: Authorization token
54
+ :param log_batch_size: Option to set the maximum number of
55
+ logs that can be processed in one batch
56
+ :param is_skipped_an_issue: Option to mark skipped tests as not
57
+ 'To Investigate' items on the server side
58
+ :param verify_ssl: Option to skip ssl verification
59
+ :param max_pool_size: Option to set the maximum number of
60
+ connections to save the pool.
61
61
"""
62
62
self ._batch_logs = []
63
+ self .api_v1 , self .api_v2 = 'v1' , 'v2'
63
64
self .endpoint = endpoint
64
- self .log_batch_size = log_batch_size
65
65
self .project = project
66
- self .token = token
66
+ self .base_url_v1 = uri_join (
67
+ self .endpoint , 'api/{}' .format (self .api_v1 ), self .project )
68
+ self .base_url_v2 = uri_join (
69
+ self .endpoint , 'api/{}' .format (self .api_v2 ), self .project )
70
+ self .is_skipped_an_issue = is_skipped_an_issue
67
71
self .launch_id = launch_id
72
+ self .log_batch_size = log_batch_size
73
+ self .token = token
68
74
self .verify_ssl = verify_ssl
69
- self .is_skipped_an_issue = is_skipped_an_issue
70
-
71
- self .api_v1 = 'v1'
72
- self .api_v2 = 'v2'
73
- self .base_url_v1 = uri_join (self .endpoint ,
74
- "api/{}" .format (self .api_v1 ),
75
- self .project )
76
- self .base_url_v2 = uri_join (self .endpoint ,
77
- "api/{}" .format (self .api_v2 ),
78
- self .project )
79
-
80
75
self .session = requests .Session ()
81
76
if retries :
82
77
self .session .mount ('https://' , HTTPAdapter (
83
78
max_retries = retries , pool_maxsize = max_pool_size ))
84
79
self .session .mount ('http://' , HTTPAdapter (
85
80
max_retries = retries , pool_maxsize = max_pool_size ))
86
- self .session .headers ["Authorization" ] = "bearer {0}" .format (self .token )
81
+ self .session .headers ['Authorization' ] = 'bearer {0}' .format (self .token )
82
+
83
+ self ._log_manager = LogManager (
84
+ self .endpoint , self .session , self .api_v2 , self .launch_id ,
85
+ self .project , log_batch_size = log_batch_size )
86
+ self ._test_manager = TestManager (
87
+ self .session , self .endpoint , project , self .launch_id )
88
+
89
+ def finish_launch (self ,
90
+ end_time ,
91
+ status = None ,
92
+ attributes = None ,
93
+ ** kwargs ):
94
+ """Finish launch.
95
+
96
+ :param end_time: Launch end time
97
+ :param status: Launch status. Can be one of the followings:
98
+ PASSED, FAILED, STOPPED, SKIPPED, RESETED,
99
+ CANCELLED
100
+ :param attributes: Launch attributes
101
+ """
102
+ url = uri_join (self .base_url_v2 , 'launch' , self .launch_id , 'finish' )
103
+ request_payload = LaunchFinishRequest (
104
+ end_time = end_time ,
105
+ status = status ,
106
+ attributes = attributes ,
107
+ ** kwargs
108
+ ).payload
109
+ response = HttpRequest (self .session .put , url = url , json = request_payload ,
110
+ verify_ssl = self .verify_ssl ).make ()
111
+ logger .debug ('finish_launch - ID: %s' , self .launch_id )
112
+ return response .message
113
+
114
+ def finish_test_item (self ,
115
+ item_id ,
116
+ end_time ,
117
+ status ,
118
+ issue = None ,
119
+ attributes = None ,
120
+ ** kwargs ):
121
+ """Finish suite/case/step/nested step item.
122
+
123
+ :param item_id: id of the test item
124
+ :param end_time: time in UTC format
125
+ :param status: status of the test
126
+ :param issue: description of an issue
127
+ :param attributes: list of attributes
128
+ :param kwargs: other parameters
129
+ :return: json message
130
+ """
131
+ self ._test_manager .finish_test_item (self .api_v2 ,
132
+ item_id ,
133
+ end_time ,
134
+ status ,
135
+ issue = issue ,
136
+ attributes = attributes ,
137
+ ** kwargs )
87
138
88
- self ._test_manager = TestManager (self .session ,
89
- self .endpoint ,
90
- project ,
91
- self .launch_id )
139
+ def get_project_settings (self ):
140
+ """Get settings from project.
141
+
142
+ :return: json body
143
+ """
144
+ url = uri_join (self .base_url_v1 , 'settings' )
145
+ r = self .session .get (url = url , json = {}, verify = self .verify_ssl )
146
+ return r .json ()
147
+
148
+ def log (self , time , message , level = None , attachment = None , item_id = None ):
149
+ """Send log message to the Report Portal.
150
+
151
+ :param time: Time in UTC
152
+ :param message: Log message
153
+ :param level: Message's log level
154
+ :param attachment: Message attachments
155
+ :param item_id: ID of the RP item the message belongs to
156
+ """
157
+ self ._log_manager .log (time , message , level , attachment , item_id )
158
+
159
+ def start (self ):
160
+ """Start the client."""
161
+ self ._log_manager .start ()
92
162
93
163
def start_launch (self ,
94
164
name ,
@@ -102,16 +172,16 @@ def start_launch(self,
102
172
):
103
173
"""Start a new launch with the given parameters.
104
174
105
- :param name: Name of launch
175
+ :param name: Launch name
106
176
:param start_time: Launch start time
107
177
:param description: Launch description
108
178
:param attributes: Launch attributes
109
179
:param mode: Launch mode
110
- :param rerun: Launch rerun
111
- :param rerun_of: Items to rerun in launch
180
+ :param rerun: Enables launch rerun mode
181
+ :param rerun_of: Rerun mode. Specifies launch to be re-runned.
182
+ Should be used with the 'rerun' option.
112
183
"""
113
- url = uri_join (self .base_url_v2 , "launch" )
114
-
184
+ url = uri_join (self .base_url_v2 , 'launch' )
115
185
request_payload = LaunchStartRequest (
116
186
name = name ,
117
187
start_time = start_time ,
@@ -122,55 +192,25 @@ def start_launch(self,
122
192
rerun_of = rerun_of ,
123
193
** kwargs
124
194
).payload
125
-
126
195
response = HttpRequest (self .session .post ,
127
196
url = url ,
128
197
json = request_payload ,
129
- verify = self .verify_ssl ).make ()
198
+ verify_ssl = self .verify_ssl ).make ()
130
199
self ._test_manager .launch_id = self .launch_id = response .id
131
- logger .debug (" start_launch - ID: %s" , self .launch_id )
200
+ logger .debug (' start_launch - ID: %s' , self .launch_id )
132
201
return self .launch_id
133
202
134
- def finish_launch (self ,
135
- end_time ,
136
- status = None ,
137
- attributes = None ,
138
- ** kwargs ):
139
- """Finish launch.
140
-
141
- :param end_time: Launch end time
142
- :param status: Launch status. Can be one of the followings:
143
- PASSED, FAILED, STOPPED, SKIPPED, RESETED,
144
- CANCELLED
145
- :param attributes: Launch attributes
146
- """
147
- url = uri_join (self .base_url_v2 , "launch" , self .launch_id , "finish" )
148
-
149
- request_payload = LaunchFinishRequest (
150
- end_time = end_time ,
151
- status = status ,
152
- attributes = attributes ,
153
- ** kwargs
154
- ).payload
155
-
156
- response = HttpRequest (self .session .put , url = url , json = request_payload ,
157
- verify = self .verify_ssl ).make ()
158
-
159
- logger .debug ("finish_launch - ID: %s" , self .launch_id )
160
- return response .message
161
-
162
- def start_item (self ,
163
- name ,
164
- start_time ,
165
- item_type ,
166
- description = None ,
167
- attributes = None ,
168
- parameters = None ,
169
- parent_item_id = None ,
170
- has_stats = True ,
171
- code_ref = None ,
172
- ** kwargs
173
- ):
203
+ def start_test_item (self ,
204
+ name ,
205
+ start_time ,
206
+ item_type ,
207
+ description = None ,
208
+ attributes = None ,
209
+ parameters = None ,
210
+ parent_item_id = None ,
211
+ has_stats = True ,
212
+ code_ref = None ,
213
+ ** kwargs ):
174
214
"""Start case/step/nested step item.
175
215
176
216
:param name: Name of test item
@@ -188,42 +228,13 @@ def start_item(self,
188
228
start_time ,
189
229
item_type ,
190
230
description = description ,
191
- attributes = attributes [ 0 ] ,
231
+ attributes = attributes ,
192
232
parameters = parameters ,
193
233
parent_uuid = parent_item_id ,
194
234
has_stats = has_stats ,
195
235
code_ref = code_ref ,
196
236
** kwargs )
197
237
198
- def finish_item (self ,
199
- item_id ,
200
- end_time ,
201
- status ,
202
- issue = None ,
203
- attributes = None ,
204
- ** kwargs
205
- ):
206
- """Finish suite/case/step/nested step item.
207
-
208
- :param item_id: id of the test item
209
- :param end_time: time in UTC format
210
- :param status: status of the test
211
- :param issue: description of an issue
212
- :param attributes: list of attributes
213
- :param kwargs: other parameters
214
- :return: json message
215
- """
216
- self ._test_manager .finish_test_item (self .api_v2 ,
217
- item_id ,
218
- end_time ,
219
- status ,
220
- issue = issue ,
221
- attributes = attributes [0 ],
222
- ** kwargs )
223
-
224
- def save_log (self , log_time , ** kwargs ):
225
- """Save logs for test items.
226
-
227
- :param log_time: Log time
228
- """
229
- pass
238
+ def terminate (self , * args , ** kwargs ):
239
+ """Call this to terminate the client."""
240
+ self ._log_manager .stop ()
0 commit comments