Skip to content

Commit 35c37fe

Browse files
authored
Merge pull request #6 from nassauwinter/cloud_automation_enpoints
Implement Cloud Automation endpoints
2 parents 264746a + c3b8494 commit 35c37fe

File tree

5 files changed

+100
-11
lines changed

5 files changed

+100
-11
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ test_case = zapi.test_cases.get_test_case("<test_case_id>")
5858
creation_result = zapi.test_cases.create_test_case("<project_key>", "test_case_name")
5959
```
6060

61+
### Troubleshooting
62+
63+
For troubleshooting see [TROUBLESHOOTING.md](TROUBLESHOOTING.md)
64+
6165

6266
### License
6367

TROUBLESHOOTING.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## Reporting to Zephyr
2+
3+
- The Cucumber format is different from Behave reporter format.
4+
In case you want to report test executions from output Behave file,
5+
please use some custom formatter for Behave output, i.e. https://pypi.org/project/behave-cucumber-formatter/.

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = zephyr-python-api
3-
version = 0.0.2
3+
version = 0.0.3
44
author = Petr Sharapenko
55
author_email = nassauwinter@gmail.com
66
description = Zephyr (TM4J) Python REST API wrapper

zephyr/scale/cloud/endpoints/automations.py

Lines changed: 85 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from json import dumps
2+
13
from ...zephyr_session import ZephyrSession
24

35

@@ -7,25 +9,99 @@ class AutomationEndpoints:
79
def __init__(self, session: ZephyrSession):
810
self.session = session
911

10-
def post_custom_format(self):
12+
def _post_reports(self,
13+
path,
14+
project_key,
15+
file_path,
16+
auto_create=False,
17+
test_cycle=None,
18+
**kwargs):
19+
"""
20+
Post various reports logic.
21+
22+
:param path: str with resource path
23+
:param project_key: str with project key
24+
:param file_path: str with path to .zip archive with report files
25+
:param auto_create: indicate if test cases should be created if non existent
26+
:param test_cycle: dict with test cycle description data
27+
"""
28+
params = {'projectKey': project_key}
29+
to_files = None
30+
31+
if auto_create:
32+
params.update({'autoCreateTestCases': True})
33+
34+
if test_cycle:
35+
to_files = {'testCycle': (None, dumps(test_cycle), 'application/json')}
36+
37+
return self.session.post_file(path,
38+
file_path,
39+
to_files=to_files,
40+
params=params,
41+
**kwargs)
42+
43+
def post_custom_format(self,
44+
project_key,
45+
file_path,
46+
auto_create=False,
47+
test_cycle=None,
48+
**kwargs):
1149
"""
1250
Create results using Zephyr Scale's custom results format.
51+
52+
:param project_key: str with project key
53+
:param file_path: str with path to .zip archive with report files
54+
:param auto_create: indicate if test cases should be created if non existent
55+
:param test_cycle: dict with test cycle description data
1356
"""
14-
raise NotImplementedError
57+
return self._post_reports('automations/executions/custom',
58+
project_key=project_key,
59+
file_path=file_path,
60+
auto_create=auto_create,
61+
test_cycle=test_cycle,
62+
**kwargs)
1563

16-
def post_cucumber_format(self):
64+
def post_cucumber_format(self,
65+
project_key,
66+
file_path,
67+
auto_create=False,
68+
test_cycle=None,
69+
**kwargs):
1770
"""
1871
Create results using the Cucumber results format.
72+
73+
:param project_key: str with project key
74+
:param file_path: str with path to .zip archive with report files
75+
:param auto_create: indicate if test cases should be created if non existent
76+
:param test_cycle: dict with test cycle description data
1977
"""
20-
raise NotImplementedError
78+
return self._post_reports('automations/executions/cucumber',
79+
project_key=project_key,
80+
file_path=file_path,
81+
auto_create=auto_create,
82+
test_cycle=test_cycle,
83+
**kwargs)
2184

22-
def post_junit_xml_format(self):
85+
def post_junit_xml_format(self,
86+
project_key,
87+
file_path,
88+
auto_create=False,
89+
test_cycle=None,
90+
**kwargs):
2391
"""
24-
Create results using the JUnit XML results format. Optionally,
25-
you can send a 'testCycle' part in your form data to customize
26-
the created test cycle.
92+
Create results using the JUnit XML results format.
93+
94+
:param project_key: str with project key
95+
:param file_path: str with path to .zip archive with report files
96+
:param auto_create: indicate if test cases should be created if non existent
97+
:param test_cycle: dict with test cycle description data
2798
"""
28-
raise NotImplementedError
99+
return self._post_reports('automations/executions/junit',
100+
project_key=project_key,
101+
file_path=file_path,
102+
auto_create=auto_create,
103+
test_cycle=test_cycle,
104+
**kwargs)
29105

30106
def get_testcases_zip(self, project_key):
31107
"""

zephyr/scale/zephyr_session.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,15 @@ def get_paginated(self, endpoint, params=None):
101101
params.update(parse_qs(params_str))
102102
return
103103

104-
def post_file(self, endpoint: str, file_path: str, **kwargs):
104+
def post_file(self, endpoint: str, file_path: str, to_files=None, **kwargs):
105105
"""
106106
Post wrapper to send a file. Handles single file opening,
107107
sending its content and closing
108108
"""
109109
with open(file_path, "rb") as file:
110110
files = {"file": file}
111+
112+
if to_files:
113+
files.update(to_files)
114+
111115
return self._request("post", endpoint, files=files, **kwargs)

0 commit comments

Comments
 (0)