Don’t allow indexing 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.
This commit is contained in:
Chris Hill-Scott
2018-10-26 12:13:04 +01:00
parent 780b9bb715
commit e1197c54a5
10 changed files with 17 additions and 12 deletions

View File

@@ -273,6 +273,7 @@ class Service():
ALLOWED_PROPERTIES = {
'active',
'contact_link',
'dvla_organisation',
'email_branding',
'email_from',
@@ -305,7 +306,9 @@ class Service():
raise AttributeError('`{}` is not a service attribute'.format(attr))
def __getitem__(self, attr):
return self.__getattr__(attr)
raise NotImplementedError(
'Use current_service.{} instead of current_service[\'{}\']'.format(attr, attr)
)
def get(self, attr, default=None):
try: