From 67534f838d7ea3f8b42718f767a9d7f267cbd0dd Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Sat, 27 Oct 2018 13:09:03 +0100 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20allow=20use=20of=20`.get()`=20o?= =?UTF-8?q?n=20service=20model?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Making people use a property is a sure way to make sure they’re spelling the name of the property correctly, and allows us to easily swap out properties that call through to the underlying JSON, and properties which are implemented as methods. The API should always return something in the JSON for a property, even if it’s just `None`. --- app/main/views/api_keys.py | 6 +++--- app/main/views/service_settings.py | 4 ++-- app/models/service.py | 7 +++---- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/app/main/views/api_keys.py b/app/main/views/api_keys.py index 91b787961..95048eabf 100644 --- a/app/main/views/api_keys.py +++ b/app/main/views/api_keys.py @@ -151,12 +151,12 @@ def get_apis(): if current_service.service_callback_api: callback_api = service_api_client.get_service_callback_api( current_service.id, - current_service.get('service_callback_api')[0] + current_service.service_callback_api[0] ) if current_service.inbound_api: inbound_api = service_api_client.get_service_inbound_api( current_service.id, - current_service.get('inbound_api')[0] + current_service.inbound_api[0] ) return (callback_api, inbound_api) @@ -251,7 +251,7 @@ def get_received_text_messages_callback(): if current_service.inbound_api: return service_api_client.get_service_inbound_api( current_service.id, - current_service.get('inbound_api')[0] + current_service.inbound_api[0] ) diff --git a/app/main/views/service_settings.py b/app/main/views/service_settings.py index 5a00f47d0..25e2f29c3 100644 --- a/app/main/views/service_settings.py +++ b/app/main/views/service_settings.py @@ -782,7 +782,7 @@ def service_set_letter_contact_block(service_id): @user_is_platform_admin def set_organisation_type(service_id): - form = OrganisationTypeForm(organisation_type=current_service.get('organisation_type')) + form = OrganisationTypeForm(organisation_type=current_service.organisation_type) if form.validate_on_submit(): free_sms_fragment_limit = current_app.config['DEFAULT_FREE_SMS_FRAGMENT_LIMITS'].get( @@ -885,7 +885,7 @@ def set_letter_branding(service_id): ) return redirect(url_for('.service_settings', service_id=service_id)) - form.dvla_org_id.data = current_service.get('dvla_organisation', '001') + form.dvla_org_id.data = current_service.dvla_organisation return render_template( 'views/service-settings/set-letter-branding.html', diff --git a/app/models/service.py b/app/models/service.py index 79964e931..e9b1e7ae4 100644 --- a/app/models/service.py +++ b/app/models/service.py @@ -53,10 +53,9 @@ class Service(): ) def get(self, attr, default=None): - try: - return self._dict[attr] - except KeyError: - return default + raise NotImplementedError( + 'Use current_service.{} instead of current_service.get(\'{}\')'.format(attr, attr) + ) @property def trial_mode(self):