From 1618fb570f7b0560d0c79bbbf55d815bbef24dd4 Mon Sep 17 00:00:00 2001 From: Chen Chen Date: Mon, 4 Apr 2022 13:25:54 -0400 Subject: [PATCH 1/7] creating the submit class for submission to testbed api --- ga4gh/testbed/submit/submit_to_api.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 ga4gh/testbed/submit/submit_to_api.py diff --git a/ga4gh/testbed/submit/submit_to_api.py b/ga4gh/testbed/submit/submit_to_api.py new file mode 100644 index 0000000..7c24ebf --- /dev/null +++ b/ga4gh/testbed/submit/submit_to_api.py @@ -0,0 +1,15 @@ +import requests + + +class Submit(): + + def __init__(self, url, series_id, series_token, report) : + self.url = url + self.series_id = series_id + self.series_token = series_token + self.report = report + + def submit_report(self): + header = {"GA4GH-TestbedReportSeriesId": self.series_id, "GA4GH-TestbedReportSeriesToken": self.series_token} + submit_repuest = requests.post(self.url, headers=header ,json=self.report) + return submit_repuest.status_code From 4d011001b72891451ac01aeed91bfacf70e2a912 Mon Sep 17 00:00:00 2001 From: Chen Chen Date: Mon, 4 Apr 2022 13:27:36 -0400 Subject: [PATCH 2/7] fix spelling error --- ga4gh/testbed/submit/submit_to_api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ga4gh/testbed/submit/submit_to_api.py b/ga4gh/testbed/submit/submit_to_api.py index 7c24ebf..301adfe 100644 --- a/ga4gh/testbed/submit/submit_to_api.py +++ b/ga4gh/testbed/submit/submit_to_api.py @@ -11,5 +11,5 @@ def __init__(self, url, series_id, series_token, report) : def submit_report(self): header = {"GA4GH-TestbedReportSeriesId": self.series_id, "GA4GH-TestbedReportSeriesToken": self.series_token} - submit_repuest = requests.post(self.url, headers=header ,json=self.report) - return submit_repuest.status_code + submit_request = requests.post(self.url, headers=header ,json=self.report) + return submit_request.status_code From 061f49e1503343d4ea2e7a44b4b500412258870f Mon Sep 17 00:00:00 2001 From: Chen Chen Date: Tue, 5 Apr 2022 09:59:25 -0400 Subject: [PATCH 3/7] renamed and added docstring --- ga4gh/testbed/submit/report_submitter.py | 19 +++++++++++++++++++ ga4gh/testbed/submit/submit_to_api.py | 15 --------------- 2 files changed, 19 insertions(+), 15 deletions(-) create mode 100644 ga4gh/testbed/submit/report_submitter.py delete mode 100644 ga4gh/testbed/submit/submit_to_api.py diff --git a/ga4gh/testbed/submit/report_submitter.py b/ga4gh/testbed/submit/report_submitter.py new file mode 100644 index 0000000..3c977ff --- /dev/null +++ b/ga4gh/testbed/submit/report_submitter.py @@ -0,0 +1,19 @@ +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) + return submit_request.status_code + diff --git a/ga4gh/testbed/submit/submit_to_api.py b/ga4gh/testbed/submit/submit_to_api.py deleted file mode 100644 index 301adfe..0000000 --- a/ga4gh/testbed/submit/submit_to_api.py +++ /dev/null @@ -1,15 +0,0 @@ -import requests - - -class Submit(): - - def __init__(self, url, series_id, series_token, report) : - self.url = url - self.series_id = series_id - self.series_token = series_token - self.report = report - - def submit_report(self): - header = {"GA4GH-TestbedReportSeriesId": self.series_id, "GA4GH-TestbedReportSeriesToken": self.series_token} - submit_request = requests.post(self.url, headers=header ,json=self.report) - return submit_request.status_code From 2a341dd7ae3f8e305e7974ae3384664530507c3c Mon Sep 17 00:00:00 2001 From: Chen Chen Date: Thu, 7 Apr 2022 14:47:29 -0400 Subject: [PATCH 4/7] adding unit tests for report submitter --- ga4gh/testbed/submit/__init__.py | 0 .../test_submit/test_report_submitter.py | 56 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 ga4gh/testbed/submit/__init__.py create mode 100644 tests/test_unit/test_ga4gh/test_testbed/test_submit/test_report_submitter.py diff --git a/ga4gh/testbed/submit/__init__.py b/ga4gh/testbed/submit/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_unit/test_ga4gh/test_testbed/test_submit/test_report_submitter.py b/tests/test_unit/test_ga4gh/test_testbed/test_submit/test_report_submitter.py new file mode 100644 index 0000000..0f6edd1 --- /dev/null +++ b/tests/test_unit/test_ga4gh/test_testbed/test_submit/test_report_submitter.py @@ -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,result" +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, result): + submitter = ReportSubmitter + assert submitter.submit_report(series_id, series_token, report, url) == result + From 40ed71685499a9471f50010de906bac3cb508b25 Mon Sep 17 00:00:00 2001 From: Chen Chen Date: Fri, 8 Apr 2022 09:15:16 -0400 Subject: [PATCH 5/7] adding github actions to run testbed api --- .github/workflows/test.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 084180a..cb91d7c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 From 5e82926d53dcae410db40fda3e09b743c607b034 Mon Sep 17 00:00:00 2001 From: Chen Chen Date: Fri, 8 Apr 2022 09:40:24 -0400 Subject: [PATCH 6/7] updating test code for report submitter --- ga4gh/testbed/submit/report_submitter.py | 15 ++++++++++++++- .../test_submit/test_report_submitter.py | 6 +++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/ga4gh/testbed/submit/report_submitter.py b/ga4gh/testbed/submit/report_submitter.py index 3c977ff..1745411 100644 --- a/ga4gh/testbed/submit/report_submitter.py +++ b/ga4gh/testbed/submit/report_submitter.py @@ -1,3 +1,4 @@ +from re import sub import requests @@ -15,5 +16,17 @@ def submit_report(series_id, series_token, report, url="http://localhost:4500/re ''' header = {"GA4GH-TestbedReportSeriesId": series_id, "GA4GH-TestbedReportSeriesToken": series_token} submit_request = requests.post(url, headers=header ,json=report) - return submit_request.status_code + 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 diff --git a/tests/test_unit/test_ga4gh/test_testbed/test_submit/test_report_submitter.py b/tests/test_unit/test_ga4gh/test_testbed/test_submit/test_report_submitter.py index 0f6edd1..a3666c6 100644 --- a/tests/test_unit/test_ga4gh/test_testbed/test_submit/test_report_submitter.py +++ b/tests/test_unit/test_ga4gh/test_testbed/test_submit/test_report_submitter.py @@ -3,7 +3,7 @@ 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,result" +submit_report_inputs = "series_id,series_token,report,url,status_code" submit_report_cases = [ ( "1edb5213-52a2-434f-a7b8-b101fea8fb30", @@ -50,7 +50,7 @@ ] @pytest.mark.parametrize(submit_report_inputs, submit_report_cases) -def test_case_submit_report(series_id,series_token,report,url, result): +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) == result + assert submitter.submit_report(series_id, series_token, report, url)["status_code"] == status_code From 678c85343c2b7bde5a4c00dddafaeb5528348cab Mon Sep 17 00:00:00 2001 From: Jeremy Adams Date: Fri, 8 Apr 2022 09:48:23 -0400 Subject: [PATCH 7/7] increment to version 0.2.0 --- README.md | 3 +++ setup.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f5e30ba..278683d 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/setup.py b/setup.py index f6293fa..0fefc76 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ import setuptools NAME = "ga4gh-testbed-lib" -VERSION = "0.1.2" +VERSION = "0.2.0" AUTHOR = "Jeremy Adams" EMAIL = "jeremy.adams@ga4gh.org"