コード例 #1
0
    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
コード例 #2
0
 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
コード例 #3
0
 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
コード例 #4
0
    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)
コード例 #5
0
def client():
    return api_client.APIClient()
コード例 #6
0
def client():
    return api_client.APIClient(api_key="test")