How to use the mkmsdk.exceptions function in mkmsdk

To help you get started, we’ve selected a few mkmsdk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github evonove / mkm-sdk / tests / tests_integration / test_mkm.py View on Github external
def test_request_with_params(mkm_sandbox20):
    """Verifies request to an endpoint that has mandatory parameters"""

    r = mkm_sandbox20.account_management.vacation(params={"onVacation": "false"})
    assert r.status_code == 200

    with pytest.raises(exceptions.ConnectionError) as e:
        mkm_sandbox20.account_management.vacation()
    assert e.value.response.status_code == 400
github evonove / mkm-sdk / tests / tests_unit / test_api.py View on Github external
def test_handle_request(mocked_response):
    api = Api("https://sandbox.cardmarket.com/ws/v1.1/output.json")

    mocked_response.status_code = 400
    with pytest.raises(exceptions.ConnectionError):
        api.handle_response(mocked_response)

    mocked_response.status_code = 401
    with pytest.raises(exceptions.ConnectionError):
        api.handle_response(mocked_response)

    mocked_response.status_code = 403
    with pytest.raises(exceptions.ConnectionError):
        api.handle_response(mocked_response)

    mocked_response.status_code = 404
    with pytest.raises(exceptions.ConnectionError):
        api.handle_response(mocked_response)

    mocked_response.status_code = 405
    with pytest.raises(exceptions.ConnectionError):
        api.handle_response(mocked_response)

    mocked_response.status_code = 409
    with pytest.raises(exceptions.ConnectionError):
        api.handle_response(mocked_response)

    mocked_response.status_code = 410
    with pytest.raises(exceptions.ConnectionError):
github evonove / mkm-sdk / mkmsdk / api.py View on Github external
def handle_response(self, response):
        """
        Check the HTTP response

        Params:
            `response`: Response received from the server
        Return:
            `response`: Returns the response received if positive or raise exception if negative
        """

        # We don't automatically follow redirects so accept those responses
        if 200 <= response.status_code <= 399:
            return response
        else:
            raise exceptions.ConnectionError(response)