Merge branch 'main' into stvnrlly-remove-broadcasts

This commit is contained in:
stvnrlly
2022-10-20 19:44:20 -04:00
56 changed files with 1011 additions and 613 deletions

View File

@@ -15,7 +15,7 @@ from app.dao.notifications_dao import (
dao_get_letters_to_be_printed,
dao_get_notification_by_reference,
dao_get_notification_count_for_job_id,
dao_get_notification_or_history_by_reference,
dao_get_notification_history_by_reference,
dao_get_notifications_by_recipient_or_reference,
dao_timeout_notifications,
dao_update_notification,
@@ -1607,28 +1607,28 @@ def test_dao_get_notification_by_reference_with_no_matches_raises_error(notify_d
dao_get_notification_by_reference('REF1')
def test_dao_get_notification_or_history_by_reference_with_one_match_returns_notification(
def test_dao_get_notification_history_by_reference_with_one_match_returns_notification(
sample_letter_template
):
create_notification(template=sample_letter_template, reference='REF1')
notification = dao_get_notification_or_history_by_reference('REF1')
notification = dao_get_notification_history_by_reference('REF1')
assert notification.reference == 'REF1'
def test_dao_get_notification_or_history_by_reference_with_multiple_matches_raises_error(
def test_dao_get_notification_history_by_reference_with_multiple_matches_raises_error(
sample_letter_template
):
create_notification(template=sample_letter_template, reference='REF1')
create_notification(template=sample_letter_template, reference='REF1')
with pytest.raises(SQLAlchemyError):
dao_get_notification_or_history_by_reference('REF1')
dao_get_notification_history_by_reference('REF1')
def test_dao_get_notification_or_history_by_reference_with_no_matches_raises_error(notify_db_session):
def test_dao_get_notification_history_by_reference_with_no_matches_raises_error(notify_db_session):
with pytest.raises(SQLAlchemyError):
dao_get_notification_or_history_by_reference('REF1')
dao_get_notification_history_by_reference('REF1')
@pytest.mark.parametrize("notification_type",

View File

@@ -47,31 +47,17 @@ def test_dao_update_annual_billing_for_future_years(notify_db_session, sample_se
@pytest.mark.parametrize('org_type, year, expected_default',
[('central', 2021, 150000),
('local', 2021, 25000),
('nhs_central', 2021, 150000),
('nhs_local', 2021, 25000),
('nhs_gp', 2021, 10000),
('emergency_service', 2021, 25000),
('school_or_college', 2021, 10000),
('other', 2021, 10000),
(None, 2021, 10000),
('central', 2020, 250000),
('local', 2020, 25000),
('nhs_central', 2020, 250000),
('nhs_local', 2020, 25000),
('nhs_gp', 2020, 25000),
('emergency_service', 2020, 25000),
('school_or_college', 2020, 25000),
('other', 2020, 25000),
(None, 2020, 25000),
('central', 2019, 250000),
('school_or_college', 2022, 10000),
('central', 2022, 40000),
('local', 2022, 20000),
('nhs_local', 2022, 20000),
('emergency_service', 2022, 20000),
('central', 2023, 40000),
[('federal', 2021, 150000),
('state', 2021, 150000),
(None, 2021, 150000),
('federal', 2020, 250000),
('state', 2020, 250000),
('other', 2020, 250000),
(None, 2020, 250000),
('federal', 2019, 250000),
('federal', 2022, 40000),
('state', 2022, 40000),
('federal', 2023, 40000),
])
def test_set_default_free_allowance_for_service(notify_db_session, org_type, year, expected_default):
@@ -93,7 +79,7 @@ def test_set_default_free_allowance_for_service_using_correct_year(sample_servic
mock_dao.assert_called_once_with(
sample_service.id,
25000,
250000,
2020
)
@@ -105,9 +91,9 @@ def test_set_default_free_allowance_for_service_updates_existing_year(sample_ser
assert not sample_service.organisation_type
assert len(annual_billing) == 1
assert annual_billing[0].service_id == sample_service.id
assert annual_billing[0].free_sms_fragment_limit == 10000
assert annual_billing[0].free_sms_fragment_limit == 150000
sample_service.organisation_type = 'central'
sample_service.organisation_type = 'federal'
set_default_free_allowance_for_service(service=sample_service, year_start=None)
annual_billing = AnnualBilling.query.all()

View File

@@ -65,7 +65,7 @@ def test_update_organisation(notify_db_session):
data = {
'name': 'new name',
"crown": True,
"organisation_type": 'local',
"organisation_type": 'state',
"agreement_signed": True,
"agreement_signed_at": datetime.datetime.utcnow(),
"agreement_signed_by_id": user.id,
@@ -124,8 +124,8 @@ def test_update_organisation_does_not_update_the_service_if_certain_attributes_n
email_branding = create_email_branding()
letter_branding = create_letter_branding()
sample_service.organisation_type = 'local'
sample_organisation.organisation_type = 'central'
sample_service.organisation_type = 'state'
sample_organisation.organisation_type = 'federal'
sample_organisation.email_branding = email_branding
sample_organisation.letter_branding = letter_branding
@@ -138,8 +138,8 @@ def test_update_organisation_does_not_update_the_service_if_certain_attributes_n
assert sample_organisation.name == 'updated org name'
assert sample_organisation.organisation_type == 'central'
assert sample_service.organisation_type == 'local'
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
@@ -152,20 +152,20 @@ def test_update_organisation_updates_the_service_org_type_if_org_type_is_provide
sample_service,
sample_organisation,
):
sample_service.organisation_type = 'local'
sample_organisation.organisation_type = 'local'
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='central')
dao_update_organisation(sample_organisation.id, organisation_type='federal')
assert sample_organisation.organisation_type == 'central'
assert sample_service.organisation_type == 'central'
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 == 'central'
).one().organisation_type == 'federal'
def test_update_organisation_updates_the_service_branding_if_branding_is_provided(
@@ -228,8 +228,8 @@ def test_update_organisation_updates_services_with_new_crown_type(
def test_add_service_to_organisation(sample_service, sample_organisation):
assert sample_organisation.services == []
sample_service.organisation_type = "central"
sample_organisation.organisation_type = "local"
sample_service.organisation_type = "federal"
sample_organisation.organisation_type = "state"
sample_organisation.crown = False
dao_add_service_to_organisation(sample_service, sample_organisation.id)

View File

@@ -98,7 +98,7 @@ def test_create_service(notify_db_session):
email_from="email_from",
message_limit=1000,
restricted=False,
organisation_type='central',
organisation_type='federal',
created_by=user)
dao_create_service(service, user)
assert Service.query.count() == 1
@@ -110,7 +110,7 @@ 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 == 'central'
assert service_db.organisation_type == 'federal'
assert service_db.crown is None
assert not service.letter_branding
assert not service.organisation_id
@@ -119,13 +119,13 @@ def test_create_service(notify_db_session):
def test_create_service_with_organisation(notify_db_session):
user = create_user(email='local.authority@local-authority.gov.uk')
organisation = create_organisation(
name='Some local authority', organisation_type='local', domains=['local-authority.gov.uk'])
name='Some local authority', organisation_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='central',
organisation_type='federal',
created_by=user)
dao_create_service(service, user)
assert Service.query.count() == 1
@@ -138,7 +138,7 @@ 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 == 'local'
assert service_db.organisation_type == 'state'
assert service_db.crown is None
assert not service.letter_branding
assert service.organisation_id == organisation.id
@@ -162,6 +162,7 @@ def test_create_service_with_organisation(notify_db_session):
# the NHS branding set up
('SHN', False),
))
@pytest.mark.skip(reason='Update for TTS')
def test_create_nhs_service_get_default_branding_based_on_email_address(
notify_db_session,
branding_name_to_create,
@@ -446,7 +447,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='nhs_central')
org = create_organisation(organisation_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)
@@ -484,7 +485,7 @@ def test_dao_fetch_live_services_data(sample_user):
# 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': 'nhs_central', 'consent_to_research': None, 'contact_name': 'Test User',
'organisation_type': 'federal', 'consent_to_research': None, 'contact_name': 'Test User',
'contact_email': 'notify@digital.cabinet-office.gov.uk', 'contact_mobile': '+447700900986',
'live_date': datetime(2014, 4, 20, 10, 0), 'sms_volume_intent': None, 'email_volume_intent': None,
'letter_volume_intent': None, 'sms_totals': 2, 'email_totals': 1, 'letter_totals': 1,