Skip to content

Commit

Permalink
Merge pull request #28 from ga4gh-rnaseq/develop
Browse files Browse the repository at this point in the history
Merge develop into master
  • Loading branch information
Jeremy Adams committed Nov 27, 2020
2 parents 298c032 + 8a46aa6 commit a3accae
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 13 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ env:
global:
- GH_USER: ga4gh-rnaseq
- GH_REPO: rnaget-compliance-suite
- REQUESTS_CA_BUNDLE: ${TRAVIS_BUILD_DIR}/certs/cabundle.pem
- secure: J+a6OkJZRU5m/qy9G3AMdmPjtuegdAhCypaoa7lk9Vs8zVoY1+ImEfZEVC1nLZQgaCmmUvYqUHqRj4SZ+0Vv4FaGkqsfX4Ad5/ymVF4WnkkC2mr6si4jzOpZN+7OpHM0z5gY6X3bir3Jlx/WB/I3IDCjysOUfOLw9X3nD9Cfvq108KjMpR5RM76mBn23XNubyZJ8BX36YaowAEVpml83VyEA3QAwd37ejB3tuUigSk1i9PWRnMqKdrY6fbM6DuTnFiI1ZW1KEvvr5AHY61XsatSLFIAg8RH2suBduneLdxbkGPW9jfvGt+l/G73STagIcuv69jOQh/rIPxrlSy8JPt3hbWRS6eaeZOidtoURofTYm2CEFFO8WOsagKCyAirUYBHKCTdN518tuR6t++5gPfQQB97l/n+4C4WdKDhPYP1Lto+YXjyumBE0E/JRSTTsum4kcps8SSjJtHTn86ZeI0jBIfkLEMjNc7/dQog5hCD7viH+b+GTqVuz70CxzrZut5CJdBWGj2hPwSbkbveVi50Ccp/eodh7uUZZO6Mptd1HF4+ad53XBEjaxds8Dm1cVCXH+3gJajAAYb99mPZWjEl1h/Iho6H9r/wwrTlfMHVPGBe42DtQpFfHfOzgz4NOgqR7lyP7sLEEd6quTn7RCMMsdXukJgGIQvMHKaKy3Cc=
36 changes: 25 additions & 11 deletions compliance_suite/elements/api_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import os
import re
import requests
from requests.exceptions import SSLError

import compliance_suite.exceptions.test_status_exception as tse
from compliance_suite.schema_validator import SchemaValidator
Expand Down Expand Up @@ -38,11 +39,18 @@ def execute_test_case(self):
# make GET/POST request
url = self.get_mature_url()
request_method = REQUEST_METHOD[self.case_params["http_method"]]
response = request_method(
url,
headers=self.headers,
params=self.params)
self.set_test_status(url, response)
response = None

try:
response = request_method(
url,
headers=self.headers,
params=self.params,
verify=True)
except SSLError:
pass
finally:
self.set_test_status(url, response)

def set_test_status(self, url, response):
"""Sets test status and messages based on response
Expand All @@ -59,19 +67,25 @@ def set_test_status(self, url, response):
params (dict): key-value mapping of supplied parameters
response (Response): response object from the request
"""

# apply_params = self.test.kwargs["apply_params"]

if self.status != -1:
self.append_audit("Request: " + url)
self.append_audit("Params: " + str(sanitize_dict(self.params)))
self.append_audit("Headers: " + str(sanitize_dict(self.headers)))
# only add response body if JSON format is expected
if self.is_json:
if re.compile("json").search(response.headers["Content-Type"]):
self.append_audit("Response Body: " + response.text)

try:

# Validation 0, if the response is None type, that means the
# request did not complete successfully, this is an automatic
# failure
if response == None:
raise tse.NoResponseException("No response returned by HTTP request")

# only add response body if JSON format is expected
if self.is_json:
if re.compile("json").search(response.headers["Content-Type"]):
self.append_audit("Response Body: " + response.text)

# Validation 1, Content-Type, Media Type validation
# check response content type is in accepted media types
response_media_type = self.__get_response_media_type(response)
Expand Down
2 changes: 1 addition & 1 deletion compliance_suite/elements/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def __init__(self, case_params, test, runner):
if "summary_skip" in self.case_params.keys() else "",
2: "An unhandled exception occurred"
}
self.summary = self.set_summary()
self.set_summary()

self.error_message = None
self.audit = []
Expand Down
4 changes: 3 additions & 1 deletion compliance_suite/elements/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"""

from compliance_suite.elements.element import Element
from compliance_suite.elements.api_case import APICase
import json

class Component(Element):
Expand All @@ -35,7 +36,8 @@ def __init__(self, test_params, test, runner):
self.test_params = test_params
self.test = test
self.runner = runner
self.case_class = None
self.case_class = APICase
self.test_cases = []

def create_test_cases(self):
"""Create all test cases from params
Expand Down
5 changes: 5 additions & 0 deletions compliance_suite/exceptions/test_status_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ class TestStatusException(Exception):

pass

class NoResponseException(TestStatusException):
"""Raised when no response was received from the endpoint"""

pass

class MediaTypeException(TestStatusException):
"""Raised when response content type does not match accepted media types"""

Expand Down

0 comments on commit a3accae

Please sign in to comment.