Use constants for organisation type

This reduces the chances of making a typo, because doing so will raise
an exception rather than fail silently.
This commit is contained in:
Chris Hill-Scott
2019-09-12 15:03:32 +01:00
parent 077dc194c6
commit 20f857753a
5 changed files with 41 additions and 22 deletions

View File

@@ -9,15 +9,24 @@ from app.notify_client.organisations_api_client import organisations_client
class Organisation(JSONModel):
TYPE_CENTRAL = 'central'
TYPE_LOCAL = 'local'
TYPE_NHS_CENTRAL = 'nhs_central'
TYPE_NHS_LOCAL = 'nhs_local'
TYPE_NHS_GP = 'nhs_gp'
TYPE_EMERGENCY_SERVICE = 'emergency_service'
TYPE_SCHOOL_OR_COLLEGE = 'school_or_college'
TYPE_OTHER = 'other'
TYPES = (
('central', 'Central government'),
('local', 'Local government'),
('nhs_central', 'NHS central government agency or public body'),
('nhs_local', 'NHS Trust or Clinical Commissioning Group'),
('nhs_gp', 'GP practice'),
('emergency_service', 'Emergency service'),
('school_or_college', 'School or college'),
('other', 'Other'),
(TYPE_CENTRAL, 'Central government'),
(TYPE_LOCAL, 'Local government'),
(TYPE_NHS_CENTRAL, 'NHS central government agency or public body'),
(TYPE_NHS_LOCAL, 'NHS Trust or Clinical Commissioning Group'),
(TYPE_NHS_GP, 'GP practice'),
(TYPE_EMERGENCY_SERVICE, 'Emergency service'),
(TYPE_SCHOOL_OR_COLLEGE, 'School or college'),
(TYPE_OTHER, 'Other'),
)
ALLOWED_PROPERTIES = {

View File

@@ -270,7 +270,7 @@ class Service(JSONModel):
@property
def shouldnt_use_govuk_as_sms_sender(self):
return self.organisation_type != 'central'
return self.organisation_type != Organisation.TYPE_CENTRAL
@cached_property
def sms_senders(self):
@@ -419,7 +419,7 @@ class Service(JSONModel):
@property
def needs_to_change_email_branding(self):
return self.email_branding_id is None and self.organisation_type != 'central'
return self.email_branding_id is None and self.organisation_type != Organisation.TYPE_CENTRAL
@property
def letter_branding_id(self):
@@ -599,7 +599,10 @@ class Service(JSONModel):
def able_to_accept_agreement(self):
return (
self.organisation.agreement_signed is not None
or self.organisation_type in {'nhs_gp', 'nhs_local'}
or self.organisation_type in {
Organisation.TYPE_NHS_GP,
Organisation.TYPE_NHS_LOCAL,
}
)
@property