Storing more info about an organisation

Currently we have
- a thing in the database called an ‘organisation’ which we don’t use
- the idea of an organisation which we derive from the user’s email
  address and is used to set the default branding for their service and
  determine whether they’ve signed the MOU

We should make these two things into one thing, by storing everything
we know about an organisation against that organisation in the database.
This will be much less laborious than storing it in a YAML file that
needs a deploy every time it’s updated.

An organisation can now have:
- domains which we can use to automatically associate services with it
  (eg anyone whose email address ends in `dwp.gsi.gov.uk` gets services
  they create associated to the DWP organisation)
- default letter branding for any new services
- default email branding for any new services
This commit is contained in:
Chris Hill-Scott
2019-02-19 11:47:30 +00:00
parent 46abcfd96d
commit d7e03e00d3
5 changed files with 221 additions and 13 deletions

View File

@@ -1,3 +1,4 @@
import datetime
import uuid
import pytest
@@ -16,7 +17,13 @@ from app.dao.organisation_dao import (
)
from app.models import Organisation
from tests.app.db import create_organisation, create_service, create_user
from tests.app.db import (
create_email_branding,
create_letter_branding,
create_organisation,
create_service,
create_user,
)
def test_get_organisations_gets_all_organisations_alphabetically_with_active_organisations_first(
@@ -47,19 +54,38 @@ def test_get_organisation_by_id_gets_correct_organisation(notify_db, notify_db_s
assert organisation_from_db == organisation
def test_update_organisation(notify_db, notify_db_session):
updated_name = 'new name'
def test_update_organisation(
notify_db,
notify_db_session,
):
create_organisation()
organisation = Organisation.query.one()
user = create_user()
email_branding = create_email_branding()
letter_branding = create_letter_branding()
assert organisation.name != updated_name
data = {
'name': 'new name',
"crown": True,
"organisation_type": 'local',
"agreement_signed": True,
"agreement_signed_at": datetime.datetime.utcnow(),
"agreement_signed_by_id": user.id,
"agreement_signed_version": 999.99,
"letter_branding_id": letter_branding.id,
"email_branding_id": email_branding.id,
}
dao_update_organisation(organisation.id, **{'name': updated_name})
for attribute, value in data.items():
assert getattr(organisation, attribute) != value
dao_update_organisation(organisation.id, **data)
organisation = Organisation.query.one()
assert organisation.name == updated_name
for attribute, value in data.items():
assert getattr(organisation, attribute) == value
def test_add_service_to_organisation(notify_db, notify_db_session, sample_service, sample_organisation):

View File

@@ -32,10 +32,29 @@ def test_get_organisation_by_id(admin_request, notify_db_session):
organisation_id=org.id
)
assert set(response.keys()) == {'id', 'name', 'active'}
assert set(response.keys()) == {
'id',
'name',
'active',
'crown',
'organisation_type',
'agreement_signed',
'agreement_signed_at',
'agreement_signed_by_id',
'agreement_signed_version',
'letter_branding_id',
'email_branding_id',
}
assert response['id'] == str(org.id)
assert response['name'] == 'test_org_1'
assert response['active'] is True
assert response['crown'] is None
assert response['organisation_type'] is None
assert response['agreement_signed'] is None
assert response['agreement_signed_by_id'] is None
assert response['agreement_signed_version'] is None
assert response['letter_branding_id'] is None
assert response['email_branding_id'] is None
def test_post_create_organisation(admin_request, notify_db_session):
@@ -91,12 +110,27 @@ def test_post_create_organisation_with_missing_name_gives_validation_error(admin
assert response['errors'][0]['message'] == 'name is a required property'
def test_post_update_organisation_updates_fields(admin_request, notify_db_session):
@pytest.mark.parametrize('agreement_signed', (
None, True, False
))
@pytest.mark.parametrize('crown', (
None, True, False
))
def test_post_update_organisation_updates_fields(
admin_request,
notify_db_session,
agreement_signed,
crown,
):
org = create_organisation()
data = {
'name': 'new organisation name',
'active': False
'active': False,
'agreement_signed': agreement_signed,
'crown': crown,
}
assert org.agreement_signed is None
assert org.crown is None
admin_request.post(
'organisation.update_organisation',
@@ -111,6 +145,39 @@ def test_post_update_organisation_updates_fields(admin_request, notify_db_sessio
assert organisation[0].id == org.id
assert organisation[0].name == data['name']
assert organisation[0].active == data['active']
assert organisation[0].agreement_signed == agreement_signed
assert organisation[0].crown == crown
assert organisation[0].domains == []
@pytest.mark.parametrize('domain_list', (
['example.com'],
['example.com', 'example.org', 'example.net'],
[],
))
def test_post_update_organisation_updates_domains(
admin_request,
notify_db_session,
domain_list,
):
org = create_organisation(name='test_org_2')
data = {
'domains': domain_list,
}
admin_request.post(
'organisation.update_organisation',
_data=data,
organisation_id=org.id,
_expected_status=204
)
organisation = Organisation.query.all()
assert len(organisation) == 1
assert [
domain.domain for domain in organisation[0].domains
] == domain_list
def test_post_update_organisation_raises_400_on_existing_org_name(