mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-25 00:33:41 -04:00
Merge branch 'master' into stop-populating-mapping-tables
This commit is contained in:
@@ -35,7 +35,7 @@ def test_should_only_get_created_letters(sample_letter_template):
|
||||
|
||||
def test_should_only_get_api_letters(sample_letter_template, sample_letter_job):
|
||||
api_noti = create_notification(sample_letter_template)
|
||||
job_noti = create_notification(sample_letter_template, job=sample_letter_job)
|
||||
create_notification(sample_letter_template, job=sample_letter_job)
|
||||
|
||||
ret = dao_set_created_live_letter_api_notifications_to_pending()
|
||||
|
||||
@@ -44,7 +44,7 @@ def test_should_only_get_api_letters(sample_letter_template, sample_letter_job):
|
||||
|
||||
def test_should_only_get_normal_api_letters(sample_letter_template):
|
||||
live_noti = create_notification(sample_letter_template, key_type=KEY_TYPE_NORMAL)
|
||||
test_noti = create_notification(sample_letter_template, key_type=KEY_TYPE_TEST)
|
||||
create_notification(sample_letter_template, key_type=KEY_TYPE_TEST)
|
||||
|
||||
ret = dao_set_created_live_letter_api_notifications_to_pending()
|
||||
|
||||
|
||||
@@ -1254,7 +1254,7 @@ def test_dao_timeout_notifications_doesnt_affect_letters(sample_letter_template)
|
||||
|
||||
|
||||
def test_should_return_notifications_excluding_jobs_by_default(sample_template, sample_job, sample_api_key):
|
||||
with_job = create_notification(sample_template, job=sample_job)
|
||||
create_notification(sample_template, job=sample_job)
|
||||
without_job = create_notification(sample_template, api_key=sample_api_key)
|
||||
|
||||
include_jobs = get_notifications_for_service(sample_template.service_id, include_jobs=True).items
|
||||
|
||||
@@ -4,7 +4,6 @@ import pytest
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
|
||||
from app import encryption
|
||||
from app.dao.api_key_dao import (save_model_api_key,
|
||||
get_model_api_keys,
|
||||
get_unsigned_secrets,
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import uuid
|
||||
|
||||
import pytest
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ def test_get_all_inbound_sms_when_none_exist(sample_service):
|
||||
|
||||
def test_get_all_inbound_sms_limits_and_orders(sample_service):
|
||||
with freeze_time('2017-01-01'):
|
||||
one = create_inbound_sms(sample_service)
|
||||
create_inbound_sms(sample_service)
|
||||
with freeze_time('2017-01-03'):
|
||||
three = create_inbound_sms(sample_service)
|
||||
with freeze_time('2017-01-02'):
|
||||
@@ -48,7 +48,7 @@ def test_get_all_inbound_sms_filters_on_service(notify_db_session):
|
||||
service_two = create_service(service_name='two')
|
||||
|
||||
sms_one = create_inbound_sms(service_one)
|
||||
sms_two = create_inbound_sms(service_two)
|
||||
create_inbound_sms(service_two)
|
||||
|
||||
res = dao_get_inbound_sms_for_service(service_one.id)
|
||||
assert len(res) == 1
|
||||
|
||||
@@ -359,7 +359,7 @@ def test_get_jobs_for_service_doesnt_return_test_messages(
|
||||
sample_job,
|
||||
file_name,
|
||||
):
|
||||
test_job = create_job(
|
||||
create_job(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
sample_template.service,
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
import pytest
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
|
||||
from app.dao.organisations_dao import (
|
||||
dao_create_organisation,
|
||||
dao_get_organisations,
|
||||
dao_get_organisation_by_id,
|
||||
dao_update_organisation,
|
||||
@@ -49,7 +45,7 @@ def test_get_organisation_by_id_gets_correct_organisation(notify_db, notify_db_s
|
||||
|
||||
def test_update_organisation(notify_db, notify_db_session):
|
||||
updated_name = 'new name'
|
||||
organisation = create_organisation()
|
||||
create_organisation()
|
||||
|
||||
organisations_1 = Organisation.query.all()
|
||||
|
||||
|
||||
@@ -67,8 +67,6 @@ def test_can_get_email_providers(restore_provider_details):
|
||||
|
||||
|
||||
def test_should_not_error_if_any_provider_in_code_not_in_database(restore_provider_details):
|
||||
providers = ProviderDetails.query.all()
|
||||
|
||||
ProviderDetails.query.filter_by(identifier='mmg').delete()
|
||||
|
||||
assert clients.get_sms_client('mmg')
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
from decimal import Decimal
|
||||
from app.dao.provider_rates_dao import create_provider_rates
|
||||
|
||||
@@ -39,7 +39,7 @@ def test_add_reply_to_email_address_for_service_creates_first_email_for_service(
|
||||
|
||||
def test_add_reply_to_email_address_for_service_creates_another_email_for_service(notify_db_session):
|
||||
service = create_service()
|
||||
first_reply_to = create_reply_to_email(service=service, email_address="first@address.com")
|
||||
create_reply_to_email(service=service, email_address="first@address.com")
|
||||
|
||||
add_reply_to_email_address_for_service(service_id=service.id, email_address='second@address.com', is_default=False)
|
||||
|
||||
@@ -56,7 +56,7 @@ def test_add_reply_to_email_address_for_service_creates_another_email_for_servic
|
||||
|
||||
def test_add_reply_to_email_address_new_reply_to_is_default_existing_reply_to_is_not(notify_db_session):
|
||||
service = create_service()
|
||||
first_reply_to = create_reply_to_email(service=service, email_address="first@address.com", is_default=True)
|
||||
create_reply_to_email(service=service, email_address="first@address.com", is_default=True)
|
||||
add_reply_to_email_address_for_service(service_id=service.id, email_address='second@address.com', is_default=True)
|
||||
|
||||
results = dao_get_reply_to_by_service_id(service_id=service.id)
|
||||
@@ -121,7 +121,7 @@ def test_update_reply_to_email_address(sample_service):
|
||||
|
||||
|
||||
def test_update_reply_to_email_address_set_updated_to_default(sample_service):
|
||||
first_reply_to = create_reply_to_email(service=sample_service, email_address="first@address.com")
|
||||
create_reply_to_email(service=sample_service, email_address="first@address.com")
|
||||
second_reply_to = create_reply_to_email(service=sample_service,
|
||||
email_address="second@address.com",
|
||||
is_default=False)
|
||||
|
||||
@@ -121,6 +121,7 @@ def test_dao_update_service_sms_sender_raises_exception_when_no_default_after_up
|
||||
service_sms_sender_id=sms_sender.id,
|
||||
is_default=False,
|
||||
sms_sender="updated")
|
||||
assert 'You must have at least one SMS sender as the default' in str(e.value)
|
||||
|
||||
|
||||
def test_update_existing_sms_sender_with_inbound_number(notify_db_session):
|
||||
|
||||
@@ -2,7 +2,8 @@ import uuid
|
||||
|
||||
from app.models import (
|
||||
ServiceWhitelist,
|
||||
MOBILE_TYPE, EMAIL_TYPE)
|
||||
EMAIL_TYPE,
|
||||
)
|
||||
|
||||
from app.dao.service_whitelist_dao import (
|
||||
dao_fetch_service_whitelist,
|
||||
|
||||
@@ -590,13 +590,16 @@ def test_fetch_stats_counts_should_ignore_team_key(
|
||||
def test_fetch_stats_for_today_only_includes_today(notify_db, notify_db_session, sample_template):
|
||||
# two created email, one failed email, and one created sms
|
||||
with freeze_time('2001-01-01T23:59:00'):
|
||||
just_before_midnight_yesterday = create_notification(notify_db, None, to_field='1', status='delivered')
|
||||
# just_before_midnight_yesterday
|
||||
create_notification(notify_db, None, to_field='1', status='delivered')
|
||||
|
||||
with freeze_time('2001-01-02T00:01:00'):
|
||||
just_after_midnight_today = create_notification(notify_db, None, to_field='2', status='failed')
|
||||
# just_after_midnight_today
|
||||
create_notification(notify_db, None, to_field='2', status='failed')
|
||||
|
||||
with freeze_time('2001-01-02T12:00:00'):
|
||||
right_now = create_notification(notify_db, None, to_field='3', status='created')
|
||||
# right_now
|
||||
create_notification(notify_db, None, to_field='3', status='created')
|
||||
|
||||
stats = dao_fetch_todays_stats_for_service(sample_template.service_id)
|
||||
|
||||
@@ -613,14 +616,22 @@ def test_fetch_monthly_historical_stats_separates_months(notify_db, notify_db_se
|
||||
notify_db_session,
|
||||
sample_template
|
||||
)
|
||||
_before_start_of_financial_year = notification_history(created_at=datetime(2016, 3, 31))
|
||||
start_of_financial_year = notification_history(created_at=datetime(2016, 4, 1))
|
||||
start_of_summer = notification_history(created_at=datetime(2016, 6, 20))
|
||||
start_of_autumn = notification_history(created_at=datetime(2016, 9, 30, 23, 30, 0)) # October because BST
|
||||
start_of_winter = notification_history(created_at=datetime(2016, 12, 1), status='delivered')
|
||||
start_of_spring = notification_history(created_at=datetime(2017, 3, 11))
|
||||
end_of_financial_year = notification_history(created_at=datetime(2017, 3, 31))
|
||||
_after_end_of_financial_year = notification_history(created_at=datetime(2017, 3, 31, 23, 30)) # after because BST
|
||||
# _before_start_of_financial_year
|
||||
notification_history(created_at=datetime(2016, 3, 31))
|
||||
# start_of_financial_year
|
||||
notification_history(created_at=datetime(2016, 4, 1))
|
||||
# start_of_summer
|
||||
notification_history(created_at=datetime(2016, 6, 20))
|
||||
# start_of_autumn
|
||||
notification_history(created_at=datetime(2016, 9, 30, 23, 30, 0)) # October because BST
|
||||
# start_of_winter
|
||||
notification_history(created_at=datetime(2016, 12, 1), status='delivered')
|
||||
# start_of_spring
|
||||
notification_history(created_at=datetime(2017, 3, 11))
|
||||
# end_of_financial_year
|
||||
notification_history(created_at=datetime(2017, 3, 31))
|
||||
# _after_end_of_financial_year
|
||||
notification_history(created_at=datetime(2017, 3, 31, 23, 30)) # after because BST
|
||||
|
||||
result = dao_fetch_monthly_historical_stats_for_service(sample_template.service_id, 2016)
|
||||
|
||||
@@ -687,10 +698,12 @@ def test_dao_fetch_todays_stats_for_all_services_includes_all_services(notify_db
|
||||
|
||||
def test_dao_fetch_todays_stats_for_all_services_only_includes_today(notify_db, notify_db_session):
|
||||
with freeze_time('2001-01-01T23:59:00'):
|
||||
just_before_midnight_yesterday = create_notification(notify_db, None, to_field='1', status='delivered')
|
||||
# just_before_midnight_yesterday
|
||||
create_notification(notify_db, None, to_field='1', status='delivered')
|
||||
|
||||
with freeze_time('2001-01-02T00:01:00'):
|
||||
just_after_midnight_today = create_notification(notify_db, None, to_field='2', status='failed')
|
||||
# just_after_midnight_today
|
||||
create_notification(notify_db, None, to_field='2', status='failed')
|
||||
|
||||
with freeze_time('2001-01-02T12:00:00'):
|
||||
stats = dao_fetch_todays_stats_for_all_services()
|
||||
|
||||
@@ -13,12 +13,18 @@ from app.models import (
|
||||
SMS_TYPE,
|
||||
EMAIL_TYPE,
|
||||
LETTER_TYPE,
|
||||
NOTIFICATION_STATUS_TYPES,
|
||||
NOTIFICATION_CREATED,
|
||||
NOTIFICATION_DELIVERED,
|
||||
NOTIFICATION_FAILED,
|
||||
NOTIFICATION_PENDING,
|
||||
NOTIFICATION_PERMANENT_FAILURE,
|
||||
NOTIFICATION_SENDING,
|
||||
NOTIFICATION_SENT,
|
||||
NOTIFICATION_STATUS_SUCCESS,
|
||||
NOTIFICATION_TECHNICAL_FAILURE,
|
||||
NOTIFICATION_TEMPORARY_FAILURE,
|
||||
NOTIFICATION_PERMANENT_FAILURE,
|
||||
NOTIFICATION_PENDING, NOTIFICATION_CREATED, NOTIFICATION_FAILED, NOTIFICATION_SENT, NOTIFICATION_SENDING,
|
||||
NOTIFICATION_STATUS_TYPES_COMPLETED, Notification, NOTIFICATION_STATUS_TYPES, NOTIFICATION_STATUS_SUCCESS)
|
||||
)
|
||||
from tests.app.conftest import sample_notification, sample_email_template, sample_template, sample_job, sample_service
|
||||
|
||||
|
||||
|
||||
@@ -133,7 +133,7 @@ def test_get_all_templates_for_service(notify_db, notify_db_session, service_fac
|
||||
assert len(dao_get_all_templates_for_service(service_1.id)) == 1
|
||||
assert len(dao_get_all_templates_for_service(service_2.id)) == 1
|
||||
|
||||
template_1 = create_sample_template(
|
||||
create_sample_template(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
template_name='Sample Template 1',
|
||||
@@ -141,7 +141,7 @@ def test_get_all_templates_for_service(notify_db, notify_db_session, service_fac
|
||||
content="Template content",
|
||||
service=service_1
|
||||
)
|
||||
template_2 = create_sample_template(
|
||||
create_sample_template(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
template_name='Sample Template 2',
|
||||
@@ -149,7 +149,7 @@ def test_get_all_templates_for_service(notify_db, notify_db_session, service_fac
|
||||
content="Template content",
|
||||
service=service_1
|
||||
)
|
||||
template_3 = create_sample_template(
|
||||
create_sample_template(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
template_name='Sample Template 3',
|
||||
@@ -164,7 +164,7 @@ def test_get_all_templates_for_service(notify_db, notify_db_session, service_fac
|
||||
|
||||
|
||||
def test_get_all_templates_for_service_is_alphabetised(notify_db, notify_db_session, sample_service):
|
||||
template_1 = create_sample_template(
|
||||
create_sample_template(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
template_name='Sample Template 1',
|
||||
@@ -180,7 +180,7 @@ def test_get_all_templates_for_service_is_alphabetised(notify_db, notify_db_sess
|
||||
content="Template content",
|
||||
service=sample_service
|
||||
)
|
||||
template_3 = create_sample_template(
|
||||
create_sample_template(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
template_name='Sample Template 3',
|
||||
|
||||
Reference in New Issue
Block a user