mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-11 10:28:55 -04:00
reformat
This commit is contained in:
@@ -27,13 +27,13 @@ from tests.app.db import (
|
||||
|
||||
|
||||
def test_get_organizations_gets_all_organizations_alphabetically_with_active_organizations_first(
|
||||
notify_db_session
|
||||
notify_db_session,
|
||||
):
|
||||
m_active_org = create_organization(name='m_active_organization')
|
||||
z_inactive_org = create_organization(name='z_inactive_organization', active=False)
|
||||
a_inactive_org = create_organization(name='a_inactive_organization', active=False)
|
||||
z_active_org = create_organization(name='z_active_organization')
|
||||
a_active_org = create_organization(name='a_active_organization')
|
||||
m_active_org = create_organization(name="m_active_organization")
|
||||
z_inactive_org = create_organization(name="z_inactive_organization", active=False)
|
||||
a_inactive_org = create_organization(name="a_inactive_organization", active=False)
|
||||
z_active_org = create_organization(name="z_active_organization")
|
||||
a_active_org = create_organization(name="a_active_organization")
|
||||
|
||||
organizations = dao_get_organizations()
|
||||
|
||||
@@ -61,8 +61,8 @@ def test_update_organization(notify_db_session):
|
||||
email_branding = create_email_branding()
|
||||
|
||||
data = {
|
||||
'name': 'new name',
|
||||
"organization_type": 'state',
|
||||
"name": "new name",
|
||||
"organization_type": "state",
|
||||
"agreement_signed": True,
|
||||
"agreement_signed_at": datetime.datetime.utcnow(),
|
||||
"agreement_signed_by_id": user.id,
|
||||
@@ -85,12 +85,15 @@ def test_update_organization(notify_db_session):
|
||||
assert organization.updated_at
|
||||
|
||||
|
||||
@pytest.mark.parametrize('domain_list, expected_domains', (
|
||||
(['abc', 'def'], {'abc', 'def'}),
|
||||
(['ABC', 'DEF'], {'abc', 'def'}),
|
||||
([], set()),
|
||||
(None, {'123', '456'}),
|
||||
))
|
||||
@pytest.mark.parametrize(
|
||||
"domain_list, expected_domains",
|
||||
(
|
||||
(["abc", "def"], {"abc", "def"}),
|
||||
(["ABC", "DEF"], {"abc", "def"}),
|
||||
([], set()),
|
||||
(None, {"123", "456"}),
|
||||
),
|
||||
)
|
||||
def test_update_organization_domains_lowercases(
|
||||
notify_db_session,
|
||||
domain_list,
|
||||
@@ -101,7 +104,7 @@ def test_update_organization_domains_lowercases(
|
||||
organization = Organization.query.one()
|
||||
|
||||
# Seed some domains
|
||||
dao_update_organization(organization.id, domains=['123', '456'])
|
||||
dao_update_organization(organization.id, domains=["123", "456"])
|
||||
|
||||
# This should overwrite the seeded domains
|
||||
dao_update_organization(organization.id, domains=domain_list)
|
||||
@@ -109,9 +112,7 @@ def test_update_organization_domains_lowercases(
|
||||
assert {domain.domain for domain in organization.domains} == expected_domains
|
||||
|
||||
|
||||
@pytest.mark.parametrize('domain_list, expected_domains', (
|
||||
(['abc', 'ABC'], {'abc'}),
|
||||
))
|
||||
@pytest.mark.parametrize("domain_list, expected_domains", ((["abc", "ABC"], {"abc"}),))
|
||||
def test_update_organization_domains_lowercases_integrity_error(
|
||||
notify_db_session,
|
||||
domain_list,
|
||||
@@ -122,10 +123,9 @@ def test_update_organization_domains_lowercases_integrity_error(
|
||||
organization = Organization.query.one()
|
||||
|
||||
# Seed some domains
|
||||
dao_update_organization(organization.id, domains=['123', '456'])
|
||||
dao_update_organization(organization.id, domains=["123", "456"])
|
||||
|
||||
with pytest.raises(expected_exception=IntegrityError):
|
||||
|
||||
# This should overwrite the seeded domains
|
||||
dao_update_organization(organization.id, domains=domain_list)
|
||||
|
||||
@@ -138,21 +138,21 @@ def test_update_organization_does_not_update_the_service_if_certain_attributes_n
|
||||
):
|
||||
email_branding = create_email_branding()
|
||||
|
||||
sample_service.organization_type = 'state'
|
||||
sample_organization.organization_type = 'federal'
|
||||
sample_service.organization_type = "state"
|
||||
sample_organization.organization_type = "federal"
|
||||
sample_organization.email_branding = email_branding
|
||||
|
||||
sample_organization.services.append(sample_service)
|
||||
db.session.commit()
|
||||
|
||||
assert sample_organization.name == 'sample organization'
|
||||
assert sample_organization.name == "sample organization"
|
||||
|
||||
dao_update_organization(sample_organization.id, name='updated org name')
|
||||
dao_update_organization(sample_organization.id, name="updated org name")
|
||||
|
||||
assert sample_organization.name == 'updated org name'
|
||||
assert sample_organization.name == "updated org name"
|
||||
|
||||
assert sample_organization.organization_type == 'federal'
|
||||
assert sample_service.organization_type == 'state'
|
||||
assert sample_organization.organization_type == "federal"
|
||||
assert sample_service.organization_type == "state"
|
||||
|
||||
assert sample_organization.email_branding == email_branding
|
||||
assert sample_service.email_branding is None
|
||||
@@ -162,20 +162,23 @@ def test_update_organization_updates_the_service_org_type_if_org_type_is_provide
|
||||
sample_service,
|
||||
sample_organization,
|
||||
):
|
||||
sample_service.organization_type = 'state'
|
||||
sample_organization.organization_type = 'state'
|
||||
sample_service.organization_type = "state"
|
||||
sample_organization.organization_type = "state"
|
||||
|
||||
sample_organization.services.append(sample_service)
|
||||
db.session.commit()
|
||||
|
||||
dao_update_organization(sample_organization.id, organization_type='federal')
|
||||
dao_update_organization(sample_organization.id, organization_type="federal")
|
||||
|
||||
assert sample_organization.organization_type == 'federal'
|
||||
assert sample_service.organization_type == 'federal'
|
||||
assert Service.get_history_model().query.filter_by(
|
||||
id=sample_service.id,
|
||||
version=2
|
||||
).one().organization_type == 'federal'
|
||||
assert sample_organization.organization_type == "federal"
|
||||
assert sample_service.organization_type == "federal"
|
||||
assert (
|
||||
Service.get_history_model()
|
||||
.query.filter_by(id=sample_service.id, version=2)
|
||||
.one()
|
||||
.organization_type
|
||||
== "federal"
|
||||
)
|
||||
|
||||
|
||||
def test_update_organization_updates_the_service_branding_if_branding_is_provided(
|
||||
@@ -198,7 +201,7 @@ def test_update_organization_does_not_override_service_branding(
|
||||
sample_organization,
|
||||
):
|
||||
email_branding = create_email_branding()
|
||||
custom_email_branding = create_email_branding(name='custom')
|
||||
custom_email_branding = create_email_branding(name="custom")
|
||||
|
||||
sample_service.email_branding = custom_email_branding
|
||||
|
||||
@@ -223,15 +226,18 @@ def test_add_service_to_organization(sample_service, sample_organization):
|
||||
assert sample_organization.services[0].id == sample_service.id
|
||||
|
||||
assert sample_service.organization_type == sample_organization.organization_type
|
||||
assert Service.get_history_model().query.filter_by(
|
||||
id=sample_service.id,
|
||||
version=2
|
||||
).one().organization_type == sample_organization.organization_type
|
||||
assert (
|
||||
Service.get_history_model()
|
||||
.query.filter_by(id=sample_service.id, version=2)
|
||||
.one()
|
||||
.organization_type
|
||||
== sample_organization.organization_type
|
||||
)
|
||||
assert sample_service.organization_id == sample_organization.id
|
||||
|
||||
|
||||
def test_get_organization_services(sample_service, sample_organization):
|
||||
another_service = create_service(service_name='service 2')
|
||||
another_service = create_service(service_name="service 2")
|
||||
another_org = create_organization()
|
||||
|
||||
dao_add_service_to_organization(sample_service, sample_organization.id)
|
||||
@@ -240,12 +246,14 @@ def test_get_organization_services(sample_service, sample_organization):
|
||||
org_services = dao_get_organization_services(sample_organization.id)
|
||||
other_org_services = dao_get_organization_services(another_org.id)
|
||||
|
||||
assert [sample_service.name, another_service.name] == sorted([s.name for s in org_services])
|
||||
assert [sample_service.name, another_service.name] == sorted(
|
||||
[s.name for s in org_services]
|
||||
)
|
||||
assert not other_org_services
|
||||
|
||||
|
||||
def test_get_organization_by_service_id(sample_service, sample_organization):
|
||||
another_service = create_service(service_name='service 2')
|
||||
another_service = create_service(service_name="service 2")
|
||||
another_org = create_organization()
|
||||
|
||||
dao_add_service_to_organization(sample_service, sample_organization.id)
|
||||
@@ -259,11 +267,15 @@ def test_get_organization_by_service_id(sample_service, sample_organization):
|
||||
|
||||
|
||||
def test_dao_get_users_for_organization(sample_organization):
|
||||
first = create_user(email='first@invited.com')
|
||||
second = create_user(email='another@invited.com')
|
||||
first = create_user(email="first@invited.com")
|
||||
second = create_user(email="another@invited.com")
|
||||
|
||||
dao_add_user_to_organization(organization_id=sample_organization.id, user_id=first.id)
|
||||
dao_add_user_to_organization(organization_id=sample_organization.id, user_id=second.id)
|
||||
dao_add_user_to_organization(
|
||||
organization_id=sample_organization.id, user_id=first.id
|
||||
)
|
||||
dao_add_user_to_organization(
|
||||
organization_id=sample_organization.id, user_id=second.id
|
||||
)
|
||||
|
||||
results = dao_get_users_for_organization(organization_id=sample_organization.id)
|
||||
|
||||
@@ -278,13 +290,17 @@ def test_dao_get_users_for_organization_returns_empty_list(sample_organization):
|
||||
|
||||
|
||||
def test_dao_get_users_for_organization_only_returns_active_users(sample_organization):
|
||||
first = create_user(email='first@invited.com')
|
||||
second = create_user(email='another@invited.com')
|
||||
first = create_user(email="first@invited.com")
|
||||
second = create_user(email="another@invited.com")
|
||||
|
||||
dao_add_user_to_organization(organization_id=sample_organization.id, user_id=first.id)
|
||||
dao_add_user_to_organization(organization_id=sample_organization.id, user_id=second.id)
|
||||
dao_add_user_to_organization(
|
||||
organization_id=sample_organization.id, user_id=first.id
|
||||
)
|
||||
dao_add_user_to_organization(
|
||||
organization_id=sample_organization.id, user_id=second.id
|
||||
)
|
||||
|
||||
second.state = 'inactive'
|
||||
second.state = "inactive"
|
||||
|
||||
results = dao_get_users_for_organization(organization_id=sample_organization.id)
|
||||
assert len(results) == 1
|
||||
@@ -295,40 +311,44 @@ def test_add_user_to_organization_returns_user(sample_organization):
|
||||
org_user = create_user()
|
||||
assert not org_user.organizations
|
||||
|
||||
added_user = dao_add_user_to_organization(organization_id=sample_organization.id, user_id=org_user.id)
|
||||
added_user = dao_add_user_to_organization(
|
||||
organization_id=sample_organization.id, user_id=org_user.id
|
||||
)
|
||||
assert len(added_user.organizations) == 1
|
||||
assert added_user.organizations[0] == sample_organization
|
||||
|
||||
|
||||
def test_add_user_to_organization_when_user_does_not_exist(sample_organization):
|
||||
with pytest.raises(expected_exception=SQLAlchemyError):
|
||||
dao_add_user_to_organization(organization_id=sample_organization.id, user_id=uuid.uuid4())
|
||||
dao_add_user_to_organization(
|
||||
organization_id=sample_organization.id, user_id=uuid.uuid4()
|
||||
)
|
||||
|
||||
|
||||
def test_add_user_to_organization_when_organization_does_not_exist(sample_user):
|
||||
with pytest.raises(expected_exception=SQLAlchemyError):
|
||||
dao_add_user_to_organization(organization_id=uuid.uuid4(), user_id=sample_user.id)
|
||||
dao_add_user_to_organization(
|
||||
organization_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_organization_by_email_address(
|
||||
domain,
|
||||
expected_org,
|
||||
notify_db_session
|
||||
):
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"domain, expected_org",
|
||||
(
|
||||
("unknown.gov.uk", False),
|
||||
("example.gov.uk", True),
|
||||
),
|
||||
)
|
||||
def test_get_organization_by_email_address(domain, expected_org, notify_db_session):
|
||||
org = create_organization()
|
||||
create_domain('example.gov.uk', org.id)
|
||||
create_domain('test.gov.uk', org.id)
|
||||
create_domain("example.gov.uk", org.id)
|
||||
create_domain("test.gov.uk", org.id)
|
||||
|
||||
another_org = create_organization(name='Another')
|
||||
create_domain('cabinet-office.gov.uk', another_org.id)
|
||||
create_domain('cabinetoffice.gov.uk', another_org.id)
|
||||
another_org = create_organization(name="Another")
|
||||
create_domain("cabinet-office.gov.uk", another_org.id)
|
||||
create_domain("cabinetoffice.gov.uk", another_org.id)
|
||||
|
||||
found_org = dao_get_organization_by_email_address('test@{}'.format(domain))
|
||||
found_org = dao_get_organization_by_email_address("test@{}".format(domain))
|
||||
|
||||
if expected_org:
|
||||
assert found_org is org
|
||||
@@ -338,7 +358,9 @@ def test_get_organization_by_email_address(
|
||||
|
||||
def test_get_organization_by_email_address_ignores_gsi_gov_uk(notify_db_session):
|
||||
org = create_organization()
|
||||
create_domain('example.gov.uk', org.id)
|
||||
create_domain("example.gov.uk", org.id)
|
||||
|
||||
found_org = dao_get_organization_by_email_address('test_gsi_address@example.gsi.gov.uk')
|
||||
found_org = dao_get_organization_by_email_address(
|
||||
"test_gsi_address@example.gsi.gov.uk"
|
||||
)
|
||||
assert org == found_org
|
||||
|
||||
Reference in New Issue
Block a user