Don’t allow use of .get() on service model

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`.
This commit is contained in:
Chris Hill-Scott
2018-10-27 13:09:03 +01:00
parent 1e2608d2e0
commit 67534f838d
3 changed files with 8 additions and 9 deletions

View File

@@ -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]
)

View File

@@ -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',

View File

@@ -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):