mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-20 14:29:25 -04:00
Automatically associate new service with an org
This is the same thing we do in the admin app at the moment with YAML:
2f4e933b65/app/utils.py (L556-L562)
This commit is contained in:
@@ -6,6 +6,7 @@ from sqlalchemy.exc import IntegrityError, SQLAlchemyError
|
||||
|
||||
from app.dao.organisation_dao import (
|
||||
dao_get_organisations,
|
||||
dao_get_organisation_by_email_address,
|
||||
dao_get_organisation_by_id,
|
||||
dao_get_organisation_by_service_id,
|
||||
dao_get_organisation_services,
|
||||
@@ -18,6 +19,7 @@ from app.dao.organisation_dao import (
|
||||
from app.models import Organisation
|
||||
|
||||
from tests.app.db import (
|
||||
create_domain,
|
||||
create_email_branding,
|
||||
create_letter_branding,
|
||||
create_organisation,
|
||||
@@ -197,3 +199,30 @@ def test_add_user_to_organisation_when_user_does_not_exist(sample_organisation):
|
||||
def test_add_user_to_organisation_when_organisation_does_not_exist(sample_user):
|
||||
with pytest.raises(expected_exception=SQLAlchemyError):
|
||||
dao_add_user_to_organisation(organisation_id=uuid.uuid4(), user_id=sample_user.id)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('domain, expected_org', (
|
||||
('unknown.gov.uk', False),
|
||||
('example.gov.uk', True),
|
||||
))
|
||||
def test_get_organisation_by_email_address(
|
||||
admin_request,
|
||||
sample_user,
|
||||
domain,
|
||||
expected_org,
|
||||
):
|
||||
|
||||
org = create_organisation()
|
||||
create_domain('example.gov.uk', org.id)
|
||||
create_domain('test.gov.uk', org.id)
|
||||
|
||||
another_org = create_organisation(name='Another')
|
||||
create_domain('cabinet-office.gov.uk', another_org.id)
|
||||
create_domain('cabinetoffice.gov.uk', another_org.id)
|
||||
|
||||
found_org = dao_get_organisation_by_email_address('test@{}'.format(domain))
|
||||
|
||||
if expected_org:
|
||||
assert found_org is org
|
||||
else:
|
||||
assert found_org is None
|
||||
|
||||
@@ -4,7 +4,7 @@ from datetime import datetime
|
||||
import pytest
|
||||
from freezegun import freeze_time
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
from sqlalchemy.orm.exc import FlushError, NoResultFound
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
|
||||
from app import db
|
||||
from app.dao.inbound_numbers_dao import (
|
||||
@@ -167,9 +167,9 @@ def test_cannot_create_service_with_no_user(notify_db_session):
|
||||
message_limit=1000,
|
||||
restricted=False,
|
||||
created_by=user)
|
||||
with pytest.raises(FlushError) as excinfo:
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
dao_create_service(service, None)
|
||||
assert "Can't flush None value found in collection Service.users" in str(excinfo.value)
|
||||
assert "Can't create a service without a user" in str(excinfo.value)
|
||||
|
||||
|
||||
def test_should_add_user_to_service(notify_db_session):
|
||||
|
||||
Reference in New Issue
Block a user