mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 23:55:58 -05:00
Merge branch 'master' into primary-provider
Conflicts: app/dao/notifications_dao.py app/dao/provider_statistics_dao.py app/schemas.py tests/app/conftest.py
This commit is contained in:
122
tests/app/dao/test_notification_statistics_dao.py
Normal file
122
tests/app/dao/test_notification_statistics_dao.py
Normal file
@@ -0,0 +1,122 @@
|
||||
from datetime import (date, timedelta)
|
||||
|
||||
from app.models import NotificationStatistics
|
||||
from tests.app.conftest import sample_notification_statistics as create_sample_notification_statistics
|
||||
from app.dao.notifications_dao import dao_get_7_day_agg_notification_statistics_for_service
|
||||
|
||||
|
||||
def test_display_weekly_notification_statistics_sum_over_week(notify_db,
|
||||
notify_db_session,
|
||||
sample_service):
|
||||
fools = date(2016, 4, 1)
|
||||
create_sample_notification_statistics(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
day=fools
|
||||
)
|
||||
create_sample_notification_statistics(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
day=fools + timedelta(days=1)
|
||||
)
|
||||
assert dao_get_7_day_agg_notification_statistics_for_service(
|
||||
sample_service.id,
|
||||
fools
|
||||
).all() == [(0, 4, 2, 2, 4, 2, 2)]
|
||||
|
||||
|
||||
def test_display_weekly_notification_statistics_separate_over_weeks(notify_db,
|
||||
notify_db_session,
|
||||
sample_service):
|
||||
fools = date(2016, 4, 1)
|
||||
next_week = fools + timedelta(days=7)
|
||||
create_sample_notification_statistics(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
day=fools
|
||||
)
|
||||
create_sample_notification_statistics(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
day=next_week
|
||||
)
|
||||
assert dao_get_7_day_agg_notification_statistics_for_service(
|
||||
sample_service.id,
|
||||
fools
|
||||
).all() == [(1, 2, 1, 1, 2, 1, 1), (0, 2, 1, 1, 2, 1, 1)]
|
||||
|
||||
|
||||
def test_display_weekly_notification_statistics_7_days_from_date_from(notify_db,
|
||||
notify_db_session,
|
||||
sample_service):
|
||||
fools = date(2016, 4, 1)
|
||||
eow_fools = fools + timedelta(days=6)
|
||||
next_week = fools + timedelta(days=7)
|
||||
two_weeks_later = fools + timedelta(days=14)
|
||||
create_sample_notification_statistics(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
day=fools
|
||||
)
|
||||
create_sample_notification_statistics(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
day=eow_fools
|
||||
)
|
||||
create_sample_notification_statistics(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
day=next_week
|
||||
)
|
||||
create_sample_notification_statistics(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
day=two_weeks_later
|
||||
)
|
||||
assert dao_get_7_day_agg_notification_statistics_for_service(
|
||||
sample_service.id,
|
||||
fools
|
||||
).all() == [(2, 2, 1, 1, 2, 1, 1), (1, 2, 1, 1, 2, 1, 1), (0, 4, 2, 2, 4, 2, 2)]
|
||||
|
||||
|
||||
def test_display_weekly_notification_statistics_week_number_misses_week(notify_db,
|
||||
notify_db_session,
|
||||
sample_service):
|
||||
fools = date(2016, 4, 1)
|
||||
two_weeks_later = fools + timedelta(days=14)
|
||||
create_sample_notification_statistics(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
day=fools
|
||||
)
|
||||
create_sample_notification_statistics(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
day=two_weeks_later
|
||||
)
|
||||
assert dao_get_7_day_agg_notification_statistics_for_service(
|
||||
sample_service.id,
|
||||
fools
|
||||
).all() == [(2, 2, 1, 1, 2, 1, 1), (0, 2, 1, 1, 2, 1, 1)]
|
||||
|
||||
|
||||
def test_display_weekly_notification_statistics_week_limit(notify_db,
|
||||
notify_db_session,
|
||||
sample_service):
|
||||
fools = date(2016, 4, 1)
|
||||
two_weeks_later = fools + timedelta(days=14)
|
||||
create_sample_notification_statistics(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
day=fools
|
||||
)
|
||||
create_sample_notification_statistics(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
day=two_weeks_later
|
||||
)
|
||||
assert dao_get_7_day_agg_notification_statistics_for_service(
|
||||
sample_service.id,
|
||||
fools,
|
||||
1
|
||||
).all() == [(0, 2, 1, 1, 2, 1, 1)]
|
||||
@@ -8,10 +8,24 @@ from app.dao.services_dao import (
|
||||
dao_fetch_service_by_id,
|
||||
dao_fetch_all_services_by_user,
|
||||
dao_fetch_service_by_id_and_user,
|
||||
dao_update_service
|
||||
dao_update_service,
|
||||
delete_service_and_all_associated_db_objects
|
||||
)
|
||||
from app.dao.users_dao import save_model_user
|
||||
from app.models import Service, User
|
||||
from app.models import (
|
||||
NotificationStatistics,
|
||||
TemplateStatistics,
|
||||
ProviderStatistics,
|
||||
VerifyCode,
|
||||
ApiKey,
|
||||
Template,
|
||||
Job,
|
||||
Notification,
|
||||
Permission,
|
||||
User,
|
||||
InvitedUser,
|
||||
Service
|
||||
)
|
||||
from sqlalchemy.orm.exc import FlushError, NoResultFound
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
|
||||
@@ -287,3 +301,32 @@ def test_create_service_and_history_is_transactional(sample_user):
|
||||
assert 'column "name" violates not-null constraint' in str(excinfo.value)
|
||||
assert Service.query.count() == 0
|
||||
assert Service.get_history_model().query.count() == 0
|
||||
|
||||
|
||||
def test_delete_service_and_associated_objects(notify_db,
|
||||
notify_db_session,
|
||||
sample_user,
|
||||
sample_service,
|
||||
sample_email_code,
|
||||
sample_sms_code,
|
||||
sample_template,
|
||||
sample_email_template,
|
||||
sample_api_key,
|
||||
sample_job,
|
||||
sample_notification,
|
||||
sample_invited_user,
|
||||
sample_permission,
|
||||
sample_provider_statistics):
|
||||
delete_service_and_all_associated_db_objects(sample_service)
|
||||
assert NotificationStatistics.query.count() == 0
|
||||
assert TemplateStatistics.query.count() == 0
|
||||
assert ProviderStatistics.query.count() == 0
|
||||
assert VerifyCode.query.count() == 0
|
||||
assert ApiKey.query.count() == 0
|
||||
assert Template.query.count() == 0
|
||||
assert Job.query.count() == 0
|
||||
assert Notification.query.count() == 0
|
||||
assert Permission.query.count() == 0
|
||||
assert User.query.count() == 0
|
||||
assert InvitedUser.query.count() == 0
|
||||
assert Service.query.count() == 0
|
||||
|
||||
@@ -218,3 +218,15 @@ def test_update_template_creates_a_history_record_with_current_data(sample_servi
|
||||
|
||||
assert Template.get_history_model().query.filter_by(name='Sample Template').one().version == 1
|
||||
assert Template.get_history_model().query.filter_by(name='new name').one().version == 2
|
||||
|
||||
|
||||
def test_get_template_history_version(sample_user, sample_service, sample_template):
|
||||
old_content = sample_template.content
|
||||
sample_template.content = "New content"
|
||||
dao_update_template(sample_template)
|
||||
old_template = dao_get_template_by_id_and_service_id(
|
||||
sample_template.id,
|
||||
sample_service.id,
|
||||
'1'
|
||||
)
|
||||
assert old_template.content == old_content
|
||||
|
||||
Reference in New Issue
Block a user