Skip to content

Commit 599bb28

Browse files
author
Jeremy Adams
authored
Merge pull request #8 from ga4gh/release/0.2.0
Release/0.2.0 into main
2 parents 5dc83c8 + 678c853 commit 599bb28

File tree

6 files changed

+104
-1
lines changed

6 files changed

+104
-1
lines changed

.github/workflows/test.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ jobs:
2525
- name: Install dependencies
2626
run: pip install -r requirements.txt
2727

28+
- name: Run Testbed API
29+
run: docker run -d -p 4500:4500 ga4gh/ga4gh-testbed-api:0.1.0
30+
31+
- name: Service Health Check
32+
uses: jtalk/url-health-check-action@v2
33+
with:
34+
url: http://localhost:4500/reports
35+
follow-redirect: false
36+
max-attempts: 6
37+
retry-delay: 10s
38+
retry-all: true
39+
2840
- name: Run Tests
2941
run: python -m pytest --cov
3042

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,8 @@ python -m pytest --cov
5757

5858
## Changelog
5959

60+
### v0.2.0
61+
* Able to submit reports to Testbed API via standard `POST` request
62+
6063
### v0.1.2
6164
* Test level entity now has a `message` attribute for capturing test result summary in a single message

ga4gh/testbed/submit/__init__.py

Whitespace-only changes.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from re import sub
2+
import requests
3+
4+
5+
class ReportSubmitter():
6+
7+
def submit_report(series_id, series_token, report, url="http://localhost:4500/reports"):
8+
'''
9+
Submits a report to the GA4GH testbed api.
10+
11+
Required arguments:
12+
series_id - A series ID is needed by server to group the report
13+
series_token - A token is needed to verify authenticity
14+
report - GA4GH report in JSON format
15+
url - URL of the testbed server
16+
'''
17+
header = {"GA4GH-TestbedReportSeriesId": series_id, "GA4GH-TestbedReportSeriesToken": series_token}
18+
submit_request = requests.post(url, headers=header ,json=report)
19+
20+
results = {
21+
"status_code": submit_request.status_code,
22+
"error_message": None,
23+
"report_id": None
24+
}
25+
26+
if submit_request.status_code == 200:
27+
results["report_id"] = submit_request.json()["id"]
28+
else:
29+
if "message" in submit_request.json().keys():
30+
results["error_message"] = submit_request.json()["message"]
31+
32+
return results

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import setuptools
22

33
NAME = "ga4gh-testbed-lib"
4-
VERSION = "0.1.2"
4+
VERSION = "0.2.0"
55
AUTHOR = "Jeremy Adams"
66
EMAIL = "jeremy.adams@ga4gh.org"
77

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import pytest
2+
from ga4gh.testbed.submit.report_submitter import ReportSubmitter
3+
4+
sample_report = {"schema_name":"ga4gh-testbed-report","schema_version":"0.1.0","testbed_name":"refget-compliance-suite","testbed_version":"","testbed_description":"","platform_name":"","platform_description":"","input_parameters":{},"start_time":"2022-03-22T17:45:37Z","end_time":"2022-03-22T17:46:32Z","status":"PASS","summary":{"unknown":0,"passed":49,"warned":0,"failed":0,"skipped":20},"phases":[]}
5+
6+
submit_report_inputs = "series_id,series_token,report,url,status_code"
7+
submit_report_cases = [
8+
(
9+
"1edb5213-52a2-434f-a7b8-b101fea8fb30",
10+
"K5pLbwScVu8rEoLLj8pRy5Wv7EXTVahn",
11+
sample_report,
12+
"http://localhost:4500/reports",
13+
200
14+
),
15+
(
16+
"483382e9-f92b-466d-9427-154d56a75fcf",
17+
"l0HiRbbpjVDKc6k3tQ2skzROB1oAP2IV",
18+
sample_report,
19+
"http://localhost:4500/reports",
20+
200
21+
),
22+
(
23+
"1edb5213-52a2-434f-a7b8-b101fea8fb30",
24+
"K5pLbwScVu8rEoLLj8pRy5Wv7EXTVahn",
25+
"",
26+
"http://localhost:4500/reports",
27+
400
28+
),
29+
(
30+
"1edb5213-52a2-434f-a7b8-b101fea8fb30",
31+
"K5pLbwScVu8rEoLLj8pRy5Wv7EXTVahn",
32+
{},
33+
"http://localhost:4500/reports",
34+
500
35+
),
36+
(
37+
"",
38+
"K5pLbwScVu8rEoLLj8pRy5Wv7EXTVahn",
39+
sample_report,
40+
"http://localhost:4500/reports",
41+
404
42+
),
43+
(
44+
"1edb5213-52a2-434f-a7b8-b101fea8fb30",
45+
"",
46+
sample_report,
47+
"http://localhost:4500/reports",
48+
401
49+
),
50+
]
51+
52+
@pytest.mark.parametrize(submit_report_inputs, submit_report_cases)
53+
def test_case_submit_report(series_id,series_token,report,url, status_code):
54+
submitter = ReportSubmitter
55+
assert submitter.submit_report(series_id, series_token, report, url)["status_code"] == status_code
56+

0 commit comments

Comments
 (0)