def test_debug_mode(self, monkeypatch): """ Tests that the client object keeps track of responses and errors when debug mode is enabled. """ class MockException(Exception): """ A mock exception to ensure that the exception raised is the expected one. """ pass def mock_raise(exception): raise exception mock_get_response = MockGETResponse(200) monkeypatch.setattr(requests, "get", lambda url, headers: mock_get_response) monkeypatch.setattr(requests, "post", lambda url, headers, data: mock_raise(MockException)) client = api_client.APIClient(debug=True) assert client.DEBUG is True assert client.errors == [] assert client.responses == [] client.get("") assert len(client.responses) == 1 assert client.responses[0] == mock_get_response with pytest.raises(MockException): client.post("", {}) assert len(client.errors) == 1
def test_init_default_client(self): """ Test that initializing a default client generates an APIClient with the expected params. """ client = api_client.APIClient(authentication_token="") assert client.BASE_URL.startswith("https://") assert client.HEADERS["User-Agent"] == client.USER_AGENT
def test_init_default_client(self): """ Test that initializing a default client generates an APIClient with the expected params. """ client = api_client.APIClient(api_key="test") assert client.BASE_URL.startswith("https://") assert client.HEADERS["User-Agent"] == client.USER_AGENT assert client.TIMEOUT_SECONDS == 600
def test_set_authorization_header(self): """ Test that the authentication token is added to the header correctly. """ client = api_client.APIClient() authentication_token = MagicMock() client.set_authorization_header(authentication_token) assert client.HEADERS["Authorization"] == "apiKey {}".format(authentication_token)
def client(): return api_client.APIClient()
def client(): return api_client.APIClient(api_key="test")