Skip to content

Commit

Permalink
Merge f46edae into e439e0d
Browse files Browse the repository at this point in the history
  • Loading branch information
Chen2x committed May 17, 2022
2 parents e439e0d + f46edae commit 6e0c95e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
21 changes: 15 additions & 6 deletions ga4gh/testbed/submit/report_submitter.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,37 @@
from re import sub
import requests
import json
from ga4gh.testbed.report.report import Report


class ReportSubmitter():

def submit_report(series_id, series_token, report, url="http://localhost:4500/reports"):
def submit_report(series_id, series_token, report: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
report - GA4GH report object
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,
"status_code": None,
"error_message": None,
"report_id": None
}

if type(report) != Report:
results["status_code"] = 400
results["error_message"] = "Report submitted is not a GA4GH Report object"
return results

header = {"GA4GH-TestbedReportSeriesId": series_id, "GA4GH-TestbedReportSeriesToken": series_token}
submit_request = requests.post(url, headers=header ,json=json.loads(report.to_json()))

results["status_code"] = submit_request.status_code

if submit_request.status_code == 200:
results["report_id"] = submit_request.json()["id"]
else:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import pytest
from ga4gh.testbed.submit.report_submitter import ReportSubmitter
from ga4gh.testbed.report.report import Report

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":[]}
sample_report = Report()

submit_report_inputs = "series_id,series_token,report,url,status_code"
submit_report_cases = [
Expand Down Expand Up @@ -31,7 +32,7 @@
"K5pLbwScVu8rEoLLj8pRy5Wv7EXTVahn",
{},
"http://localhost:4500/reports",
500
400
),
(
"",
Expand Down

0 comments on commit 6e0c95e

Please sign in to comment.