Refactor to not need custom constructor

All the constructor of the service model is doing is setting a default
value of a property, this is more idiomatically expressed with a custom
property, and means we can get rid of the custom constructor entirely.
This commit is contained in:
Chris Hill-Scott
2020-06-03 15:04:45 +01:00
parent a95d9b5152
commit e089de74ee

View File

@@ -39,7 +39,6 @@ class Service(JSONModel):
'letter_contact_block',
'message_limit',
'name',
'permissions',
'prefix_sms',
'research_mode',
'service_callback_api',
@@ -68,16 +67,14 @@ class Service(JSONModel):
'upload_letters',
)
def __init__(self, _dict):
super().__init__(_dict)
if 'permissions' not in self._dict:
self.permissions = {'email', 'sms', 'letter'}
@classmethod
def from_id(cls, service_id):
return cls(service_api_client.get_service(service_id)['data'])
@property
def permissions(self):
return self._dict.get('permissions', self.TEMPLATE_TYPES)
def update(self, **kwargs):
return service_api_client.update_service(self.id, **kwargs)