Add organisation_id to Service.

This is the second commit in the series to add organisation_id to Service.
- Data migration to update services.organisation_id from data in organisation_to_service
 (The rollback will lose any updates to organisation unless the script is updated to set organistion_to_service from service.organisation_id )
- Update Service.organisation relationship to a ForeignKey relationship to Organisation.
- Update Organisation.services to a backref relationship to Service.
This commit is contained in:
Rebecca Law
2019-08-13 17:25:30 +01:00
parent 515d6602c1
commit 55dc7184cc
6 changed files with 36 additions and 20 deletions

View File

@@ -178,17 +178,6 @@ def test_add_service_to_organisation(sample_service, sample_organisation):
assert sample_service.organisation_id == sample_organisation.id
def test_add_service_to_multiple_organisation_raises_error(sample_service, sample_organisation):
another_org = create_organisation()
dao_add_service_to_organisation(sample_service, sample_organisation.id)
with pytest.raises(IntegrityError):
dao_add_service_to_organisation(sample_service, another_org.id)
assert len(sample_organisation.services) == 1
assert sample_organisation.services[0] == sample_service
def test_get_organisation_services(sample_service, sample_organisation):
another_service = create_service(service_name='service 2')
another_org = create_organisation()

View File

@@ -58,6 +58,7 @@ from app.models import (
INTERNATIONAL_SMS_TYPE,
LETTER_TYPE,
user_folder_permissions,
Organisation
)
from tests.app.db import (
create_ft_billing,
@@ -124,6 +125,7 @@ def test_create_service_with_organisation(notify_db_session):
dao_create_service(service, user)
assert Service.query.count() == 1
service_db = Service.query.one()
organisation = Organisation.query.get(organisation.id)
assert service_db.name == "service_name"
assert service_db.id == service.id
assert service_db.email_from == 'email_from'