notify-api-332 rename organisation

This commit is contained in:
Kenneth Kehl
2023-07-10 11:06:29 -07:00
parent 8be3864d7a
commit 4940d5e93b
42 changed files with 1301 additions and 1274 deletions

View File

@@ -61,7 +61,7 @@ def test_dao_update_annual_billing_for_future_years(notify_db_session, sample_se
])
def test_set_default_free_allowance_for_service(notify_db_session, org_type, year, expected_default):
service = create_service(organisation_type=org_type)
service = create_service(organization_type=org_type)
set_default_free_allowance_for_service(service=service, year_start=year)
@@ -88,12 +88,12 @@ def test_set_default_free_allowance_for_service_using_correct_year(sample_servic
def test_set_default_free_allowance_for_service_updates_existing_year(sample_service):
set_default_free_allowance_for_service(service=sample_service, year_start=None)
annual_billing = AnnualBilling.query.all()
assert not sample_service.organisation_type
assert not sample_service.organization_type
assert len(annual_billing) == 1
assert annual_billing[0].service_id == sample_service.id
assert annual_billing[0].free_sms_fragment_limit == 150000
sample_service.organisation_type = 'federal'
sample_service.organization_type = 'federal'
set_default_free_allowance_for_service(service=sample_service, year_start=None)
annual_billing = AnnualBilling.query.all()

View File

@@ -14,20 +14,20 @@ from app.dao.fact_billing_dao import (
fetch_monthly_billing_for_year,
fetch_sms_billing_for_all_services,
fetch_sms_free_allowance_remainder_until_date,
fetch_usage_year_for_organisation,
fetch_usage_year_for_organization,
fetch_volumes_by_service,
get_rate,
get_rates_for_billing,
query_organisation_sms_usage_for_year,
query_organization_sms_usage_for_year,
)
from app.dao.organisation_dao import dao_add_service_to_organisation
from app.dao.organization_dao import dao_add_service_to_organization
from app.models import NOTIFICATION_STATUS_TYPES, FactBilling
from tests.app.db import (
create_annual_billing,
create_ft_billing,
create_notification,
create_notification_history,
create_organisation,
create_organization,
create_rate,
create_service,
create_service_data_retention,
@@ -461,16 +461,16 @@ def test_delete_billing_data(notify_db_session):
def test_fetch_sms_free_allowance_remainder_until_date_with_two_services(notify_db_session):
service = create_service(service_name='has free allowance')
template = create_template(service=service)
org = create_organisation(name="Org for {}".format(service.name))
dao_add_service_to_organisation(service=service, organisation_id=org.id)
org = create_organization(name="Org for {}".format(service.name))
dao_add_service_to_organization(service=service, organization_id=org.id)
create_annual_billing(service_id=service.id, free_sms_fragment_limit=10, financial_year_start=2016)
create_ft_billing(template=template, local_date=datetime(2016, 4, 20), billable_unit=2, rate=0.11)
create_ft_billing(template=template, local_date=datetime(2016, 5, 20), billable_unit=3, rate=0.11)
service_2 = create_service(service_name='used free allowance')
template_2 = create_template(service=service_2)
org_2 = create_organisation(name="Org for {}".format(service_2.name))
dao_add_service_to_organisation(service=service_2, organisation_id=org_2.id)
org_2 = create_organization(name="Org for {}".format(service_2.name))
dao_add_service_to_organization(service=service_2, organization_id=org_2.id)
create_annual_billing(service_id=service_2.id, free_sms_fragment_limit=20, financial_year_start=2016)
create_ft_billing(template=template_2, local_date=datetime(2016, 4, 20), billable_unit=12, rate=0.11)
create_ft_billing(template=template_2, local_date=datetime(2016, 4, 22), billable_unit=10, rate=0.11)
@@ -488,8 +488,8 @@ def test_fetch_sms_billing_for_all_services_for_first_quarter(notify_db_session)
# This test is useful because the inner query resultset is empty.
service = create_service(service_name='a - has free allowance')
template = create_template(service=service)
org = create_organisation(name="Org for {}".format(service.name))
dao_add_service_to_organisation(service=service, organisation_id=org.id)
org = create_organization(name="Org for {}".format(service.name))
dao_add_service_to_organization(service=service, organization_id=org.id)
create_annual_billing(service_id=service.id, free_sms_fragment_limit=25000, financial_year_start=2019)
create_ft_billing(template=template, local_date=datetime(2019, 4, 20, 12), billable_unit=44, rate=0.11)
results = fetch_sms_billing_for_all_services(datetime(2019, 4, 1, 12), datetime(2019, 5, 30, 12))
@@ -501,8 +501,8 @@ def test_fetch_sms_billing_for_all_services_for_first_quarter(notify_db_session)
def test_fetch_sms_billing_for_all_services_with_remainder(notify_db_session):
service_1 = create_service(service_name='a - has free allowance')
template = create_template(service=service_1)
org = create_organisation(name="Org for {}".format(service_1.name))
dao_add_service_to_organisation(service=service_1, organisation_id=org.id)
org = create_organization(name="Org for {}".format(service_1.name))
dao_add_service_to_organization(service=service_1, organization_id=org.id)
create_annual_billing(service_id=service_1.id, free_sms_fragment_limit=10, financial_year_start=2019)
create_ft_billing(template=template, local_date=datetime(2019, 4, 20), billable_unit=2, rate=0.11)
create_ft_billing(template=template, local_date=datetime(2019, 5, 20), billable_unit=2, rate=0.11)
@@ -510,24 +510,24 @@ def test_fetch_sms_billing_for_all_services_with_remainder(notify_db_session):
service_2 = create_service(service_name='b - used free allowance')
template_2 = create_template(service=service_2)
org_2 = create_organisation(name="Org for {}".format(service_2.name))
dao_add_service_to_organisation(service=service_2, organisation_id=org_2.id)
org_2 = create_organization(name="Org for {}".format(service_2.name))
dao_add_service_to_organization(service=service_2, organization_id=org_2.id)
create_annual_billing(service_id=service_2.id, free_sms_fragment_limit=10, financial_year_start=2019)
create_ft_billing(template=template_2, local_date=datetime(2019, 4, 20), billable_unit=12, rate=0.11)
create_ft_billing(template=template_2, local_date=datetime(2019, 5, 20), billable_unit=3, rate=0.11)
service_3 = create_service(service_name='c - partial allowance')
template_3 = create_template(service=service_3)
org_3 = create_organisation(name="Org for {}".format(service_3.name))
dao_add_service_to_organisation(service=service_3, organisation_id=org_3.id)
org_3 = create_organization(name="Org for {}".format(service_3.name))
dao_add_service_to_organization(service=service_3, organization_id=org_3.id)
create_annual_billing(service_id=service_3.id, free_sms_fragment_limit=10, financial_year_start=2019)
create_ft_billing(template=template_3, local_date=datetime(2019, 4, 20), billable_unit=5, rate=0.11)
create_ft_billing(template=template_3, local_date=datetime(2019, 5, 20), billable_unit=7, rate=0.11)
service_4 = create_service(service_name='d - email only')
email_template = create_template(service=service_4, template_type='email')
org_4 = create_organisation(name="Org for {}".format(service_4.name))
dao_add_service_to_organisation(service=service_4, organisation_id=org_4.id)
org_4 = create_organization(name="Org for {}".format(service_4.name))
dao_add_service_to_organization(service=service_4, organization_id=org_4.id)
create_annual_billing(service_id=service_4.id, free_sms_fragment_limit=10, financial_year_start=2019)
create_ft_billing(template=email_template, local_date=datetime(2019, 5, 22), notifications_sent=5,
billable_unit=0, rate=0)
@@ -539,21 +539,21 @@ def test_fetch_sms_billing_for_all_services_with_remainder(notify_db_session):
# sms_remainder is 5, because "service_1" has 5 sms_billing_units. 2 of them for a period before
# the requested report's start date.
{
"organisation_name": org.name, "organisation_id": org.id, "service_name": service_1.name,
"organization_name": org.name, "organization_id": org.id, "service_name": service_1.name,
"service_id": service_1.id, "free_sms_fragment_limit": 10, "sms_rate": Decimal('0.11'), "sms_remainder": 5,
"sms_billable_units": 3, "chargeable_billable_sms": 0, "sms_cost": Decimal('0.00')
},
# sms remainder is 0, because this service sent SMS worth 15 billable units, 12 of which were sent
# before requested report's start date
{
"organisation_name": org_2.name, "organisation_id": org_2.id, "service_name": service_2.name,
"organization_name": org_2.name, "organization_id": org_2.id, "service_name": service_2.name,
"service_id": service_2.id, "free_sms_fragment_limit": 10, "sms_rate": Decimal('0.11'), "sms_remainder": 0,
"sms_billable_units": 3, "chargeable_billable_sms": 3, "sms_cost": Decimal('0.33')
},
# sms remainder is 0, because this service sent SMS worth 12 billable units, 5 of which were sent
# before requested report's start date
{
"organisation_name": org_3.name, "organisation_id": org_3.id, "service_name": service_3.name,
"organization_name": org_3.name, "organization_id": org_3.id, "service_name": service_3.name,
"service_id": service_3.id, "free_sms_fragment_limit": 10, "sms_rate": Decimal('0.11'), "sms_remainder": 0,
"sms_billable_units": 7, "chargeable_billable_sms": 2, "sms_cost": Decimal('0.22')
},
@@ -562,7 +562,7 @@ def test_fetch_sms_billing_for_all_services_with_remainder(notify_db_session):
assert [dict(result) for result in results] == expected_results
def test_fetch_sms_billing_for_all_services_without_an_organisation_appears(notify_db_session):
def test_fetch_sms_billing_for_all_services_without_an_organization_appears(notify_db_session):
fixtures = set_up_usage_data(datetime(2019, 5, 1))
results = fetch_sms_billing_for_all_services(datetime(2019, 5, 1), datetime(2019, 5, 31))
@@ -571,7 +571,7 @@ def test_fetch_sms_billing_for_all_services_without_an_organisation_appears(noti
# sms_remainder is 5, because service_1_sms_and_letter has 5 sms_billing_units. 2 of them for a period before
# the requested report's start date.
{
"organisation_name": fixtures["org_1"].name, "organisation_id": fixtures["org_1"].id,
"organization_name": fixtures["org_1"].name, "organization_id": fixtures["org_1"].id,
"service_name": fixtures["service_1_sms_and_letter"].name,
"service_id": fixtures["service_1_sms_and_letter"].id,
"free_sms_fragment_limit": 10, "sms_rate": Decimal('0.11'), "sms_remainder": 5,
@@ -580,14 +580,14 @@ def test_fetch_sms_billing_for_all_services_without_an_organisation_appears(noti
# sms remainder is 0, because this service sent SMS worth 15 billable units, 12 of which were sent
# before requested report's start date
{
"organisation_name": None, "organisation_id": None,
"organization_name": None, "organization_id": None,
"service_name": fixtures["service_with_sms_without_org"].name,
"service_id": fixtures["service_with_sms_without_org"].id, "free_sms_fragment_limit": 10,
"sms_rate": Decimal('0.11'), "sms_remainder": 0,
"sms_billable_units": 3, "chargeable_billable_sms": 3, "sms_cost": Decimal('0.33')
},
{
"organisation_name": None, "organisation_id": None,
"organization_name": None, "organization_id": None,
"service_name": fixtures["service_with_sms_within_allowance"].name,
"service_id": fixtures["service_with_sms_within_allowance"].id, "free_sms_fragment_limit": 10,
"sms_rate": Decimal('0.11'), "sms_remainder": 8,
@@ -599,19 +599,19 @@ def test_fetch_sms_billing_for_all_services_without_an_organisation_appears(noti
@freeze_time('2019-06-01 13:30')
def test_fetch_usage_year_for_organisation(notify_db_session):
def test_fetch_usage_year_for_organization(notify_db_session):
fixtures = set_up_usage_data(datetime(2019, 5, 1))
service_with_emails_for_org = create_service(service_name='Service with emails for org')
create_annual_billing(service_with_emails_for_org.id, free_sms_fragment_limit=0, financial_year_start=2019)
dao_add_service_to_organisation(
dao_add_service_to_organization(
service=service_with_emails_for_org,
organisation_id=fixtures["org_1"].id
organization_id=fixtures["org_1"].id
)
template = create_template(service=service_with_emails_for_org, template_type='email')
create_ft_billing(local_date=datetime(2019, 5, 1),
template=template,
notifications_sent=1100)
results = fetch_usage_year_for_organisation(fixtures["org_1"].id, 2019)
results = fetch_usage_year_for_organization(fixtures["org_1"].id, 2019)
assert len(results) == 3
first_row = results[str(fixtures["service_1_sms_and_letter"].id)]
@@ -642,12 +642,12 @@ def test_fetch_usage_year_for_organisation(notify_db_session):
assert third_row['emails_sent'] == 0
def test_fetch_usage_year_for_organisation_populates_ft_billing_for_today(notify_db_session):
def test_fetch_usage_year_for_organization_populates_ft_billing_for_today(notify_db_session):
create_rate(start_date=datetime.utcnow() - timedelta(days=1), value=0.65, notification_type='sms')
new_org = create_organisation(name='New organisation')
new_org = create_organization(name='New organization')
service = create_service()
template = create_template(service=service)
dao_add_service_to_organisation(service=service, organisation_id=new_org.id)
dao_add_service_to_organization(service=service, organization_id=new_org.id)
current_year = datetime.utcnow().year
create_annual_billing(service_id=service.id, free_sms_fragment_limit=10, financial_year_start=current_year)
@@ -655,21 +655,21 @@ def test_fetch_usage_year_for_organisation_populates_ft_billing_for_today(notify
create_notification(template=template, status='delivered')
results = fetch_usage_year_for_organisation(organisation_id=new_org.id, year=current_year)
results = fetch_usage_year_for_organization(organization_id=new_org.id, year=current_year)
assert len(results) == 1
assert FactBilling.query.count() == 1
@freeze_time('2022-05-01 13:30')
def test_fetch_usage_year_for_organisation_calculates_cost_from_multiple_rates(notify_db_session):
def test_fetch_usage_year_for_organization_calculates_cost_from_multiple_rates(notify_db_session):
old_rate_date = date(2022, 4, 29)
new_rate_date = date(2022, 5, 1)
current_year = datetime.utcnow().year
org = create_organisation(name='Organisation 1')
org = create_organization(name='Organization 1')
service_1 = create_service(restricted=False, service_name="Service 1")
dao_add_service_to_organisation(service=service_1, organisation_id=org.id)
dao_add_service_to_organization(service=service_1, organization_id=org.id)
sms_template_1 = create_template(service=service_1)
create_ft_billing(
local_date=old_rate_date, template=sms_template_1, rate=2,
@@ -681,7 +681,7 @@ def test_fetch_usage_year_for_organisation_calculates_cost_from_multiple_rates(n
)
create_annual_billing(service_id=service_1.id, free_sms_fragment_limit=3, financial_year_start=current_year)
results = fetch_usage_year_for_organisation(organisation_id=org.id, year=current_year)
results = fetch_usage_year_for_organization(organization_id=org.id, year=current_year)
assert len(results) == 1
assert results[str(service_1.id)]['free_sms_limit'] == 3
@@ -692,16 +692,16 @@ def test_fetch_usage_year_for_organisation_calculates_cost_from_multiple_rates(n
@freeze_time('2022-05-01 13:30')
def test_fetch_usage_year_for_organisation_when_no_usage(notify_db_session):
def test_fetch_usage_year_for_organization_when_no_usage(notify_db_session):
current_year = datetime.utcnow().year
org = create_organisation(name='Organisation 1')
org = create_organization(name='Organization 1')
service_1 = create_service(restricted=False, service_name="Service 1")
dao_add_service_to_organisation(service=service_1, organisation_id=org.id)
dao_add_service_to_organization(service=service_1, organization_id=org.id)
create_annual_billing(service_id=service_1.id, free_sms_fragment_limit=3, financial_year_start=current_year)
results = fetch_usage_year_for_organisation(organisation_id=org.id, year=current_year)
results = fetch_usage_year_for_organization(organization_id=org.id, year=current_year)
assert len(results) == 1
assert results[str(service_1.id)]['free_sms_limit'] == 3
@@ -712,17 +712,17 @@ def test_fetch_usage_year_for_organisation_when_no_usage(notify_db_session):
@freeze_time('2022-05-01 13:30')
def test_fetch_usage_year_for_organisation_only_queries_present_year(notify_db_session):
def test_fetch_usage_year_for_organization_only_queries_present_year(notify_db_session):
current_year = datetime.utcnow().year
last_year = current_year - 1
date_two_years_ago = date(2021, 3, 31)
date_in_last_financial_year = date(2022, 3, 31)
date_in_this_year = datetime.utcnow().date()
org = create_organisation(name='Organisation 1')
org = create_organization(name='Organization 1')
service_1 = create_service(restricted=False, service_name="Service 1")
dao_add_service_to_organisation(service=service_1, organisation_id=org.id)
dao_add_service_to_organization(service=service_1, organization_id=org.id)
sms_template_1 = create_template(service=service_1)
create_ft_billing(
@@ -741,7 +741,7 @@ def test_fetch_usage_year_for_organisation_only_queries_present_year(notify_db_s
create_annual_billing(service_id=service_1.id, free_sms_fragment_limit=0, financial_year_start=last_year)
create_annual_billing(service_id=service_1.id, free_sms_fragment_limit=8, financial_year_start=current_year)
results = fetch_usage_year_for_organisation(organisation_id=org.id, year=last_year)
results = fetch_usage_year_for_organization(organization_id=org.id, year=last_year)
assert len(results) == 1
assert results[str(service_1.id)]['sms_billable_units'] == 2
@@ -750,15 +750,15 @@ def test_fetch_usage_year_for_organisation_only_queries_present_year(notify_db_s
@freeze_time('2020-02-27 13:30')
def test_fetch_usage_year_for_organisation_only_returns_data_for_live_services(notify_db_session):
org = create_organisation(name='Organisation without live services')
def test_fetch_usage_year_for_organization_only_returns_data_for_live_services(notify_db_session):
org = create_organization(name='Organization without live services')
live_service = create_service(restricted=False)
sms_template = create_template(service=live_service)
trial_service = create_service(restricted=True, service_name='trial_service')
email_template = create_template(service=trial_service, template_type='email')
trial_sms_template = create_template(service=trial_service, template_type='sms')
dao_add_service_to_organisation(service=live_service, organisation_id=org.id)
dao_add_service_to_organisation(service=trial_service, organisation_id=org.id)
dao_add_service_to_organization(service=live_service, organization_id=org.id)
dao_add_service_to_organization(service=trial_service, organization_id=org.id)
create_ft_billing(local_date=datetime.utcnow().date(), template=sms_template, rate=0.0158,
billable_unit=19, notifications_sent=19)
create_ft_billing(local_date=datetime.utcnow().date(), template=email_template, billable_unit=0,
@@ -768,7 +768,7 @@ def test_fetch_usage_year_for_organisation_only_returns_data_for_live_services(n
create_annual_billing(service_id=live_service.id, free_sms_fragment_limit=0, financial_year_start=2020)
create_annual_billing(service_id=trial_service.id, free_sms_fragment_limit=0, financial_year_start=2020)
results = fetch_usage_year_for_organisation(organisation_id=org.id, year=2020)
results = fetch_usage_year_for_organization(organization_id=org.id, year=2020)
assert len(results) == 1
assert results[str(live_service.id)]['sms_billable_units'] == 19
@@ -776,15 +776,15 @@ def test_fetch_usage_year_for_organisation_only_returns_data_for_live_services(n
@freeze_time('2022-04-27 13:30')
def test_query_organisation_sms_usage_for_year_handles_multiple_services(notify_db_session):
def test_query_organization_sms_usage_for_year_handles_multiple_services(notify_db_session):
today = datetime.utcnow().date()
yesterday = datetime.utcnow().date() - timedelta(days=1)
current_year = datetime.utcnow().year
org = create_organisation(name='Organisation 1')
org = create_organization(name='Organization 1')
service_1 = create_service(restricted=False, service_name="Service 1")
dao_add_service_to_organisation(service=service_1, organisation_id=org.id)
dao_add_service_to_organization(service=service_1, organization_id=org.id)
sms_template_1 = create_template(service=service_1)
create_ft_billing(
local_date=yesterday, template=sms_template_1, rate=1,
@@ -797,7 +797,7 @@ def test_query_organisation_sms_usage_for_year_handles_multiple_services(notify_
create_annual_billing(service_id=service_1.id, free_sms_fragment_limit=5, financial_year_start=current_year)
service_2 = create_service(restricted=False, service_name="Service 2")
dao_add_service_to_organisation(service=service_2, organisation_id=org.id)
dao_add_service_to_organization(service=service_2, organization_id=org.id)
sms_template_2 = create_template(service=service_2)
create_ft_billing(
local_date=yesterday, template=sms_template_2, rate=1,
@@ -811,7 +811,7 @@ def test_query_organisation_sms_usage_for_year_handles_multiple_services(notify_
# ----------
result = query_organisation_sms_usage_for_year(org.id, 2022).all()
result = query_organization_sms_usage_for_year(org.id, 2022).all()
service_1_rows = [row for row in result if row.service_id == service_1.id]
service_2_rows = [row for row in result if row.service_id == service_2.id]
@@ -845,15 +845,15 @@ def test_query_organisation_sms_usage_for_year_handles_multiple_services(notify_
@freeze_time('2022-05-01 13:30')
def test_query_organisation_sms_usage_for_year_handles_multiple_rates(notify_db_session):
def test_query_organization_sms_usage_for_year_handles_multiple_rates(notify_db_session):
old_rate_date = date(2022, 4, 29)
new_rate_date = date(2022, 5, 1)
current_year = datetime.utcnow().year
org = create_organisation(name='Organisation 1')
org = create_organization(name='Organization 1')
service_1 = create_service(restricted=False, service_name="Service 1")
dao_add_service_to_organisation(service=service_1, organisation_id=org.id)
dao_add_service_to_organization(service=service_1, organization_id=org.id)
sms_template_1 = create_template(service=service_1)
create_ft_billing(
local_date=old_rate_date, template=sms_template_1, rate=2,
@@ -865,7 +865,7 @@ def test_query_organisation_sms_usage_for_year_handles_multiple_rates(notify_db_
)
create_annual_billing(service_id=service_1.id, free_sms_fragment_limit=3, financial_year_start=current_year)
result = query_organisation_sms_usage_for_year(org.id, 2022).all()
result = query_organization_sms_usage_for_year(org.id, 2022).all()
# al lthe free allowance is used on the first day
assert result[0]['local_date'] == date(2022, 4, 29)
@@ -992,28 +992,28 @@ def test_fetch_volumes_by_service(notify_db_session):
# since we are using a pre-set up fixture, we only care about some of the results
assert len(results) == 5
assert results[0].service_name == 'a - with sms and letter'
assert results[0].organisation_name == 'Org for a - with sms and letter'
assert results[0].organization_name == 'Org for a - with sms and letter'
assert results[0].free_allowance == 10
assert results[0].sms_notifications == 2
assert results[0].sms_chargeable_units == 3
assert results[0].email_totals == 0
assert results[1].service_name == 'f - without ft_billing'
assert results[1].organisation_name == 'Org for a - with sms and letter'
assert results[1].organization_name == 'Org for a - with sms and letter'
assert results[1].free_allowance == 10
assert results[1].sms_notifications == 0
assert results[1].sms_chargeable_units == 0
assert results[1].email_totals == 0
assert results[3].service_name == 'b - chargeable sms'
assert not results[3].organisation_name
assert not results[3].organization_name
assert results[3].free_allowance == 10
assert results[3].sms_notifications == 2
assert results[3].sms_chargeable_units == 3
assert results[3].email_totals == 0
assert results[4].service_name == 'e - sms within allowance'
assert not results[4].organisation_name
assert not results[4].organization_name
assert results[4].free_allowance == 10
assert results[4].sms_notifications == 1
assert results[4].sms_chargeable_units == 2

View File

@@ -1,344 +0,0 @@
import datetime
import uuid
import pytest
from sqlalchemy.exc import IntegrityError, SQLAlchemyError
from app import db
from app.dao.organisation_dao import (
dao_add_service_to_organisation,
dao_add_user_to_organisation,
dao_get_organisation_by_email_address,
dao_get_organisation_by_id,
dao_get_organisation_by_service_id,
dao_get_organisation_services,
dao_get_organisations,
dao_get_users_for_organisation,
dao_update_organisation,
)
from app.models import Organisation, Service
from tests.app.db import (
create_domain,
create_email_branding,
create_organisation,
create_service,
create_user,
)
def test_get_organisations_gets_all_organisations_alphabetically_with_active_organisations_first(
notify_db_session
):
m_active_org = create_organisation(name='m_active_organisation')
z_inactive_org = create_organisation(name='z_inactive_organisation', active=False)
a_inactive_org = create_organisation(name='a_inactive_organisation', active=False)
z_active_org = create_organisation(name='z_active_organisation')
a_active_org = create_organisation(name='a_active_organisation')
organisations = dao_get_organisations()
assert len(organisations) == 5
assert organisations[0] == a_active_org
assert organisations[1] == m_active_org
assert organisations[2] == z_active_org
assert organisations[3] == a_inactive_org
assert organisations[4] == z_inactive_org
def test_get_organisation_by_id_gets_correct_organisation(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_session):
create_organisation()
organisation = Organisation.query.one()
user = create_user()
email_branding = create_email_branding()
data = {
'name': 'new name',
"organisation_type": 'state',
"agreement_signed": True,
"agreement_signed_at": datetime.datetime.utcnow(),
"agreement_signed_by_id": user.id,
"agreement_signed_version": 999.99,
"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
@pytest.mark.parametrize('domain_list, expected_domains', (
(['abc', 'def'], {'abc', 'def'}),
(['ABC', 'DEF'], {'abc', 'def'}),
([], set()),
(None, {'123', '456'}),
))
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
@pytest.mark.parametrize('domain_list, expected_domains', (
(['abc', 'ABC'], {'abc'}),
))
def test_update_organisation_domains_lowercases_integrity_error(
notify_db_session,
domain_list,
expected_domains,
):
create_organisation()
organisation = Organisation.query.one()
# Seed some domains
dao_update_organisation(organisation.id, domains=['123', '456'])
with pytest.raises(expected_exception=IntegrityError):
# 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_does_not_update_the_service_if_certain_attributes_not_provided(
sample_service,
sample_organisation,
):
email_branding = create_email_branding()
sample_service.organisation_type = 'state'
sample_organisation.organisation_type = 'federal'
sample_organisation.email_branding = email_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 == 'federal'
assert sample_service.organisation_type == 'state'
assert sample_organisation.email_branding == email_branding
assert sample_service.email_branding is None
def test_update_organisation_updates_the_service_org_type_if_org_type_is_provided(
sample_service,
sample_organisation,
):
sample_service.organisation_type = 'state'
sample_organisation.organisation_type = 'state'
sample_organisation.services.append(sample_service)
db.session.commit()
dao_update_organisation(sample_organisation.id, organisation_type='federal')
assert sample_organisation.organisation_type == 'federal'
assert sample_service.organisation_type == 'federal'
assert Service.get_history_model().query.filter_by(
id=sample_service.id,
version=2
).one().organisation_type == 'federal'
def test_update_organisation_updates_the_service_branding_if_branding_is_provided(
sample_service,
sample_organisation,
):
email_branding = create_email_branding()
sample_organisation.services.append(sample_service)
db.session.commit()
dao_update_organisation(sample_organisation.id, email_branding_id=email_branding.id)
assert sample_organisation.email_branding == email_branding
assert sample_service.email_branding == email_branding
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')
sample_service.email_branding = custom_email_branding
sample_organisation.services.append(sample_service)
db.session.commit()
dao_update_organisation(sample_organisation.id, email_branding_id=email_branding.id)
assert sample_organisation.email_branding == email_branding
assert sample_service.email_branding == custom_email_branding
def test_add_service_to_organisation(sample_service, sample_organisation):
assert sample_organisation.services == []
sample_service.organisation_type = "federal"
sample_organisation.organisation_type = "state"
dao_add_service_to_organisation(sample_service, sample_organisation.id)
assert len(sample_organisation.services) == 1
assert sample_organisation.services[0].id == sample_service.id
assert sample_service.organisation_type == sample_organisation.organisation_type
assert Service.get_history_model().query.filter_by(
id=sample_service.id,
version=2
).one().organisation_type == sample_organisation.organisation_type
assert sample_service.organisation_id == sample_organisation.id
def test_get_organisation_services(sample_service, sample_organisation):
another_service = create_service(service_name='service 2')
another_org = create_organisation()
dao_add_service_to_organisation(sample_service, sample_organisation.id)
dao_add_service_to_organisation(another_service, sample_organisation.id)
org_services = dao_get_organisation_services(sample_organisation.id)
other_org_services = dao_get_organisation_services(another_org.id)
assert [sample_service.name, another_service.name] == sorted([s.name for s in org_services])
assert not other_org_services
def test_get_organisation_by_service_id(sample_service, sample_organisation):
another_service = create_service(service_name='service 2')
another_org = create_organisation()
dao_add_service_to_organisation(sample_service, sample_organisation.id)
dao_add_service_to_organisation(another_service, another_org.id)
organisation_1 = dao_get_organisation_by_service_id(sample_service.id)
organisation_2 = dao_get_organisation_by_service_id(another_service.id)
assert organisation_1 == sample_organisation
assert organisation_2 == another_org
def test_dao_get_users_for_organisation(sample_organisation):
first = create_user(email='first@invited.com')
second = create_user(email='another@invited.com')
dao_add_user_to_organisation(organisation_id=sample_organisation.id, user_id=first.id)
dao_add_user_to_organisation(organisation_id=sample_organisation.id, user_id=second.id)
results = dao_get_users_for_organisation(organisation_id=sample_organisation.id)
assert len(results) == 2
assert results[0] == first
assert results[1] == second
def test_dao_get_users_for_organisation_returns_empty_list(sample_organisation):
results = dao_get_users_for_organisation(organisation_id=sample_organisation.id)
assert len(results) == 0
def test_dao_get_users_for_organisation_only_returns_active_users(sample_organisation):
first = create_user(email='first@invited.com')
second = create_user(email='another@invited.com')
dao_add_user_to_organisation(organisation_id=sample_organisation.id, user_id=first.id)
dao_add_user_to_organisation(organisation_id=sample_organisation.id, user_id=second.id)
second.state = 'inactive'
results = dao_get_users_for_organisation(organisation_id=sample_organisation.id)
assert len(results) == 1
assert results[0] == first
def test_add_user_to_organisation_returns_user(sample_organisation):
org_user = create_user()
assert not org_user.organisations
added_user = dao_add_user_to_organisation(organisation_id=sample_organisation.id, user_id=org_user.id)
assert len(added_user.organisations) == 1
assert added_user.organisations[0] == sample_organisation
def test_add_user_to_organisation_when_user_does_not_exist(sample_organisation):
with pytest.raises(expected_exception=SQLAlchemyError):
dao_add_user_to_organisation(organisation_id=sample_organisation.id, user_id=uuid.uuid4())
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(
domain,
expected_org,
notify_db_session
):
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
def test_get_organisation_by_email_address_ignores_gsi_gov_uk(notify_db_session):
org = create_organisation()
create_domain('example.gov.uk', org.id)
found_org = dao_get_organisation_by_email_address('test_gsi_address@example.gsi.gov.uk')
assert org == found_org

View File

@@ -0,0 +1,344 @@
import datetime
import uuid
import pytest
from sqlalchemy.exc import IntegrityError, SQLAlchemyError
from app import db
from app.dao.organization_dao import (
dao_add_service_to_organization,
dao_add_user_to_organization,
dao_get_organization_by_email_address,
dao_get_organization_by_id,
dao_get_organization_by_service_id,
dao_get_organization_services,
dao_get_organizations,
dao_get_users_for_organization,
dao_update_organization,
)
from app.models import Organization, Service
from tests.app.db import (
create_domain,
create_email_branding,
create_organization,
create_service,
create_user,
)
def test_get_organizations_gets_all_organizations_alphabetically_with_active_organizations_first(
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')
organizations = dao_get_organizations()
assert len(organizations) == 5
assert organizations[0] == a_active_org
assert organizations[1] == m_active_org
assert organizations[2] == z_active_org
assert organizations[3] == a_inactive_org
assert organizations[4] == z_inactive_org
def test_get_organization_by_id_gets_correct_organization(notify_db_session):
organization = create_organization()
organization_from_db = dao_get_organization_by_id(organization.id)
assert organization_from_db == organization
def test_update_organization(notify_db_session):
create_organization()
organization = Organization.query.one()
user = create_user()
email_branding = create_email_branding()
data = {
'name': 'new name',
"organization_type": 'state',
"agreement_signed": True,
"agreement_signed_at": datetime.datetime.utcnow(),
"agreement_signed_by_id": user.id,
"agreement_signed_version": 999.99,
"email_branding_id": email_branding.id,
}
for attribute, value in data.items():
assert getattr(organization, attribute) != value
assert organization.updated_at is None
dao_update_organization(organization.id, **data)
organization = Organization.query.one()
for attribute, value in data.items():
assert getattr(organization, attribute) == value
assert organization.updated_at
@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,
expected_domains,
):
create_organization()
organization = Organization.query.one()
# Seed some domains
dao_update_organization(organization.id, domains=['123', '456'])
# This should overwrite the seeded domains
dao_update_organization(organization.id, domains=domain_list)
assert {domain.domain for domain in organization.domains} == expected_domains
@pytest.mark.parametrize('domain_list, expected_domains', (
(['abc', 'ABC'], {'abc'}),
))
def test_update_organization_domains_lowercases_integrity_error(
notify_db_session,
domain_list,
expected_domains,
):
create_organization()
organization = Organization.query.one()
# Seed some domains
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)
assert {domain.domain for domain in organization.domains} == expected_domains
def test_update_organization_does_not_update_the_service_if_certain_attributes_not_provided(
sample_service,
sample_organization,
):
email_branding = create_email_branding()
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'
dao_update_organization(sample_organization.id, 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.email_branding == email_branding
assert sample_service.email_branding is None
def test_update_organization_updates_the_service_org_type_if_org_type_is_provided(
sample_service,
sample_organization,
):
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')
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(
sample_service,
sample_organization,
):
email_branding = create_email_branding()
sample_organization.services.append(sample_service)
db.session.commit()
dao_update_organization(sample_organization.id, email_branding_id=email_branding.id)
assert sample_organization.email_branding == email_branding
assert sample_service.email_branding == email_branding
def test_update_organization_does_not_override_service_branding(
sample_service,
sample_organization,
):
email_branding = create_email_branding()
custom_email_branding = create_email_branding(name='custom')
sample_service.email_branding = custom_email_branding
sample_organization.services.append(sample_service)
db.session.commit()
dao_update_organization(sample_organization.id, email_branding_id=email_branding.id)
assert sample_organization.email_branding == email_branding
assert sample_service.email_branding == custom_email_branding
def test_add_service_to_organization(sample_service, sample_organization):
assert sample_organization.services == []
sample_service.organization_type = "federal"
sample_organization.organization_type = "state"
dao_add_service_to_organization(sample_service, sample_organization.id)
assert len(sample_organization.services) == 1
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 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_org = create_organization()
dao_add_service_to_organization(sample_service, sample_organization.id)
dao_add_service_to_organization(another_service, sample_organization.id)
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 not other_org_services
def test_get_organization_by_service_id(sample_service, sample_organization):
another_service = create_service(service_name='service 2')
another_org = create_organization()
dao_add_service_to_organization(sample_service, sample_organization.id)
dao_add_service_to_organization(another_service, another_org.id)
organization_1 = dao_get_organization_by_service_id(sample_service.id)
organization_2 = dao_get_organization_by_service_id(another_service.id)
assert organization_1 == sample_organization
assert organization_2 == another_org
def test_dao_get_users_for_organization(sample_organization):
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)
results = dao_get_users_for_organization(organization_id=sample_organization.id)
assert len(results) == 2
assert results[0] == first
assert results[1] == second
def test_dao_get_users_for_organization_returns_empty_list(sample_organization):
results = dao_get_users_for_organization(organization_id=sample_organization.id)
assert len(results) == 0
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')
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'
results = dao_get_users_for_organization(organization_id=sample_organization.id)
assert len(results) == 1
assert results[0] == first
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)
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())
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)
@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)
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))
if expected_org:
assert found_org is org
else:
assert found_org is None
def test_get_organization_by_email_address_ignores_gsi_gov_uk(notify_db_session):
org = create_organization()
create_domain('example.gov.uk', org.id)
found_org = dao_get_organization_by_email_address('test_gsi_address@example.gsi.gov.uk')
assert org == found_org

View File

@@ -14,7 +14,7 @@ from app.dao.inbound_numbers_dao import (
dao_set_inbound_number_active_flag,
dao_set_inbound_number_to_service,
)
from app.dao.organisation_dao import dao_add_service_to_organisation
from app.dao.organization_dao import dao_add_service_to_organization
from app.dao.service_permissions_dao import dao_remove_service_permission
from app.dao.service_user_dao import (
dao_get_service_user,
@@ -38,7 +38,7 @@ from app.dao.services_dao import (
dao_suspend_service,
dao_update_service,
delete_service_and_all_associated_db_objects,
get_live_services_with_organisation,
get_live_services_with_organization,
get_services_by_partial_name,
)
from app.dao.users_dao import create_user_code, save_model_user
@@ -54,7 +54,7 @@ from app.models import (
Job,
Notification,
NotificationHistory,
Organisation,
Organization,
Permission,
Service,
ServicePermission,
@@ -73,7 +73,7 @@ from tests.app.db import (
create_invited_user,
create_notification,
create_notification_history,
create_organisation,
create_organization,
create_service,
create_service_with_defined_sms_sender,
create_service_with_inbound_number,
@@ -90,7 +90,7 @@ def test_create_service(notify_db_session):
email_from="email_from",
message_limit=1000,
restricted=False,
organisation_type='federal',
organization_type='federal',
created_by=user)
dao_create_service(service, user)
assert Service.query.count() == 1
@@ -102,25 +102,25 @@ def test_create_service(notify_db_session):
assert service_db.prefix_sms is True
assert service.active is True
assert user in service_db.users
assert service_db.organisation_type == 'federal'
assert not service.organisation_id
assert service_db.organization_type == 'federal'
assert not service.organization_id
def test_create_service_with_organisation(notify_db_session):
def test_create_service_with_organization(notify_db_session):
user = create_user(email='local.authority@local-authority.gov.uk')
organisation = create_organisation(
name='Some local authority', organisation_type='state', domains=['local-authority.gov.uk'])
organization = create_organization(
name='Some local authority', organization_type='state', domains=['local-authority.gov.uk'])
assert Service.query.count() == 0
service = Service(name="service_name",
email_from="email_from",
message_limit=1000,
restricted=False,
organisation_type='federal',
organization_type='federal',
created_by=user)
dao_create_service(service, user)
assert Service.query.count() == 1
service_db = Service.query.one()
organisation = Organisation.query.get(organisation.id)
organization = Organization.query.get(organization.id)
assert service_db.name == "service_name"
assert service_db.id == service.id
assert service_db.email_from == 'email_from'
@@ -128,9 +128,9 @@ def test_create_service_with_organisation(notify_db_session):
assert service_db.prefix_sms is True
assert service.active is True
assert user in service_db.users
assert service_db.organisation_type == 'state'
assert service.organisation_id == organisation.id
assert service.organisation == organisation
assert service_db.organization_type == 'state'
assert service.organization_id == organization.id
assert service.organization == organization
def test_cannot_create_two_services_with_same_name(notify_db_session):
@@ -387,7 +387,7 @@ def test_get_all_user_services_should_return_empty_list_if_no_services_for_user(
@freeze_time('2019-04-23T10:00:00')
def test_dao_fetch_live_services_data(sample_user):
org = create_organisation(organisation_type='federal')
org = create_organization(organization_type='federal')
service = create_service(go_live_user=sample_user, go_live_at='2014-04-20T10:00:00')
sms_template = create_template(service=service)
service_2 = create_service(service_name='second', go_live_at='2017-04-20T10:00:00', go_live_user=sample_user)
@@ -397,7 +397,7 @@ def test_dao_fetch_live_services_data(sample_user):
create_service(service_name='not_active', active=False)
create_service(service_name='not_live', count_as_live=False)
email_template = create_template(service=service, template_type='email')
dao_add_service_to_organisation(service=service, organisation_id=org.id)
dao_add_service_to_organization(service=service, organization_id=org.id)
# two sms billing records for 1st service within current financial year:
create_ft_billing(local_date='2019-04-20', template=sms_template)
create_ft_billing(local_date='2019-04-21', template=sms_template)
@@ -418,19 +418,19 @@ def test_dao_fetch_live_services_data(sample_user):
assert len(results) == 3
# checks the results and that they are ordered by date:
assert results == [
{'service_id': mock.ANY, 'service_name': 'Sample service', 'organisation_name': 'test_org_1',
'organisation_type': 'federal', 'consent_to_research': None, 'contact_name': 'Test User',
{'service_id': mock.ANY, 'service_name': 'Sample service', 'organization_name': 'test_org_1',
'organization_type': 'federal', 'consent_to_research': None, 'contact_name': 'Test User',
'contact_email': 'notify@digital.cabinet-office.gov.uk', 'contact_mobile': '+12028675309',
'live_date': datetime(2014, 4, 20, 10, 0), 'sms_volume_intent': None, 'email_volume_intent': None,
'sms_totals': 2, 'email_totals': 1, 'free_sms_fragment_limit': 100},
{'service_id': mock.ANY, 'service_name': 'third', 'organisation_name': None, 'consent_to_research': None,
'organisation_type': None, 'contact_name': None, 'contact_email': None,
{'service_id': mock.ANY, 'service_name': 'third', 'organization_name': None, 'consent_to_research': None,
'organization_type': None, 'contact_name': None, 'contact_email': None,
'contact_mobile': None, 'live_date': datetime(2016, 4, 20, 10, 0), 'sms_volume_intent': None,
'email_volume_intent': None, 'sms_totals': 0, 'email_totals': 0, 'free_sms_fragment_limit': 200},
{'service_id': mock.ANY, 'service_name': 'second', 'organisation_name': None, 'consent_to_research': None,
{'service_id': mock.ANY, 'service_name': 'second', 'organization_name': None, 'consent_to_research': None,
'contact_name': 'Test User', 'contact_email': 'notify@digital.cabinet-office.gov.uk',
'contact_mobile': '+12028675309', 'live_date': datetime(2017, 4, 20, 10, 0), 'sms_volume_intent': None,
'organisation_type': None, 'email_volume_intent': None, 'sms_totals': 0, 'email_totals': 0,
'organization_type': None, 'email_volume_intent': None, 'sms_totals': 0, 'email_totals': 0,
'free_sms_fragment_limit': 300}
]
@@ -607,15 +607,15 @@ def test_create_service_and_history_is_transactional(notify_db_session):
def test_delete_service_and_associated_objects(notify_db_session):
user = create_user()
organisation = create_organisation()
service = create_service(user=user, service_permissions=None, organisation=organisation)
organization = create_organization()
service = create_service(user=user, service_permissions=None, organization=organization)
create_user_code(user=user, code='somecode', code_type='email')
create_user_code(user=user, code='somecode', code_type='sms')
template = create_template(service=service)
api_key = create_api_key(service=service)
create_notification(template=template, api_key=api_key)
create_invited_user(service=service)
user.organisations = [organisation]
user.organizations = [organization]
assert ServicePermission.query.count() == len((
SMS_TYPE, EMAIL_TYPE, INTERNATIONAL_SMS_TYPE,
@@ -635,8 +635,8 @@ def test_delete_service_and_associated_objects(notify_db_session):
assert Service.query.count() == 0
assert Service.get_history_model().query.count() == 0
assert ServicePermission.query.count() == 0
# the organisation hasn't been deleted
assert Organisation.query.count() == 1
# the organization hasn't been deleted
assert Organization.query.count() == 1
def test_add_existing_user_to_another_service_doesnot_change_old_permissions(notify_db_session):
@@ -1151,24 +1151,24 @@ def test_dao_find_services_with_high_failure_rates(notify_db_session, fake_uuid)
assert result[0].permanent_failure_rate == 0.25
def test_get_live_services_with_organisation(sample_organisation):
def test_get_live_services_with_organization(sample_organization):
trial_service = create_service(service_name='trial service', restricted=True)
live_service = create_service(service_name="count as live")
live_service_diff_org = create_service(service_name="live service different org")
dont_count_as_live = create_service(service_name="dont count as live", count_as_live=False)
inactive_service = create_service(service_name="inactive", active=False)
service_without_org = create_service(service_name="no org")
another_org = create_organisation(name='different org', )
another_org = create_organization(name='different org', )
dao_add_service_to_organisation(trial_service, sample_organisation.id)
dao_add_service_to_organisation(live_service, sample_organisation.id)
dao_add_service_to_organisation(dont_count_as_live, sample_organisation.id)
dao_add_service_to_organisation(inactive_service, sample_organisation.id)
dao_add_service_to_organisation(live_service_diff_org, another_org.id)
dao_add_service_to_organization(trial_service, sample_organization.id)
dao_add_service_to_organization(live_service, sample_organization.id)
dao_add_service_to_organization(dont_count_as_live, sample_organization.id)
dao_add_service_to_organization(inactive_service, sample_organization.id)
dao_add_service_to_organization(live_service_diff_org, another_org.id)
services = get_live_services_with_organisation()
services = get_live_services_with_organization()
assert len(services) == 3
assert ([(x.service_name, x.organisation_name) for x in services]) == [
assert ([(x.service_name, x.organization_name) for x in services]) == [
(live_service_diff_org.name, another_org.name),
(live_service.name, sample_organisation.name),
(live_service.name, sample_organization.name),
(service_without_org.name, None)]

View File

@@ -195,7 +195,7 @@ def test_create_secret_code_can_customize_digits():
@freeze_time('2018-07-07 12:00:00')
def test_dao_archive_user(sample_user, sample_organisation, fake_uuid):
def test_dao_archive_user(sample_user, sample_organization, fake_uuid):
sample_user.current_session_id = fake_uuid
# create 2 services for sample_user to be a member of (each with another active user)
@@ -212,7 +212,7 @@ def test_dao_archive_user(sample_user, sample_organisation, fake_uuid):
create_permissions(service_2_user, service_2, 'manage_settings')
# make sample_user an org member
sample_organisation.users = [sample_user]
sample_organization.users = [sample_user]
# give sample_user folder permissions for a service_1 folder
folder = create_template_folder(service_1)
@@ -224,7 +224,7 @@ def test_dao_archive_user(sample_user, sample_organisation, fake_uuid):
assert sample_user.get_permissions() == {}
assert sample_user.services == []
assert sample_user.organisations == []
assert sample_user.organizations == []
assert sample_user.auth_type == EMAIL_AUTH_TYPE
assert sample_user.email_address == '_archived_2018-07-07_notify@digital.cabinet-office.gov.uk'
assert sample_user.mobile_number is None