def test_update_organisation_does_not_override_service_branding( sample_service, sample_organisation, ): email_branding = create_email_branding() custom_email_branding = create_email_branding(name='custom') letter_branding = create_letter_branding() custom_letter_branding = create_letter_branding(name='custom', filename='custom') sample_service.email_branding = custom_email_branding sample_service.letter_branding = custom_letter_branding sample_organisation.services.append(sample_service) db.session.commit() dao_update_organisation(sample_organisation.id, email_branding_id=email_branding.id) dao_update_organisation(sample_organisation.id, letter_branding_id=letter_branding.id) assert sample_organisation.email_branding == email_branding assert sample_organisation.letter_branding == letter_branding assert sample_service.email_branding == custom_email_branding assert sample_service.letter_branding == custom_letter_branding
def test_update_organisation(notify_db_session): create_organisation() organisation = Organisation.query.one() user = create_user() email_branding = create_email_branding() letter_branding = create_letter_branding() 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, } for attribute, value in data.items(): assert getattr(organisation, attribute) != value assert organisation.updated_at is None dao_update_organisation(organisation.id, **data) organisation = Organisation.query.one() for attribute, value in data.items(): assert getattr(organisation, attribute) == value assert organisation.updated_at
def test_update_organisation_does_not_update_the_service_if_certain_attributes_not_provided( sample_service, sample_organisation, ): email_branding = create_email_branding() letter_branding = create_letter_branding() sample_service.organisation_type = 'local' sample_organisation.organisation_type = 'central' sample_organisation.email_branding = email_branding sample_organisation.letter_branding = letter_branding sample_organisation.services.append(sample_service) db.session.commit() assert sample_organisation.name == 'sample organisation' dao_update_organisation(sample_organisation.id, name='updated org name') assert sample_organisation.name == 'updated org name' assert sample_organisation.organisation_type == 'central' assert sample_service.organisation_type == 'local' assert sample_organisation.email_branding == email_branding assert sample_service.email_branding is None assert sample_organisation.letter_branding == letter_branding assert sample_service.letter_branding is None
def test_update_organisation_updates_services_with_new_crown_type( sample_service, sample_organisation): sample_organisation.services.append(sample_service) db.session.commit() assert Service.query.get(sample_service.id).crown dao_update_organisation(sample_organisation.id, crown=False) assert not Service.query.get(sample_service.id).crown
def test_update_organisation(notify_db, notify_db_session): updated_name = 'new name' create_organisation() organisation = Organisation.query.one() assert organisation.name != updated_name dao_update_organisation(organisation.id, **{'name': updated_name}) organisation = Organisation.query.one() assert organisation.name == updated_name
def test_update_organisation_updates_the_service_org_type_if_org_type_is_provided( setup_service, sample_organisation, setup_org_type): setup_service.organisation_type = setup_org_type.name sample_organisation.organisation_type = setup_org_type.name sample_organisation.services.append(setup_service) db.session.commit() dao_update_organisation(sample_organisation.id, organisation_type='other') assert sample_organisation.organisation_type == 'other' assert setup_service.organisation_type == 'other' assert Service.get_history_model().query.filter_by( id=setup_service.id, version=2).one().organisation_type == 'other'
def test_update_organisation_does_not_update_the_service_org_type_if_org_type_is_not_provided( sample_service, sample_organisation, ): sample_service.organisation_type = 'local' sample_organisation.organisation_type = 'central' sample_organisation.services.append(sample_service) db.session.commit() assert sample_organisation.name == 'sample organisation' dao_update_organisation(sample_organisation.id, name='updated org name') assert sample_organisation.name == 'updated org name' assert sample_service.organisation_type == 'local'
def test_update_organisation_does_not_update_the_service_org_type_if_org_type_is_not_provided( sample_service, sample_organisation, ): sample_service.organisation_type = "local" sample_organisation.organisation_type = "central" sample_organisation.services.append(sample_service) db.session.commit() assert sample_organisation.name == "sample organisation" dao_update_organisation(sample_organisation.id, name="updated org name") assert sample_organisation.name == "updated org name" assert sample_service.organisation_type == "local"
def test_update_organisation_domains_lowercases( notify_db_session, domain_list, expected_domains, ): create_organisation() organisation = Organisation.query.one() # Seed some domains dao_update_organisation(organisation.id, domains=['123', '456']) # This should overwrite the seeded domains dao_update_organisation(organisation.id, domains=domain_list) assert {domain.domain for domain in organisation.domains} == expected_domains
def test_update_organisation_updates_the_service_org_type_if_org_type_is_provided( sample_service, sample_organisation, ): sample_service.organisation_type = 'local' sample_organisation.organisation_type = 'local' sample_organisation.services.append(sample_service) db.session.commit() dao_update_organisation(sample_organisation.id, organisation_type='central') assert sample_organisation.organisation_type == 'central' assert sample_service.organisation_type == 'central' assert Service.get_history_model().query.filter_by( id=sample_service.id, version=2).one().organisation_type == 'central'
def test_update_organisation_updates_the_service_branding_if_branding_is_provided( sample_service, sample_organisation, ): email_branding = create_email_branding() letter_branding = create_letter_branding() sample_organisation.services.append(sample_service) db.session.commit() dao_update_organisation(sample_organisation.id, email_branding_id=email_branding.id) dao_update_organisation(sample_organisation.id, letter_branding_id=letter_branding.id) assert sample_organisation.email_branding == email_branding assert sample_organisation.letter_branding == letter_branding assert sample_service.email_branding == email_branding assert sample_service.letter_branding == letter_branding
def update_organisation(organisation_id): data = request.get_json() validate(data, post_update_organisation_schema) result = dao_update_organisation(organisation_id, **data) if result: return '', 204 else: raise InvalidRequest("Organisation not found", 404)
def update_organisation(organisation_id): data = request.get_json() validate(data, post_update_organisation_schema) result = dao_update_organisation(organisation_id, **data) if data.get("agreement_signed") is True: # if a platform admin has manually adjusted the organisation, don't tell people if data.get("agreement_signed_by_id"): send_notifications_on_mou_signed(organisation_id) if result: return "", 204 else: raise InvalidRequest("Organisation not found", 404)