X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=behave_tests%2Ffeatures%2Fsteps%2Ftestapi.py;h=15ef8b1b674b2219a2e278dc2d56d75c498a4e83;hb=e2faa91512043386aa3a11ca44792bd3c009db76;hp=67e51045e8eb550c40d984aef2002011b2b147bb;hpb=bc825ac3ee6f58791d47f9bfef288624624f700c;p=nfvbench.git diff --git a/behave_tests/features/steps/testapi.py b/behave_tests/features/steps/testapi.py index 67e5104..15ef8b1 100644 --- a/behave_tests/features/steps/testapi.py +++ b/behave_tests/features/steps/testapi.py @@ -14,22 +14,21 @@ # under the License. # -import json +import logging import requests class TestapiClient: - def __init__(self, testapi_url: str, logger): + __test__ = False # Hint for pytest: TestapiClient is not a test class. + + def __init__(self, testapi_url: str): """ Args: testapi_url: testapi URL as a string, for instance "http://172.20.73.203:8000/api/v1/results" - - logger: reference to behave_tests logger. - """ self._base_url = testapi_url - self._logger = logger + self._logger = logging.getLogger("behave_tests") def find_last_result(self, testapi_params, scenario_tag: str, nfvbench_test_input): """Search testapi database and return latest result matching filters. @@ -118,19 +117,31 @@ class TestapiClient: Perform an HTTP GET request on testapi, check status code and return JSON results as dictionary. - Args: testapi_url: a complete URL to request testapi results (with base - endpoint and parameters) + Args: + testapi_url: a complete URL to request testapi results (with base + endpoint and parameters) Returns: The JSON document from testapi as a Python dictionary Raises: + * requests.exceptions.ConnectionError in case of network problem + when trying to establish a connection with the TestAPI database + (DNS failure, refused connection, ...) + + * requests.exceptions.ConnectTimeout in case of timeout during the + request. + + * requests.exception.HTTPError if the HTTP request returned an + unsuccessful status code. + * another exception derived from requests.exceptions.RequestException + in case of problem during the HTTP request. """ response = requests.get(testapi_url) - assert response.status_code == 200 # TODO: better error message - results = json.loads(response.text) - return results + # raise an HTTPError if the HTTP request returned an unsuccessful status code: + response.raise_for_status() + return response.json() def equal_test_conditions(testapi_input, nfvbench_input):