2017-07-04 17:02:28 +01:00
|
|
|
import pytest
|
2017-07-06 10:58:48 +01:00
|
|
|
from sqlalchemy.exc import IntegrityError
|
2017-07-04 17:02:28 +01:00
|
|
|
|
2017-07-05 11:17:03 +01:00
|
|
|
from app.dao.organisations_dao import (
|
2017-07-06 10:58:48 +01:00
|
|
|
dao_create_organisation,
|
|
|
|
|
dao_get_organisations,
|
2017-07-11 18:18:23 +01:00
|
|
|
dao_get_organisation_by_id,
|
|
|
|
|
dao_update_organisation,
|
2017-07-05 11:17:03 +01:00
|
|
|
)
|
2017-07-04 17:02:28 +01:00
|
|
|
from app.models import Organisation
|
|
|
|
|
|
|
|
|
|
from tests.app.db import create_organisation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_create_organisation(notify_db, notify_db_session):
|
|
|
|
|
organisation = create_organisation()
|
|
|
|
|
|
|
|
|
|
assert Organisation.query.count() == 1
|
|
|
|
|
organisation_from_db = Organisation.query.first()
|
|
|
|
|
assert organisation == organisation_from_db
|
2017-07-05 11:17:03 +01:00
|
|
|
|
|
|
|
|
|
2017-07-06 10:58:48 +01:00
|
|
|
def test_create_organisation_without_name_or_colour_is_valid(notify_db, notify_db_session):
|
2017-09-20 11:03:48 +01:00
|
|
|
organisation = create_organisation(logo=None, name=None, colour=None)
|
2017-07-06 10:58:48 +01:00
|
|
|
|
|
|
|
|
assert Organisation.query.count() == 1
|
|
|
|
|
organisation_from_db = Organisation.query.first()
|
|
|
|
|
assert organisation == organisation_from_db
|
|
|
|
|
|
|
|
|
|
|
2017-07-05 11:17:03 +01:00
|
|
|
def test_get_organisations_gets_all_organisations(notify_db, notify_db_session):
|
2017-07-07 14:48:00 +01:00
|
|
|
org_1 = create_organisation(name='test_org_1')
|
|
|
|
|
org_2 = create_organisation(name='test_org_2')
|
2017-07-05 11:17:03 +01:00
|
|
|
|
|
|
|
|
organisations = dao_get_organisations()
|
|
|
|
|
|
|
|
|
|
assert len(organisations) == 2
|
2017-07-07 14:48:00 +01:00
|
|
|
assert org_1 == organisations[0]
|
|
|
|
|
assert org_2 == organisations[1]
|
2017-07-05 11:17:03 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_organisation_by_id_gets_correct_organisation(notify_db, notify_db_session):
|
|
|
|
|
organisation = create_organisation()
|
|
|
|
|
|
|
|
|
|
organisation_from_db = dao_get_organisation_by_id(organisation.id)
|
|
|
|
|
|
|
|
|
|
assert organisation_from_db == organisation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_update_organisation(notify_db, notify_db_session):
|
|
|
|
|
updated_name = 'new name'
|
|
|
|
|
organisation = create_organisation()
|
|
|
|
|
|
2017-07-11 18:18:23 +01:00
|
|
|
organisations_1 = Organisation.query.all()
|
|
|
|
|
|
|
|
|
|
assert len(organisations_1) == 1
|
|
|
|
|
assert organisations_1[0].name != updated_name
|
2017-07-05 11:17:03 +01:00
|
|
|
|
2017-07-11 18:18:23 +01:00
|
|
|
dao_update_organisation(organisations_1[0], name=updated_name)
|
2017-07-05 11:17:03 +01:00
|
|
|
|
2017-07-11 18:18:23 +01:00
|
|
|
organisations_2 = Organisation.query.all()
|
2017-07-05 11:17:03 +01:00
|
|
|
|
2017-07-11 18:18:23 +01:00
|
|
|
assert len(organisations_2) == 1
|
|
|
|
|
assert organisations_2[0].name == updated_name
|