- Migration to add Service.organisation_id

- Add oranisation_id to Service data model.
- Update methods to create service and associate service to organisation to set the organisation_id on the Service.
- Create the missing test, if the service user email matches a domain for an organisation then associate the service to the organisation and inherit crown and organisation_type from the organisation.
This commit is contained in:
Rebecca Law
2019-08-12 15:59:27 +01:00
parent 6ea849298e
commit 12f305bf86
5 changed files with 46 additions and 12 deletions

View File

@@ -175,6 +175,7 @@ def test_add_service_to_organisation(sample_service, sample_organisation):
id=sample_service.id,
version=2
).one().organisation_type == sample_organisation.organisation_type
assert sample_service.organisation_id == sample_organisation.id
def test_add_service_to_multiple_organisation_raises_error(sample_service, sample_organisation):

View File

@@ -107,6 +107,35 @@ def test_create_service(notify_db_session):
assert service_db.organisation_type == 'central'
assert service_db.crown is None
assert not service.letter_branding
assert not service.organisation_id
def test_create_service_with_organisation(notify_db_session):
user = create_user(email='local.authority@local-authority.gov.uk')
organisation = create_organisation(
name='Some local authority', organisation_type='local', domains=['local-authority.gov.uk'])
assert Service.query.count() == 0
service = Service(name="service_name",
email_from="email_from",
message_limit=1000,
restricted=False,
organisation_type='central',
created_by=user)
dao_create_service(service, user)
assert Service.query.count() == 1
service_db = Service.query.one()
assert service_db.name == "service_name"
assert service_db.id == service.id
assert service_db.email_from == 'email_from'
assert service_db.research_mode is False
assert service_db.prefix_sms is True
assert service.active is True
assert user in service_db.users
assert service_db.organisation_type == 'local'
assert service_db.crown is None
assert not service.letter_branding
assert service.organisation_id == organisation.id
assert service.organisation == organisation
@pytest.mark.parametrize('email_address, organisation_type', (