Esempio n. 1
0
 def request(self, method: str, path: str, headers: dict = None, auth: AuthBase = None,
             check_error=True, expected_status=None, **kwargs):
     """Generic request send"""
     url = self.build_url(path)
     auth = auth or self.auth
     if _log.isEnabledFor(logging.DEBUG):
         _log.debug("Request `{m} {u}` with headers {h}, auth {a}, kwargs {k}".format(
             m=method.upper(), u=url, h=headers and headers.keys(), a=type(auth).__name__, k=list(kwargs.keys()))
         )
     resp = self.session.request(
         method=method,
         url=url,
         headers=self._merged_headers(headers),
         auth=auth,
         timeout=kwargs.pop("timeout", self.default_timeout),
         **kwargs
     )
     # Check for API errors and unexpected HTTP status codes as desired.
     status = resp.status_code
     expected_status = ensure_list(expected_status) if expected_status else []
     if check_error and status >= 400 and status not in expected_status:
         self._raise_api_error(resp)
     if expected_status and status not in expected_status:
         raise OpenEoClientException("Got status code {s!r} for `{m} {p}` (expected {e!r})".format(
             m=method.upper(), p=path, s=status, e=expected_status)
         )
     return resp
Esempio n. 2
0
def test_ensure_list(input, expected):
    assert ensure_list(input) == expected