Inherit don’t duplicate API client constructor

This removes some code which is duplicative and obscure (ie it’s not
very clear why we do `"a" * 73` even though there is a Very Good Reason
for doing so).
This commit is contained in:
Chris Hill-Scott
2019-01-29 11:12:33 +00:00
parent eae0a5a632
commit 1d3a4e5043
22 changed files with 8 additions and 63 deletions

View File

@@ -16,6 +16,9 @@ class NotifyAdminAPIClient(BaseAPIClient):
redis_client = RedisClient()
def __init__(self):
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']

View File

@@ -7,8 +7,6 @@ KEY_TYPE_TEST = 'test'
class ApiKeyApiClient(NotifyAdminAPIClient):
def __init__(self):
super().__init__("a" * 73, "b")
def get_api_keys(self, service_id):
return self.get(url='/service/{}/api-keys'.format(service_id))

View File

@@ -2,10 +2,6 @@ from app.notify_client import NotifyAdminAPIClient
class BillingAPIClient(NotifyAdminAPIClient):
# Fudge assert in the super __init__ so
# we can set those variables later.
def __init__(self):
super().__init__("a" * 73, "b")
def get_billable_units_ft(self, service_id, year):
return self.get(

View File

@@ -2,10 +2,6 @@ from app.notify_client import NotifyAdminAPIClient
class ComplaintApiClient(NotifyAdminAPIClient):
# Fudge assert in the super __init__ so
# we can set those variables later.
def __init__(self):
super().__init__("a" * 73, "b")
def get_all_complaints(self, page=1):
params = {'page': page}

View File

@@ -3,9 +3,6 @@ from app.notify_client import NotifyAdminAPIClient, cache
class EmailBrandingClient(NotifyAdminAPIClient):
def __init__(self):
super().__init__("a" * 73, "b")
@cache.set('email_branding-{branding_id}')
def get_email_branding(self, branding_id):
return self.get(url='/email-branding/{}'.format(branding_id))

View File

@@ -2,8 +2,6 @@ from app.notify_client import NotifyAdminAPIClient
class EventsApiClient(NotifyAdminAPIClient):
def __init__(self):
super().__init__("a" * 73, "b")
def create_event(self, event_type, event_data):
data = {

View File

@@ -3,9 +3,6 @@ from app.notify_client import NotifyAdminAPIClient
class InboundNumberClient(NotifyAdminAPIClient):
def __init__(self):
super().__init__("a" * 73, "b")
def get_available_inbound_sms_numbers(self):
return self.get(url='/inbound-number/available')

View File

@@ -6,8 +6,6 @@ from app.notify_client import NotifyAdminAPIClient, _attach_current_user, cache
class InviteApiClient(NotifyAdminAPIClient):
def __init__(self):
super().__init__("a" * 73, "b")
def init_app(self, app):
super().init_app(app)

View File

@@ -18,9 +18,6 @@ class JobApiClient(NotifyAdminAPIClient):
NON_SCHEDULED_JOB_STATUSES = JOB_STATUSES - {'scheduled', 'cancelled'}
def __init__(self):
super().__init__("a" * 73, "b")
@staticmethod
def __convert_statistics(job):
results = defaultdict(int)

View File

@@ -3,9 +3,6 @@ from app.notify_client import NotifyAdminAPIClient
class LetterBrandingClient(NotifyAdminAPIClient):
def __init__(self):
super().__init__("a" * 73, "b")
def get_letter_branding(self):
return self.get(url='/dvla_organisations')

View File

@@ -3,9 +3,6 @@ from app.notify_client import NotifyAdminAPIClient
class LetterJobsClient(NotifyAdminAPIClient):
def __init__(self):
super().__init__("a" * 73, "b")
def submit_returned_letters(self, references):
return self.post(
url='/letters/returned',

View File

@@ -2,8 +2,6 @@ from app.notify_client import NotifyAdminAPIClient, _attach_current_user
class NotificationApiClient(NotifyAdminAPIClient):
def __init__(self):
super().__init__("a" * 73, "b")
def get_notifications_for_service(
self,

View File

@@ -3,8 +3,6 @@ from app.notify_client import NotifyAdminAPIClient, _attach_current_user
class OrgInviteApiClient(NotifyAdminAPIClient):
def __init__(self):
super().__init__("a" * 73, "b")
def init_app(self, app):
super().init_app(app)

View File

@@ -3,9 +3,6 @@ from app.notify_client import NotifyAdminAPIClient, _attach_current_user, cache
class OrganisationsClient(NotifyAdminAPIClient):
def __init__(self):
super().__init__("a" * 73, "b")
def get_organisations(self):
return self.get(url='/organisations')

View File

@@ -2,10 +2,6 @@ from app.notify_client import NotifyAdminAPIClient
class PlatformStatsAPIClient(NotifyAdminAPIClient):
# Fudge assert in the super __init__ so
# we can set those variables later.
def __init__(self):
super().__init__("a" * 73, "b")
def get_aggregate_platform_stats(self, params_dict=None):
return self.get("/platform-stats", params=params_dict)

View File

@@ -3,8 +3,6 @@ from app.notify_client import NotifyAdminAPIClient, _attach_current_user
class ProviderClient(NotifyAdminAPIClient):
def __init__(self):
super().__init__("a" * 73, "b")
def get_all_providers(self):
return self.get(

View File

@@ -3,10 +3,6 @@ from app.notify_client import NotifyAdminAPIClient, _attach_current_user, cache
class ServiceAPIClient(NotifyAdminAPIClient):
# Fudge assert in the super __init__ so
# we can set those variables later.
def __init__(self):
super().__init__("a" * 73, "b")
@cache.delete('user-{user_id}')
def create_service(

View File

@@ -3,8 +3,6 @@ from app.notify_client import NotifyAdminAPIClient
class StatusApiClient(NotifyAdminAPIClient):
def __init__(self):
super().__init__("a" * 73, "b")
def get_status(self, *params):
return self.get(url='/_status', *params)

View File

@@ -2,10 +2,6 @@ from app.notify_client import NotifyAdminAPIClient, cache
class TemplateFolderAPIClient(NotifyAdminAPIClient):
# Fudge assert in the super __init__ so
# we can set those variables later.
def __init__(self):
super().__init__('a' * 73, 'b')
@cache.delete('service-{service_id}-template-folders')
def create_template_folder(

View File

@@ -2,8 +2,6 @@ from app.notify_client import NotifyAdminAPIClient
class TemplateStatisticsApiClient(NotifyAdminAPIClient):
def __init__(self):
super().__init__("a" * 73, "b")
def get_template_statistics_for_service(self, service_id, limit_days=None):
params = {}

View File

@@ -18,8 +18,6 @@ ALLOWED_ATTRIBUTES = {
class UserApiClient(NotifyAdminAPIClient):
def __init__(self):
super().__init__("a" * 73, "b")
def init_app(self, app):
super().init_app(app)

View File

@@ -9,8 +9,6 @@ from app.notify_client import NotifyAdminAPIClient
from tests import service_json
from tests.conftest import api_user_active, platform_admin_user, set_config
SAMPLE_API_KEY = '{}-{}'.format('a' * 36, 's' * 36)
@pytest.mark.parametrize('method', [
'put',
@@ -26,7 +24,7 @@ SAMPLE_API_KEY = '{}-{}'.format('a' * 36, 's' * 36)
None
], ids=['active_service', 'no_service'])
def test_active_service_can_be_modified(app_, method, user, service):
api_client = NotifyAdminAPIClient(SAMPLE_API_KEY, 'base_url')
api_client = NotifyAdminAPIClient()
with app_.test_request_context() as request_context, app_.test_client() as client:
client.login(user)
@@ -45,7 +43,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(SAMPLE_API_KEY, 'base_url')
api_client = NotifyAdminAPIClient()
with app_.test_request_context() as request_context, app_.test_client() as client:
client.login(api_user_active)
@@ -64,7 +62,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(SAMPLE_API_KEY, 'base_url')
api_client = NotifyAdminAPIClient()
with app_.test_request_context() as request_context, app_.test_client() as client:
client.login(platform_admin_user)
@@ -78,7 +76,7 @@ def test_inactive_service_can_be_modified_by_platform_admin(app_, platform_admin
def test_generate_headers_sets_standard_headers(app_):
api_client = NotifyAdminAPIClient(SAMPLE_API_KEY, 'base_url')
api_client = NotifyAdminAPIClient()
with set_config(app_, 'ROUTE_SECRET_KEY_1', 'proxy-secret'):
api_client.init_app(app_)
@@ -93,7 +91,7 @@ def test_generate_headers_sets_standard_headers(app_):
def test_generate_headers_sets_request_id_if_in_request_context(app_):
api_client = NotifyAdminAPIClient(SAMPLE_API_KEY, 'base_url')
api_client = NotifyAdminAPIClient()
api_client.init_app(app_)
with app_.test_request_context() as request_context: