def test_fails_if_client_id_missing():
    with pytest.raises(AssertionError) as err:
        BaseAPIClient(api_key=API_KEY_ID)
    assert str(err.value) == "Missing service ID"
from __future__ import division
from __future__ import absolute_import
from builtins import str
from future import standard_library
standard_library.install_aliases()
import requests
import mock

import pytest
from notifications_python_client.errors import HTTPError, InvalidResponse
from notifications_python_client.base import BaseAPIClient
from tests.conftest import API_KEY_ID, SERVICE_ID, COMBINED_API_KEY


@pytest.mark.parametrize('client', [
    BaseAPIClient(api_key=COMBINED_API_KEY),
    BaseAPIClient(COMBINED_API_KEY),
],
                         ids=['combined api key', 'positional api key'])
def test_passes_through_service_id_and_key(rmock, client):
    with mock.patch('notifications_python_client.base.create_jwt_token'
                    ) as mock_create_token:
        rmock.request("GET", "/", status_code=204)
        client.request("GET", '/')
    mock_create_token.assert_called_once_with(API_KEY_ID, SERVICE_ID)
    assert client.base_url == 'https://api.notifications.service.gov.uk'


def test_can_set_base_url():
    client = BaseAPIClient(base_url='foo', api_key=COMBINED_API_KEY)
    assert client.base_url == 'foo'
def test_can_set_base_url():
    client = BaseAPIClient(base_url='foo', api_key=COMBINED_API_KEY)
    assert client.base_url == 'foo'
Esempio n. 4
0
def base_client():
    yield BaseAPIClient(base_url=TEST_HOST, api_key=COMBINED_API_KEY)