mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-07 14:38:25 -04:00
more tests
This commit is contained in:
@@ -4,23 +4,28 @@ import pytest
|
|||||||
|
|
||||||
from notifications_python_client.base import BaseAPIClient
|
from notifications_python_client.base import BaseAPIClient
|
||||||
|
|
||||||
VALID_API_KEY = (
|
|
||||||
"key" + "-" * 68 + "service-id-uuid" + "-" * 32
|
def get_api_key():
|
||||||
) # pragma: allowlist secret
|
fake_service_id = "12345678-1234-1234-1234-123456789abc"
|
||||||
FULL_API_KEY = VALID_API_KEY[-73:]
|
fake_key_part = "abcdef12-3456-7890-abcd-ef1234567890"
|
||||||
|
api_key = "x" + fake_service_id + fake_key_part
|
||||||
|
return api_key
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def client():
|
def client():
|
||||||
return BaseAPIClient(api_key=FULL_API_KEY)
|
|
||||||
|
return BaseAPIClient(api_key=get_api_key())
|
||||||
|
|
||||||
|
|
||||||
def test_init_sets_values_correctly():
|
def test_init_sets_values_correctly():
|
||||||
client = BaseAPIClient(api_key=FULL_API_KEY)
|
api_key = get_api_key()
|
||||||
|
client = BaseAPIClient(api_key=api_key)
|
||||||
assert client.base_url == "https://api.notifications.service.gov.uk"
|
assert client.base_url == "https://api.notifications.service.gov.uk"
|
||||||
assert client.api_key == FULL_API_KEY[-36:]
|
|
||||||
assert client.service_id == FULL_API_KEY[-73:-27]
|
assert client.api_key == api_key[-36:]
|
||||||
assert client.timeout == 20
|
assert client.service_id == api_key[-73:-37]
|
||||||
|
assert client.timeout == 30
|
||||||
|
|
||||||
|
|
||||||
@patch("notifications_python_client.base.create_jwt_token")
|
@patch("notifications_python_client.base.create_jwt_token")
|
||||||
@@ -36,3 +41,12 @@ def test_get_request_success(mock_request, mock_jwt, client):
|
|||||||
mock_jwt.assert_called_once_with(client.api_key, client.service_id)
|
mock_jwt.assert_called_once_with(client.api_key, client.service_id)
|
||||||
mock_request.assert_called_once()
|
mock_request.assert_called_once()
|
||||||
assert mock_request.call_args[1]["headers"]["Authorization"] == "Bearer jwt-token"
|
assert mock_request.call_args[1]["headers"]["Authorization"] == "Bearer jwt-token"
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
test_init_sets_values_correctly()
|
||||||
|
test_get_request_success()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user