Ejemplo n.º 1
0
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):
        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):
        api.handle_response(mocked_response)

    mocked_response.status_code = 1001
    with pytest.raises(exceptions.ConnectionError):
        api.handle_response(mocked_response)
Ejemplo n.º 2
0
def test_handle_request(mocked_response):
    api = Api()

    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):
        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):
        api.handle_response(mocked_response)

    mocked_response.status_code = 1001
    with pytest.raises(exceptions.ConnectionError):
        api.handle_response(mocked_response)
Ejemplo n.º 3
0
def test_create_auth():
    """
    Verifies that the default Client is used
    when all the tokens are not empty strings.
    """
    api = Api()
    auth = api.create_auth('https://www.mkmapi.eu/ws/v1.1/output.json',
                           app_token='app_token',
                           app_secret='app_secret',
                           access_token='access_token',
                           access_token_secret='access_token_secret')

    assert isinstance(auth.client, Client)
    assert auth.client.client_key == 'app_token'
    assert auth.client.client_secret == 'app_secret'
    assert auth.client.resource_owner_key == 'access_token'
    assert auth.client.resource_owner_secret == 'access_token_secret'
Ejemplo n.º 4
0
def test_create_auth_with_empty_string_token():
    """
    Verifies that the custom MKMClient is used
    when access token and access token secret
    are empty strings.
    """
    api = Api()
    auth = api.create_auth('https://www.mkmapi.eu/ws/v1.1/output.json',
                           app_token='app_token',
                           app_secret='app_secret',
                           access_token='',
                           access_token_secret='')

    assert isinstance(auth.client, MKMClient)
    assert auth.client.client_key == 'app_token'
    assert auth.client.client_secret == 'app_secret'
    assert auth.client.resource_owner_key == ''
    assert auth.client.resource_owner_secret == ''
Ejemplo n.º 5
0
def test_create_auth():
    """
    Verifies that the default Client is used
    when all the tokens are not empty strings.
    """
    api = Api("https://api.cardmarket.com/ws/v1.1/output.json")
    auth = api.create_auth(
        "https://api.cardmarket.com/ws/v1.1/output.json",
        app_token="app_token",
        app_secret="app_secret",
        access_token="access_token",
        access_token_secret="access_token_secret",
    )

    assert isinstance(auth.client, Client)
    assert auth.client.client_key == "app_token"
    assert auth.client.client_secret == "app_secret"
    assert auth.client.resource_owner_key == "access_token"
    assert auth.client.resource_owner_secret == "access_token_secret"
Ejemplo n.º 6
0
def test_create_auth_with_empty_string_token():
    """
    Verifies that the custom MKMClient is used
    when access token and access token secret
    are empty strings.
    """
    api = Api("https://api.cardmarket.com/ws/v1.1/output.json")
    auth = api.create_auth(
        "https://api.cardmarket.com/ws/v1.1/output.json",
        app_token="app_token",
        app_secret="app_secret",
        access_token="",
        access_token_secret="",
    )

    assert isinstance(auth.client, MKMClient)
    assert auth.client.client_key == "app_token"
    assert auth.client.client_secret == "app_secret"
    assert auth.client.resource_owner_key == ""
    assert auth.client.resource_owner_secret == ""
Ejemplo n.º 7
0
def test_request_with_auth_params(mocker):
    mocker.patch("mkmsdk.api.request")
    api = Api("https://sandbox.cardmarket.com/ws/v1.1/output.json")
    mocker.patch.object(api, 'create_auth')
    mocker.patch.object(api, 'handle_response')

    auth_params = {
        "app_token": "my_app_token",
        "app_secret": "my_app_secret",
        "access_token": "my_access_token",
        "access_token_secret": "my_access_token_secret"
    }

    api.request("/games", "get", auth_params=auth_params)

    api.create_auth.assert_called_with(
        "https://sandbox.cardmarket.com/ws/v1.1/output.json/games",
        app_token="my_app_token",
        app_secret="my_app_secret",
        access_token="my_access_token",
        access_token_secret="my_access_token_secret")
Ejemplo n.º 8
0
def test_good_request():
    """Verifies that a correctly formed api request returns 200."""
    new_api = Api(_API_MAP["1.1"]["api_sandbox_root"])
    response = new_api.request("/games", "get")

    assert response.status_code == 200
Ejemplo n.º 9
0
def test_sandbox_mode():
    """Verifies the sandbox endpoint is used when specified."""
    sandbox_api = Api("https://sandbox.cardmarket.com/ws/v1.1/output.json")
    expected_sandbox_base_endpoint = "https://sandbox.cardmarket.com/ws/v1.1/output.json"

    assert sandbox_api.base_endpoint == expected_sandbox_base_endpoint
Ejemplo n.º 10
0
def test_endpoint():
    """Verifies the live endpoint is used by default."""
    api = Api("https://api.cardmarket.com/ws/v1.1/output.json")
    expected_live_base_endpoint = "https://api.cardmarket.com/ws/v1.1/output.json"

    assert api.base_endpoint == expected_live_base_endpoint
Ejemplo n.º 11
0
def test_good_request():
    """Verifies that a correctly formed api request returns 200."""
    new_api = Api(sandbox_mode=True)
    response = new_api.request('/games', 'get')

    assert response.status_code == 200
Ejemplo n.º 12
0
def test_sandbox_mode():
    """Verifies the sandbox endpoint is used when specified."""
    sandbox_api = Api(sandbox_mode=True)
    expected_sandbox_base_endpoint = 'https://sandbox.mkmapi.eu/ws/v1.1/output.json'

    assert sandbox_api.base_endpoint == expected_sandbox_base_endpoint
Ejemplo n.º 13
0
def test_endpoint():
    """Verifies the live endpoint is used by default."""
    api = Api()
    expected_live_base_endpoint = 'https://www.mkmapi.eu/ws/v1.1/output.json'

    assert api.base_endpoint == expected_live_base_endpoint