Skip to content

Commit fa091f7

Browse files
Add RP item objects
1 parent bfd4ab0 commit fa091f7

File tree

9 files changed

+472
-0
lines changed

9 files changed

+472
-0
lines changed

reportportal_client/items/__init__.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""This package provides common static objects and variables.
2+
3+
Copyright (c) 2018 http://reportportal.io .
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
"""

reportportal_client/items/helpers.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""
2+
This module contains common classes-helpers for the items.
3+
4+
Copyright (c) 2018 http://reportportal.io .
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
"""
15+
16+
from enum import IntEnum
17+
18+
19+
class ItemWeight(IntEnum):
20+
"""Enum with weights for different item types."""
21+
22+
ROOT_ITEM_WEIGHT = 1
23+
LOG_ITEM_WEIGHT = 10
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
"""
2+
This module contains functional for Base RP items management.
3+
4+
Copyright (c) 2018 http://reportportal.io .
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
"""
18+
19+
from reportportal_client.core.rp_requests import HttpRequest
20+
from reportportal_client.core.rp_responses import RPResponse
21+
from reportportal_client.static.defines import NOT_FOUND
22+
23+
24+
class BaseRPItem(object):
25+
"""This model stores attributes related to RP item."""
26+
27+
def __init__(self, rp_url, session, api_version, project_name,
28+
launch_uuid, generated_id):
29+
"""Initialize instance attributes.
30+
31+
:param rp_url: report portal url
32+
:param session: Session object
33+
:param api_version: RP API version
34+
:param project_name: RP project name
35+
:param launch_uuid: Parent launch UUID
36+
:param generated_id: Id generated to speed up client
37+
"""
38+
self.uuid = None
39+
self.weight = None
40+
self.generated_id = generated_id
41+
self.http_requests = []
42+
self.responses = []
43+
self.rp_url = rp_url
44+
self.session = session
45+
self.api_version = api_version
46+
self.project_name = project_name
47+
self.launch_uuid = launch_uuid
48+
49+
@property
50+
def http_request(self):
51+
"""Get last http request.
52+
53+
:return: request object
54+
"""
55+
return self.http_requests[-1] if self.http_requests else None
56+
57+
@property
58+
def response(self):
59+
"""Get last http response.
60+
61+
:return: Response data object
62+
"""
63+
return self.responses[-1] if self.responses else None
64+
65+
@response.setter
66+
def response(self, data):
67+
"""Set the response object for the test item.
68+
69+
:param data: Response data object
70+
"""
71+
response = RPResponse(data)
72+
self.responses.append(response)
73+
self.uuid = response.id if (response.id is
74+
not NOT_FOUND) else self.uuid
75+
76+
@property
77+
def unhandled_requests(self):
78+
"""Get list of requests that were not handled.
79+
80+
:return: list of HttpRequest objects
81+
"""
82+
return [request for request in self.http_requests
83+
if not request.response]
84+
85+
def add_request(self, endpoint, method, request_class, *args, **kwargs):
86+
"""Add new request object.
87+
88+
:param endpoint: request endpoint
89+
:param method: Session object method. Allowable values: get,
90+
post, put, delete
91+
:param request_class: request class object
92+
:param args: request object attributes
93+
:param kwargs: request object named attributes
94+
:return: None
95+
"""
96+
rp_request = request_class(*args, **kwargs)
97+
rp_request.http_request = HttpRequest(method, endpoint)
98+
rp_request.priority = self.weight
99+
self.http_requests.append(rp_request)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""This package provides common static objects and variables.
2+
3+
Copyright (c) 2018 http://reportportal.io .
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
"""
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
"""
2+
This module contains functional for RP log items management.
3+
4+
Copyright (c) 2018 http://reportportal.io .
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
"""
18+
19+
from reportportal_client.items.rp_base_item import BaseRPItem
20+
from reportportal_client.core.rp_requests import RPRequestLog
21+
from reportportal_client.static.defines import RP_LOG_LEVELS
22+
from reportportal_client.items.helpers import ItemWeight
23+
24+
25+
class RPLogItem(BaseRPItem):
26+
"""This model stores attributes for RP log items."""
27+
28+
def __init__(self, rp_url, session, api_version, project_name,
29+
launch_uuid, generated_id):
30+
"""Initialize instance attributes.
31+
32+
:param rp_url: report portal URL
33+
:param session: Session object
34+
:param api_version: RP API version
35+
:param project_name: RP project name
36+
:param launch_uuid: Parent launch UUID
37+
:param generated_id: Id generated to speed up client
38+
"""
39+
super(RPLogItem, self).__init__(rp_url, session, api_version,
40+
project_name, launch_uuid,
41+
generated_id)
42+
self.weight = ItemWeight.LOG_ITEM_WEIGHT
43+
44+
@property
45+
def response(self):
46+
"""Get the response object for RP log item."""
47+
return self._responses[0]
48+
49+
@response.setter
50+
def response(self, value):
51+
"""Set the response object for RP log item."""
52+
raise NotImplementedError
53+
54+
def create(self, time, file_obj=None, item_uuid=None,
55+
level=RP_LOG_LEVELS[40000], message=None):
56+
"""Add request for log item creation.
57+
58+
:param time: Log item time
59+
:param file_obj: Object of the RPFile
60+
:param item_uuid: Parent test item UUID
61+
:param level: Log level. Allowable values: error(40000),
62+
warn(30000), info(20000), debug(10000),
63+
trace(5000), fatal(50000), unknown(60000)
64+
:param message: Log message
65+
"""
66+
endpoint = "/api/{version}/{projectName}/log".format(
67+
version=self.api_version, projectName=self.project_name)
68+
self.add_request(endpoint, self.session.post, RPRequestLog,
69+
self.launch_uuid, time, file=file_obj,
70+
item_uuid=item_uuid, level=level, message=message)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""This package provides common static objects and variables.
2+
3+
Copyright (c) 2018 http://reportportal.io .
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
"""
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
"""
2+
This module contains functional for Base RP test items management.
3+
4+
Copyright (c) 2018 http://reportportal.io .
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
"""
18+
19+
from reportportal_client.items.rp_base_item import BaseRPItem
20+
from reportportal_client.core.rp_requests import ItemFinishRequest
21+
22+
23+
class RPBaseTestItem(BaseRPItem):
24+
"""This model stores common attributes for RP test items."""
25+
26+
def __init__(self, rp_url, session, api_version, project_name, item_name,
27+
item_type, launch_uuid, generated_id, has_stats, **kwargs):
28+
"""Initialize instance attributes.
29+
30+
:param rp_url: report portal url
31+
:param session: Session object
32+
:param api_version: RP API version
33+
:param project_name: RP project name
34+
:param item_name: RP item name
35+
:param item_type: Type of the test item. Allowable values: "suite",
36+
"story", "test", "scenario", "step",
37+
"before_class", "before_groups", "before_method",
38+
"before_suite", "before_test", "after_class",
39+
"after_groups", "after_method", "after_suite",
40+
"after_test"
41+
:param launch_uuid: Parent launch UUID
42+
:param generated_id: Id generated to speed up client
43+
:param has_stats: If item has stats
44+
:param kwargs: Dict of additional named parameters
45+
"""
46+
super(RPBaseTestItem, self).__init__(rp_url, session, api_version,
47+
project_name, launch_uuid,
48+
generated_id)
49+
self.item_name = item_name
50+
self.item_type = item_type
51+
self.description = kwargs.get("description")
52+
self.attributes = kwargs.get("attributes")
53+
self.uuid = kwargs.get("uuid")
54+
self.code_ref = kwargs.get("code_ref")
55+
self.parameters = kwargs.get("parameters")
56+
self.unique_id = kwargs.get("unique_id")
57+
self.retry = kwargs.get("retry", False)
58+
self.has_stats = has_stats
59+
self.child_items = []
60+
61+
def add_child_item(self, item):
62+
"""Add new child item to the list.
63+
64+
:param item: test item object
65+
:return: None
66+
"""
67+
self.child_items.append(item)
68+
69+
def finish(self, end_time, status=None, description=None, issue=None):
70+
"""Form finish request for RP test item.
71+
72+
:param end_time: Test item end time
73+
:param status: Test status. Allowable values: "passed",
74+
"failed", "stopped", "skipped", "interrupted",
75+
"cancelled"
76+
:param description: Test item description.
77+
:param issue: Issue of the current test item
78+
"""
79+
endpoint = "{url}/api/{version}/{projectName}/item/{itemUuid}". \
80+
format(url=self.rp_url, version=self.api_version,
81+
projectName=self.project_name, itemUuid=self.uuid)
82+
83+
self.add_request(endpoint, self.session.post, ItemFinishRequest,
84+
end_time, self.launch_uuid, status,
85+
attributes=self.attributes, description=description,
86+
issue=issue, retry=self.retry)

0 commit comments

Comments
 (0)