Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

10 report submitter should take report object #11

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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