mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-08 02:18:34 -04:00
Fix calls to API client which now takes fewer args
The Notify API client changed in version 4 to take two arguments, not three (service ID was removed in favour of the combined API key). This gets a bit gnarly because the API key has to be at least a certain length so it can be substringed internally.
This commit is contained in:
@@ -8,12 +8,14 @@ KEY_TYPE_TEST = 'test'
|
||||
|
||||
class ApiKeyApiClient(NotifyAdminAPIClient):
|
||||
def __init__(self):
|
||||
super().__init__("a", "b", "c")
|
||||
super().__init__("a" * 73, "b")
|
||||
|
||||
def init_app(self, app):
|
||||
self.base_url = app.config['API_HOST_NAME']
|
||||
self.service_id = app.config['ADMIN_CLIENT_USER_NAME']
|
||||
self.api_key = app.config['ADMIN_CLIENT_SECRET']
|
||||
self.api_key = '{}-{}'.format(
|
||||
app.config['ADMIN_CLIENT_USER_NAME'],
|
||||
app.config['ADMIN_CLIENT_SECRET'],
|
||||
)
|
||||
|
||||
def get_api_keys(self, service_id, key_id=None):
|
||||
if key_id:
|
||||
|
||||
@@ -3,12 +3,14 @@ from app.notify_client import NotifyAdminAPIClient
|
||||
|
||||
class EventsApiClient(NotifyAdminAPIClient):
|
||||
def __init__(self):
|
||||
super().__init__("a", "b", "c")
|
||||
super().__init__("a" * 73, "b")
|
||||
|
||||
def init_app(self, app):
|
||||
self.base_url = app.config['API_HOST_NAME']
|
||||
self.service_id = app.config['ADMIN_CLIENT_USER_NAME']
|
||||
self.api_key = app.config['ADMIN_CLIENT_SECRET']
|
||||
self.api_key = '{}-{}'.format(
|
||||
app.config['ADMIN_CLIENT_USER_NAME'],
|
||||
app.config['ADMIN_CLIENT_SECRET'],
|
||||
)
|
||||
|
||||
def create_event(self, event_type, event_data):
|
||||
data = {
|
||||
|
||||
@@ -5,12 +5,14 @@ from app.notify_client.models import InvitedUser
|
||||
|
||||
class InviteApiClient(NotifyAdminAPIClient):
|
||||
def __init__(self):
|
||||
super().__init__("a", "b", "c")
|
||||
super().__init__("a" * 73, "b")
|
||||
|
||||
def init_app(self, app):
|
||||
self.base_url = app.config['API_HOST_NAME']
|
||||
self.service_id = app.config['ADMIN_CLIENT_USER_NAME']
|
||||
self.api_key = app.config['ADMIN_CLIENT_SECRET']
|
||||
self.api_key = '{}-{}'.format(
|
||||
app.config['ADMIN_CLIENT_USER_NAME'],
|
||||
app.config['ADMIN_CLIENT_SECRET'],
|
||||
)
|
||||
|
||||
def create_invite(self, invite_from_id, service_id, email_address, permissions):
|
||||
data = {
|
||||
|
||||
@@ -17,12 +17,14 @@ class JobApiClient(NotifyAdminAPIClient):
|
||||
}
|
||||
|
||||
def __init__(self):
|
||||
super().__init__("a", "b", "c")
|
||||
super().__init__("a" * 73, "b")
|
||||
|
||||
def init_app(self, app):
|
||||
self.base_url = app.config['API_HOST_NAME']
|
||||
self.service_id = app.config['ADMIN_CLIENT_USER_NAME']
|
||||
self.api_key = app.config['ADMIN_CLIENT_SECRET']
|
||||
self.api_key = '{}-{}'.format(
|
||||
app.config['ADMIN_CLIENT_USER_NAME'],
|
||||
app.config['ADMIN_CLIENT_SECRET'],
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def __convert_statistics(job):
|
||||
|
||||
@@ -4,12 +4,14 @@ from app.notify_client import NotifyAdminAPIClient
|
||||
class LetterJobsClient(NotifyAdminAPIClient):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__("a", "b", "c")
|
||||
super().__init__("a" * 73, "b")
|
||||
|
||||
def init_app(self, app):
|
||||
self.base_url = app.config['API_HOST_NAME']
|
||||
self.service_id = app.config['ADMIN_CLIENT_USER_NAME']
|
||||
self.api_key = app.config['ADMIN_CLIENT_SECRET']
|
||||
self.api_key = '{}-{}'.format(
|
||||
app.config['ADMIN_CLIENT_USER_NAME'],
|
||||
app.config['ADMIN_CLIENT_SECRET'],
|
||||
)
|
||||
|
||||
def get_letter_jobs(self):
|
||||
return self.get(url='/letter-jobs')['data']
|
||||
|
||||
@@ -3,12 +3,14 @@ from app.notify_client import _attach_current_user, NotifyAdminAPIClient
|
||||
|
||||
class NotificationApiClient(NotifyAdminAPIClient):
|
||||
def __init__(self):
|
||||
super().__init__("a", "b", "c")
|
||||
super().__init__("a" * 73, "b")
|
||||
|
||||
def init_app(self, app):
|
||||
self.base_url = app.config['API_HOST_NAME']
|
||||
self.service_id = app.config['ADMIN_CLIENT_USER_NAME']
|
||||
self.api_key = app.config['ADMIN_CLIENT_SECRET']
|
||||
self.api_key = '{}-{}'.format(
|
||||
app.config['ADMIN_CLIENT_USER_NAME'],
|
||||
app.config['ADMIN_CLIENT_SECRET'],
|
||||
)
|
||||
|
||||
def get_notifications_for_service(
|
||||
self,
|
||||
|
||||
@@ -4,12 +4,14 @@ from app.notify_client import NotifyAdminAPIClient
|
||||
class OrganisationsClient(NotifyAdminAPIClient):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__("a", "b", "c")
|
||||
super().__init__("a" * 73, "b")
|
||||
|
||||
def init_app(self, app):
|
||||
self.base_url = app.config['API_HOST_NAME']
|
||||
self.service_id = app.config['ADMIN_CLIENT_USER_NAME']
|
||||
self.api_key = app.config['ADMIN_CLIENT_SECRET']
|
||||
self.api_key = '{}-{}'.format(
|
||||
app.config['ADMIN_CLIENT_USER_NAME'],
|
||||
app.config['ADMIN_CLIENT_SECRET'],
|
||||
)
|
||||
|
||||
def get_organisation(self, id):
|
||||
return self.get(url='/organisation/{}'.format(id))
|
||||
|
||||
@@ -4,12 +4,14 @@ from app.notify_client import _attach_current_user, NotifyAdminAPIClient
|
||||
|
||||
class ProviderClient(NotifyAdminAPIClient):
|
||||
def __init__(self):
|
||||
super().__init__("a", "b", "c")
|
||||
super().__init__("a" * 73, "b")
|
||||
|
||||
def init_app(self, app):
|
||||
self.base_url = app.config['API_HOST_NAME']
|
||||
self.service_id = app.config['ADMIN_CLIENT_USER_NAME']
|
||||
self.api_key = app.config['ADMIN_CLIENT_SECRET']
|
||||
self.api_key = '{}-{}'.format(
|
||||
app.config['ADMIN_CLIENT_USER_NAME'],
|
||||
app.config['ADMIN_CLIENT_SECRET'],
|
||||
)
|
||||
|
||||
def get_all_providers(self):
|
||||
return self.get(
|
||||
|
||||
@@ -10,12 +10,14 @@ class ServiceAPIClient(NotifyAdminAPIClient):
|
||||
# Fudge assert in the super __init__ so
|
||||
# we can set those variables later.
|
||||
def __init__(self):
|
||||
super().__init__("a", "b", "c")
|
||||
super().__init__("a" * 73, "b")
|
||||
|
||||
def init_app(self, application):
|
||||
self.base_url = application.config['API_HOST_NAME']
|
||||
self.service_id = application.config['ADMIN_CLIENT_USER_NAME']
|
||||
self.api_key = application.config['ADMIN_CLIENT_SECRET']
|
||||
self.api_key = '{}-{}'.format(
|
||||
application.config['ADMIN_CLIENT_USER_NAME'],
|
||||
application.config['ADMIN_CLIENT_SECRET'],
|
||||
)
|
||||
|
||||
def create_service(self, service_name, message_limit, restricted, user_id, email_from):
|
||||
"""
|
||||
|
||||
@@ -4,12 +4,14 @@ from app.notify_client import NotifyAdminAPIClient
|
||||
|
||||
class StatusApiClient(NotifyAdminAPIClient):
|
||||
def __init__(self):
|
||||
super().__init__("a", "b", "c")
|
||||
super().__init__("a" * 73, "b")
|
||||
|
||||
def init_app(self, app):
|
||||
self.base_url = app.config['API_HOST_NAME']
|
||||
self.service_id = app.config['ADMIN_CLIENT_USER_NAME']
|
||||
self.api_key = app.config['ADMIN_CLIENT_SECRET']
|
||||
self.api_key = '{}-{}'.format(
|
||||
app.config['ADMIN_CLIENT_USER_NAME'],
|
||||
app.config['ADMIN_CLIENT_SECRET'],
|
||||
)
|
||||
|
||||
def get_status(self, *params):
|
||||
return self.get(url='/_status', *params)
|
||||
|
||||
@@ -3,12 +3,14 @@ from app.notify_client import NotifyAdminAPIClient
|
||||
|
||||
class TemplateStatisticsApiClient(NotifyAdminAPIClient):
|
||||
def __init__(self):
|
||||
super().__init__("a", "b", "c")
|
||||
super().__init__("a" * 73, "b")
|
||||
|
||||
def init_app(self, app):
|
||||
self.base_url = app.config['API_HOST_NAME']
|
||||
self.service_id = app.config['ADMIN_CLIENT_USER_NAME']
|
||||
self.api_key = app.config['ADMIN_CLIENT_SECRET']
|
||||
self.api_key = '{}-{}'.format(
|
||||
app.config['ADMIN_CLIENT_USER_NAME'],
|
||||
app.config['ADMIN_CLIENT_SECRET'],
|
||||
)
|
||||
|
||||
def get_template_statistics_for_service(self, service_id, limit_days=None):
|
||||
params = {}
|
||||
|
||||
@@ -15,12 +15,14 @@ ALLOWED_ATTRIBUTES = {
|
||||
|
||||
class UserApiClient(NotifyAdminAPIClient):
|
||||
def __init__(self):
|
||||
super().__init__("a", "b", "c")
|
||||
super().__init__("a" * 73, "b")
|
||||
|
||||
def init_app(self, app):
|
||||
self.base_url = app.config['API_HOST_NAME']
|
||||
self.service_id = app.config['ADMIN_CLIENT_USER_NAME']
|
||||
self.api_key = app.config['ADMIN_CLIENT_SECRET']
|
||||
self.api_key = '{}-{}'.format(
|
||||
app.config['ADMIN_CLIENT_USER_NAME'],
|
||||
app.config['ADMIN_CLIENT_SECRET'],
|
||||
)
|
||||
self.max_failed_login_count = app.config["MAX_FAILED_LOGIN_COUNT"]
|
||||
|
||||
def register_user(self, name, email_address, mobile_number, password):
|
||||
|
||||
@@ -9,6 +9,9 @@ from tests.conftest import api_user_active, platform_admin_user
|
||||
from app.notify_client import NotifyAdminAPIClient
|
||||
|
||||
|
||||
SAMPLE_API_KEY = '{}-{}'.format('a' * 36, 's' * 36)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('method', [
|
||||
'put',
|
||||
'post',
|
||||
@@ -23,7 +26,7 @@ from app.notify_client import NotifyAdminAPIClient
|
||||
None
|
||||
], ids=['active_service', 'no_service'])
|
||||
def test_active_service_can_be_modified(app_, method, user, service):
|
||||
api_client = NotifyAdminAPIClient('api_key', 'base_url', 'service_id')
|
||||
api_client = NotifyAdminAPIClient(SAMPLE_API_KEY, 'base_url')
|
||||
|
||||
with app_.test_request_context() as request_context, app_.test_client() as client:
|
||||
client.login(user)
|
||||
@@ -42,7 +45,7 @@ def test_active_service_can_be_modified(app_, method, user, service):
|
||||
'delete'
|
||||
])
|
||||
def test_inactive_service_cannot_be_modified_by_normal_user(app_, api_user_active, method):
|
||||
api_client = NotifyAdminAPIClient('api_key', 'base_url', 'service_id')
|
||||
api_client = NotifyAdminAPIClient(SAMPLE_API_KEY, 'base_url')
|
||||
|
||||
with app_.test_request_context() as request_context, app_.test_client() as client:
|
||||
client.login(api_user_active)
|
||||
@@ -61,7 +64,7 @@ def test_inactive_service_cannot_be_modified_by_normal_user(app_, api_user_activ
|
||||
'delete'
|
||||
])
|
||||
def test_inactive_service_can_be_modified_by_platform_admin(app_, platform_admin_user, method):
|
||||
api_client = NotifyAdminAPIClient('api_key', 'base_url', 'service_id')
|
||||
api_client = NotifyAdminAPIClient(SAMPLE_API_KEY, 'base_url')
|
||||
|
||||
with app_.test_request_context() as request_context, app_.test_client() as client:
|
||||
client.login(platform_admin_user)
|
||||
@@ -75,7 +78,7 @@ def test_inactive_service_can_be_modified_by_platform_admin(app_, platform_admin
|
||||
|
||||
|
||||
def test_generate_headers_sets_standard_headers():
|
||||
api_client = NotifyAdminAPIClient('api_key', 'base_url', 'service_id')
|
||||
api_client = NotifyAdminAPIClient(SAMPLE_API_KEY, 'base_url')
|
||||
|
||||
# with patch('app.notify_client.has_request_context', return_value=False):
|
||||
headers = api_client.generate_headers('api_token')
|
||||
@@ -87,7 +90,7 @@ def test_generate_headers_sets_standard_headers():
|
||||
|
||||
|
||||
def test_generate_headers_sets_request_id_if_in_request_context(app_):
|
||||
api_client = NotifyAdminAPIClient('api_key', 'base_url', 'service_id')
|
||||
api_client = NotifyAdminAPIClient(SAMPLE_API_KEY, 'base_url')
|
||||
|
||||
with app_.test_request_context() as request_context:
|
||||
headers = api_client.generate_headers('api_token')
|
||||
|
||||
Reference in New Issue
Block a user