def test_deserialize_unknown(mock_loader):
    response = mock_loader("unknown", "")
    try:
        logging.getLogger("indicoio.client.serialization").setLevel(
            logging.CRITICAL)
        deserialize(response)
    except Exception as e:
        assert isinstance(e, IndicoDecodingError)
    finally:
        logging.getLogger("indicoio.client.serialization").setLevel(
            logging.DEBUG)
Пример #2
0
    def _make_request(self, method, path, headers=None, **request_kwargs):
        logger.debug(
            f"[{method}] {path}\n\t Headers: {headers}\n\tRequest Args:{request_kwargs}"
        )

        response = getattr(self.request_session,
                           method)(f"{self.base_url}{path}",
                                   headers=headers,
                                   **request_kwargs)

        # code, api_response =
        content = deserialize(response)

        if response.status_code >= 400:
            if isinstance(content, dict):
                error = (f"{content.pop('error_type', 'Unknown Error')}, "
                         f"{content.pop('message', '')}")
                extras = content
            else:
                error = content
                extras = None

            raise IndicoRequestError(error=error,
                                     code=response.status_code,
                                     extras=extras)

        return content
def test_deserialize_json(mock_loader):
    response = mock_loader("application/json", "utf-8")
    content = deserialize(response)

    assert isinstance(content, dict)
def test_deserialize_msgpack(mock_loader):
    response = mock_loader("application/msgpack", "")
    content = deserialize(response)

    assert isinstance(content, dict)
def test_deserialize_text(mock_loader):
    response = mock_loader("text/html", "ISO-8859-1")
    content = deserialize(response)

    assert isinstance(content, str)