Skip to content

Commit

Permalink
Merge pull request #8 from ga4gh/release/0.2.0
Browse files Browse the repository at this point in the history
Release/0.2.0 into main
  • Loading branch information
Jeremy Adams authored Apr 8, 2022
2 parents 5dc83c8 + 678c853 commit 599bb28
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 1 deletion.
12 changes: 12 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ jobs:
- name: Install dependencies
run: pip install -r requirements.txt

- name: Run Testbed API
run: docker run -d -p 4500:4500 ga4gh/ga4gh-testbed-api:0.1.0

- name: Service Health Check
uses: jtalk/url-health-check-action@v2
with:
url: http://localhost:4500/reports
follow-redirect: false
max-attempts: 6
retry-delay: 10s
retry-all: true

- name: Run Tests
run: python -m pytest --cov

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,8 @@ python -m pytest --cov

## Changelog

### v0.2.0
* Able to submit reports to Testbed API via standard `POST` request

### v0.1.2
* Test level entity now has a `message` attribute for capturing test result summary in a single message
Empty file.
32 changes: 32 additions & 0 deletions ga4gh/testbed/submit/report_submitter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from re import sub
import requests


class ReportSubmitter():

def submit_report(series_id, series_token, report, url="http://localhost:4500/reports"):
'''
Submits a report to the GA4GH testbed api.
Required arguments:
series_id - A series ID is needed by server to group the report
series_token - A token is needed to verify authenticity
report - GA4GH report in JSON format
url - URL of the testbed server
'''
header = {"GA4GH-TestbedReportSeriesId": series_id, "GA4GH-TestbedReportSeriesToken": series_token}
submit_request = requests.post(url, headers=header ,json=report)

results = {
"status_code": submit_request.status_code,
"error_message": None,
"report_id": None
}

if submit_request.status_code == 200:
results["report_id"] = submit_request.json()["id"]
else:
if "message" in submit_request.json().keys():
results["error_message"] = submit_request.json()["message"]

return results
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import setuptools

NAME = "ga4gh-testbed-lib"
VERSION = "0.1.2"
VERSION = "0.2.0"
AUTHOR = "Jeremy Adams"
EMAIL = "[email protected]"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import pytest
from ga4gh.testbed.submit.report_submitter import ReportSubmitter

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":[]}

submit_report_inputs = "series_id,series_token,report,url,status_code"
submit_report_cases = [
(
"1edb5213-52a2-434f-a7b8-b101fea8fb30",
"K5pLbwScVu8rEoLLj8pRy5Wv7EXTVahn",
sample_report,
"http://localhost:4500/reports",
200
),
(
"483382e9-f92b-466d-9427-154d56a75fcf",
"l0HiRbbpjVDKc6k3tQ2skzROB1oAP2IV",
sample_report,
"http://localhost:4500/reports",
200
),
(
"1edb5213-52a2-434f-a7b8-b101fea8fb30",
"K5pLbwScVu8rEoLLj8pRy5Wv7EXTVahn",
"",
"http://localhost:4500/reports",
400
),
(
"1edb5213-52a2-434f-a7b8-b101fea8fb30",
"K5pLbwScVu8rEoLLj8pRy5Wv7EXTVahn",
{},
"http://localhost:4500/reports",
500
),
(
"",
"K5pLbwScVu8rEoLLj8pRy5Wv7EXTVahn",
sample_report,
"http://localhost:4500/reports",
404
),
(
"1edb5213-52a2-434f-a7b8-b101fea8fb30",
"",
sample_report,
"http://localhost:4500/reports",
401
),
]

@pytest.mark.parametrize(submit_report_inputs, submit_report_cases)
def test_case_submit_report(series_id,series_token,report,url, status_code):
submitter = ReportSubmitter
assert submitter.submit_report(series_id, series_token, report, url)["status_code"] == status_code

0 comments on commit 599bb28

Please sign in to comment.