How to use mkmsdk - 10 common examples

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_unit / test_exception.py View on Github external
def test_connection_error_with_message():
    """
    Test error string is formatted correctly
    when exception is initialized with a message
    """
    error = ConnectionError(message="This is a message")

    assert str(error) == "Request failed\nThis is a message"
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):
github evonove / mkm-sdk / tests / tests_unit / test_api.py View on Github external
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):
        api.handle_response(mocked_response)

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

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

    mocked_response.status_code = 545
    with pytest.raises(exceptions.ConnectionError):
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_exception.py View on Github external
def test_connection_error_with_empty_response():
    """
    Test error string is formatted correctly
    when exception is initialized with empty response
    """
    error = ConnectionError({})

    assert str(error) == "Request failed"
github evonove / mkm-sdk / tests / tests_unit / test_exception.py View on Github external
def test_connection_error_with_no_args():
    """
    Test error string is formatted correctly
    when exception is initialized without arguments
    """
    error = ConnectionError()

    assert str(error) == "Request failed"
github evonove / mkm-sdk / tests / tests_unit / test_exception.py View on Github external
def test_connection_error_with_response():
    """
    Test error string is formatted correctly
    when exception is initialized with response
    """
    Response = namedtuple("Response", "status_code reason content")
    response = Response(status_code="404", reason="Not found", content="Here some content")
    error = ConnectionError(response)

    assert str(error) == "Request failed\nStatus code: 404\nResponse message: Not found\nHere some content"
github evonove / mkm-sdk / tests / tests_integration / test_oauth.py View on Github external
def test_widget_app_oauth1_is_correct():
    """Verifies if response from backend is positive using custom Client."""
    url = "https://sandbox.cardmarket.com/ws/v1.1/output.json/games"
    auth = MKMOAuth1(
        os.environ.get("MKM_APP_TOKEN"),
        client_secret=os.environ.get("MKM_APP_SECRET"),
        resource_owner_key=os.environ.get("MKM_ACCESS_TOKEN"),
        resource_owner_secret=os.environ.get("MKM_ACCESS_TOKEN_SECRET"),
        realm=url,
        client_class=MKMClient,
    )

    r = requests.get(url, auth=auth)

    assert r.status_code == 200
github evonove / mkm-sdk / tests / tests_integration / test_oauth.py View on Github external
def test_account_entity_is_as_expected():
    """Verifies the account entity received is as expected."""
    url = "https://sandbox.cardmarket.com/ws/v1.1/output.json/account"
    auth = MKMOAuth1(
        os.environ.get("MKM_APP_TOKEN"),
        client_secret=os.environ.get("MKM_APP_SECRET"),
        resource_owner_key=os.environ.get("MKM_ACCESS_TOKEN"),
        resource_owner_secret=os.environ.get("MKM_ACCESS_TOKEN_SECRET"),
        realm=url,
    )

    r = requests.get(url, auth=auth)

    json_response = r.json()

    received_first_name = json_response["account"]["name"]["firstName"]
    received_last_name = json_response["account"]["name"]["lastName"]

    assert r.status_code == 200
    assert received_first_name
github evonove / mkm-sdk / tests / tests_integration / test_oauth.py View on Github external
def test_dedicated_app_oauth1_is_correct():
    """Verifies if response from backend is positive using custom OAuth header."""
    url = "https://sandbox.cardmarket.com/ws/v1.1/output.json/games"
    auth = MKMOAuth1(
        os.environ.get("MKM_APP_TOKEN"),
        client_secret=os.environ.get("MKM_APP_SECRET"),
        resource_owner_key=os.environ.get("MKM_ACCESS_TOKEN"),
        resource_owner_secret=os.environ.get("MKM_ACCESS_TOKEN_SECRET"),
        realm=url,
    )

    r = requests.get(url, auth=auth)

    assert r.status_code == 200