From 085110417f253fe084b3c2c4759c3294fbfb34b9 Mon Sep 17 00:00:00 2001 From: Ken Tsang Date: Mon, 12 Feb 2018 18:26:51 +0000 Subject: [PATCH] Refactor organisation_dao --- app/dao/organisation_dao.py | 4 ++-- tests/app/dao/test_organisation_dao.py | 8 +++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/app/dao/organisation_dao.py b/app/dao/organisation_dao.py index 6082ae376..50de10b07 100644 --- a/app/dao/organisation_dao.py +++ b/app/dao/organisation_dao.py @@ -1,6 +1,6 @@ from app import db from app.dao.dao_utils import transactional -from app.models import Organisation, Service +from app.models import Organisation def dao_get_organisations(): @@ -20,7 +20,7 @@ def dao_get_organisation_by_id(organisation_id): def dao_get_organisation_by_service_id(service_id): - return Organisation.query.join(Organisation.services).filter(Service.id == service_id).first() + return Organisation.query.join(Organisation.services).filter_by(id=service_id).first() @transactional diff --git a/tests/app/dao/test_organisation_dao.py b/tests/app/dao/test_organisation_dao.py index 610d71ed5..ce1256c62 100644 --- a/tests/app/dao/test_organisation_dao.py +++ b/tests/app/dao/test_organisation_dao.py @@ -85,9 +85,7 @@ def test_get_organisation_services(notify_db, notify_db_session, sample_service, org_services = dao_get_organisation_services(sample_organisation.id) other_org_services = dao_get_organisation_services(another_org.id) - assert len(org_services) == 2 - assert org_services[0].name == sample_service.name - assert org_services[1].name == another_service.name + assert [sample_service.name, another_service.name] == sorted([s.name for s in org_services]) assert not other_org_services @@ -98,8 +96,8 @@ def test_get_organisation_by_service_id(notify_db, notify_db_session, sample_ser dao_add_service_to_organisation(sample_service, sample_organisation.id) dao_add_service_to_organisation(another_service, another_org.id) - organisation_1 = dao_get_organisation_by_service_id(str(sample_service.id)) - organisation_2 = dao_get_organisation_by_service_id(str(another_service.id)) + organisation_1 = dao_get_organisation_by_service_id(sample_service.id) + organisation_2 = dao_get_organisation_by_service_id(another_service.id) assert organisation_1 == sample_organisation assert organisation_2 == another_org