Skip to content

Commit 4d5c296

Browse files
authored
Add README (s2technologies#8)
1 parent d8be358 commit 4d5c296

File tree

2 files changed

+171
-17
lines changed

2 files changed

+171
-17
lines changed

README.md

+142-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,143 @@
11
# testspace-python
2-
Library to interact with Testspace api.
2+
3+
Python module to use Testspace API and client. Provides a python object that can manage the following Testspace items: url, token, project name and space name. It also provides functions to push results and handle most common API requests.
4+
5+
## Usage
6+
To use the module the items listed below are needed.
7+
* Organization url (organization.testspace.com)
8+
* [Testspace token](https://help.testspace.com/docs/dashboard/admin-user#account)
9+
* Project name (optional)
10+
* Space name (optional)
11+
12+
Project and Space names do not have to be set on instantiation of the Testspace object and can be passed as parameters to any function call that requires them. They can also be passed into any of the functions to override, but not update the objects stored values, otherwise the stored values for project and space will be used.
13+
```
14+
from testspace import testspace as ts
15+
token = "access token"
16+
url = "organization.testspace.com"
17+
project = "project name"
18+
space= "space name"
19+
testspace = ts.Testspace(token=token, url=url, project=project, space=space)
20+
```
21+
22+
## Testspace Client
23+
Provides a python wrapper to use the [Testspace client](https://help.testspace.com/docs/reference/testspace-client) for pushing content to [Testspace](https://www.testspace.com/). Optional parameters to this function are available to provide the name of file to push, name of the result set and how.
24+
25+
### Example
26+
```
27+
testspace = ts.Testspace(token=token, url=url, project=project, space=space)
28+
testspace.push(file="testresults.xml", result_name="build.1", how="full")
29+
```
30+
The following Testspace client [options](https://help.testspace.com/docs/reference/testspace-client#push) are also supported as parameters to the push function.
31+
32+
|Client Option | Function Parameter |
33+
|---|---|
34+
|build-url|build_url|
35+
|repo|repo|
36+
|link|link|
37+
|message|message|
38+
39+
40+
## Testspace API
41+
Provides a python wrapper for the [Testspace API](https://help.testspace.com/docs/reference/web-api). The available functions mirror the structure of the documented API endpoints, with GET, POST, PATCH, and DELETE options available as appropriate for the endpoint. Where names in addition to id's are supported in the API, they can be used interchangably here as well. All functions return any JSON response as a result of the request, see Testspace API [help](https://help.testspace.com/docs/reference/web-api) for details of each response. For any Testspace API that returns a list, the page size default limit of 30 is used, for any of these function the `limit` parameter can be added with an integer value for the desired maximum number of returned items. All requests are checked with raise_for_status with the expectation that any exceptions will be appropriately handled by user of the module.
42+
43+
### Projects
44+
##### Get List of Projects
45+
```
46+
testspace.get_projects(limit=30)
47+
```
48+
##### Get a Project
49+
```
50+
testspace.get_project(project=None)
51+
```
52+
##### Create a Project
53+
```
54+
payload = {"name": "new project name"}
55+
testspace.post_projects(payload=payload)
56+
```
57+
##### Update a Project
58+
```
59+
payload = {"description": "Awesome project"}
60+
testspace.patch_project(payload, project=None):
61+
```
62+
##### Delete a Project
63+
```
64+
testspace.delete_project(project=None)
65+
```
66+
### Spaces
67+
##### Get List of Spaces for a Project
68+
```
69+
testspace.get_spaces(project=None, limit=30)
70+
```
71+
##### Get specific space
72+
```
73+
testspace.get_space(project=None, space=None)
74+
```
75+
##### Create a Space
76+
```
77+
payload = {"name": "new space name"}
78+
testspace.post_spaces(payload=payload, project=None)
79+
```
80+
##### Update a Space
81+
```
82+
payload = {"description": "Awesome project"}
83+
testspace.patch_project(payload, project=None, space=None):
84+
```
85+
##### Delete a Space
86+
```
87+
testspace.delete_space(project=None, space=None)
88+
```
89+
### Results
90+
##### Get list of Results
91+
```
92+
testspace.get_results(project=None, space=None, limit=30)
93+
```
94+
#### Get Result
95+
```
96+
testspace.get_result(result, project=None, space=None)
97+
```
98+
#### Failures
99+
##### Get list of Result Failures
100+
```
101+
testspace.get_result_failures(result, project=None, space=None, limit=30)
102+
```
103+
#### Contents
104+
##### Get Result Contents
105+
```
106+
# contents_path is used to obtain contents that are not at the root of the result
107+
testspace.get_result_contents(result, contents_path=None, project=None, space=None, limit=30)
108+
```
109+
#### Metric Dataset
110+
##### Get Metric Dataset
111+
```
112+
# Id must be as name resolution is not supported for metrics.
113+
testspace.get_metric_datasets(metric, project=None, space=None, limit=30)
114+
```
115+
### Metrics
116+
##### Get List of Metrics for a Space
117+
```
118+
testspace.get_metrics(project=None, space=None, limit=30)
119+
```
120+
##### Get Metric for a Space
121+
```
122+
# metric must be id as name resolution is not supported for this.
123+
testspace.get_metric(metric, project=None, space=None)
124+
```
125+
##### Create a Space Metric
126+
```
127+
payload = {
128+
"name": "MyMetric",
129+
"data_source": "/path/to/suite[dataset_label]"
130+
}
131+
testspace.post_metrics(payload, project=None, space=None)
132+
```
133+
##### Update a Space Metric
134+
```
135+
payload = {
136+
"data_source": "/path/to/suite[dataset_label]"
137+
}
138+
testspace.patch_metrics(payload, metric, project=None, space=None)
139+
```
140+
##### Delete a Space Metric
141+
```
142+
testspace.delete_metric(metric, project=None, space=None)
143+
```

testspace/testspace.py

+29-16
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,6 @@ def get_metrics(self, project=None, space=None, limit=30):
117117
return self.get_request_json(self.get_metrics_path(project, space), limit=limit)
118118

119119
def get_metric(self, metric, project=None, space=None):
120-
if type(metric) is not int:
121-
raise ValueError
122120
return self.get_request_json(self.get_metric_path(metric, project, space))
123121

124122
def get_metric_datasets(self, metric, project=None, space=None, limit=30):
@@ -130,14 +128,20 @@ def get_metric_datasets(self, metric, project=None, space=None, limit=30):
130128
def post_projects(self, payload):
131129
return self.post_request_json(path=self.get_projects_path(), payload=payload)
132130

133-
def post_spaces(self, payload):
134-
return self.post_request_json(path=self.get_spaces_path(), payload=payload)
131+
def post_spaces(self, payload, project=None):
132+
return self.post_request_json(
133+
path=self.get_spaces_path(project=project), payload=payload
134+
)
135135

136-
def post_results(self, payload):
137-
return self.post_request_json(path=self.get_results_path(), payload=payload)
136+
def post_results(self, payload, project=None, space=None):
137+
return self.post_request_json(
138+
path=self.get_results_path(project=project, space=space), payload=payload
139+
)
138140

139-
def post_metrics(self, payload):
140-
return self.post_request_json(path=self.get_metrics_path(), payload=payload)
141+
def post_metrics(self, payload, project=None, space=None):
142+
return self.post_request_json(
143+
path=self.get_metrics_path(project=project, space=space), payload=payload
144+
)
141145

142146
def patch_project(self, payload, project=None):
143147
return self.patch_request(
@@ -149,8 +153,11 @@ def patch_space(self, payload, project=None, space=None):
149153
path=self.get_space_path(project=project, space=space), payload=payload
150154
)
151155

152-
def patch_metric(self, payload, metric):
153-
return self.patch_request(path=self.get_metric_path(metric), payload=payload)
156+
def patch_metric(self, payload, metric, project=None, space=None):
157+
return self.patch_request(
158+
path=self.get_metric_path(metric, project=project, space=space),
159+
payload=payload,
160+
)
154161

155162
def patch_result(self, payload, result):
156163
return self.patch_request(path=self.get_result_path(result), payload=payload)
@@ -163,11 +170,15 @@ def delete_space(self, project=None, space=None):
163170
path=self.get_space_path(project=project, space=space)
164171
)
165172

166-
def delete_result(self, result):
167-
return self.delete_request(path=self.get_result_path(result))
173+
def delete_result(self, result, project=None, space=None):
174+
return self.delete_request(
175+
path=self.get_result_path(result, project=project, space=space)
176+
)
168177

169-
def delete_metric(self, metric):
170-
return self.delete_request(path=self.get_metric_path(metric))
178+
def delete_metric(self, metric, project=None, space=None):
179+
return self.delete_request(
180+
path=self.get_metric_path(metric, project=project, space=space)
181+
)
171182

172183
def get_request(self, path=None):
173184
response = self._api_request("GET", path=path)
@@ -232,7 +243,6 @@ def get_space_path(self, project=None, space=None):
232243
space = self.space
233244
else:
234245
raise ValueError
235-
236246
return "/".join([self.get_spaces_path(project), str(space)])
237247

238248
def get_results_path(self, project=None, space=None):
@@ -245,7 +255,10 @@ def get_metrics_path(self, project=None, space=None):
245255
return "/".join([self.get_space_path(project, space), "metrics"])
246256

247257
def get_metric_path(self, metric, project=None, space=None):
248-
return "/".join([self.get_metrics_path(project, space), str(metric)])
258+
metric_str = str(metric)
259+
if str.isdigit(metric_str) is not True:
260+
raise ValueError
261+
return "/".join([self.get_metrics_path(project, space), metric_str])
249262

250263
def _api_request(self, method, path, payload=None):
251264
if path is None:

0 commit comments

Comments
 (0)