mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 17:31:14 -05:00
Return financial year not calendar and ensure double precision values
are not returned from queries - Updated stats_template_usage_by_month_dao.py to return the results for financial year not calendar, as the report os for FY only and hence only the FY data is required - Updated services_dao.py to ensure double precision values are converted to an int as the 'exact' function returns double precision from the database query, as the admin code requires the value for month to be an int
This commit is contained in:
@@ -1380,3 +1380,151 @@ def test_dao_fetch_monthly_historical_usage_by_template_for_service_combined_his
|
||||
assert result[1].month == 11
|
||||
assert result[1].year == 2017
|
||||
assert result[1].count == 1
|
||||
|
||||
|
||||
@freeze_time("2017-11-10 11:09:00.000000")
|
||||
def test_dao_fetch_monthly_historical_usage_by_template_for_service_does_not_return_double_precision_values(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
sample_service
|
||||
):
|
||||
|
||||
template_one = create_sample_template(notify_db, notify_db_session, template_name='1')
|
||||
|
||||
n = create_notification(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
service=sample_service,
|
||||
template=template_one,
|
||||
created_at=datetime.utcnow()
|
||||
)
|
||||
|
||||
result = sorted(
|
||||
dao_fetch_monthly_historical_usage_by_template_for_service(n.service_id, 2017),
|
||||
key=lambda x: (x.month, x.year)
|
||||
)
|
||||
|
||||
assert len(result) == 1
|
||||
|
||||
assert result[0].template_id == template_one.id
|
||||
assert result[0].name == template_one.name
|
||||
assert result[0].template_type == template_one.template_type
|
||||
assert result[0].month == 11
|
||||
assert len(str(result[0].month)) == 2
|
||||
assert result[0].year == 2017
|
||||
assert len(str(result[0].year)) == 4
|
||||
assert result[0].count == 1
|
||||
|
||||
|
||||
@freeze_time("2018-03-10 11:09:00.000000")
|
||||
def test_dao_fetch_monthly_historical_usage_by_template_for_service_returns_financial_year(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
sample_service
|
||||
):
|
||||
template_one = create_sample_template(notify_db, notify_db_session, template_name='1', template_type='email')
|
||||
|
||||
notification_history = functools.partial(
|
||||
create_notification_history,
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
status='delivered',
|
||||
sample_template=template_one
|
||||
)
|
||||
|
||||
date = datetime.now()
|
||||
day = date.day
|
||||
year = date.year
|
||||
|
||||
notification_history(created_at=datetime(year - 1, 1, day))
|
||||
notification_history(created_at=datetime(year - 1, 3, day))
|
||||
notification_history(created_at=datetime(year - 1, 4, day))
|
||||
notification_history(created_at=datetime(year - 1, 5, day))
|
||||
notification_history(created_at=datetime(year, 1, day))
|
||||
notification_history(created_at=datetime(year, 2, day))
|
||||
|
||||
daily_stats_template_usage_by_month()
|
||||
|
||||
n = create_notification(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
service=sample_service,
|
||||
template=template_one,
|
||||
created_at=datetime.utcnow()
|
||||
)
|
||||
|
||||
result = sorted(
|
||||
dao_fetch_monthly_historical_usage_by_template_for_service(n.service_id, 2017),
|
||||
key=lambda x: (x.year, x.month)
|
||||
)
|
||||
|
||||
assert len(result) == 5
|
||||
|
||||
assert result[0].month == 4
|
||||
assert result[0].year == 2017
|
||||
assert result[1].month == 5
|
||||
assert result[1].year == 2017
|
||||
assert result[2].month == 1
|
||||
assert result[2].year == 2018
|
||||
assert result[3].month == 2
|
||||
assert result[3].year == 2018
|
||||
assert result[4].month == 3
|
||||
assert result[4].year == 2018
|
||||
|
||||
|
||||
@freeze_time("2018-03-10 11:09:00.000000")
|
||||
def test_dao_fetch_monthly_historical_usage_by_template_for_service_only_returns_for_service(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
sample_service
|
||||
):
|
||||
template_one = create_sample_template(notify_db, notify_db_session, template_name='1', template_type='email')
|
||||
|
||||
notification_history = functools.partial(
|
||||
create_notification_history,
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
status='delivered',
|
||||
sample_template=template_one
|
||||
)
|
||||
|
||||
date = datetime.now()
|
||||
day = date.day
|
||||
year = date.year
|
||||
|
||||
notification_history(created_at=datetime(year, 1, day))
|
||||
notification_history(created_at=datetime(year, 2, day))
|
||||
|
||||
service_two = create_service(service_name='other_service')
|
||||
|
||||
daily_stats_template_usage_by_month()
|
||||
|
||||
n = create_notification(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
service=sample_service,
|
||||
template=template_one,
|
||||
created_at=datetime.utcnow()
|
||||
)
|
||||
|
||||
create_notification(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
service=service_two,
|
||||
template=template_one,
|
||||
created_at=datetime.utcnow()
|
||||
)
|
||||
|
||||
result = sorted(
|
||||
dao_fetch_monthly_historical_usage_by_template_for_service(n.service_id, 2017),
|
||||
key=lambda x: (x.year, x.month)
|
||||
)
|
||||
|
||||
assert len(result) == 3
|
||||
|
||||
result = sorted(
|
||||
dao_fetch_monthly_historical_usage_by_template_for_service(service_two.id, 2017),
|
||||
key=lambda x: (x.year, x.month)
|
||||
)
|
||||
|
||||
assert len(result) == 1
|
||||
|
||||
@@ -51,55 +51,75 @@ def test_dao_get_template_usage_stats_by_service(sample_service):
|
||||
|
||||
email_template = create_template(service=sample_service, template_type="email")
|
||||
|
||||
stats1 = StatsTemplateUsageByMonth(
|
||||
new_service = create_service(service_name="service_one")
|
||||
|
||||
template_new_service = create_template(service=new_service)
|
||||
|
||||
db.session.add(StatsTemplateUsageByMonth(
|
||||
template_id=email_template.id,
|
||||
month=1,
|
||||
month=4,
|
||||
year=2017,
|
||||
count=10
|
||||
)
|
||||
))
|
||||
|
||||
stats2 = StatsTemplateUsageByMonth(
|
||||
template_id=email_template.id,
|
||||
month=2,
|
||||
db.session.add(StatsTemplateUsageByMonth(
|
||||
template_id=template_new_service.id,
|
||||
month=4,
|
||||
year=2017,
|
||||
count=10
|
||||
)
|
||||
|
||||
db.session.add(stats1)
|
||||
db.session.add(stats2)
|
||||
))
|
||||
|
||||
result = dao_get_template_usage_stats_by_service(sample_service.id, 2017)
|
||||
|
||||
assert len(result) == 2
|
||||
assert len(result) == 1
|
||||
|
||||
|
||||
def test_dao_get_template_usage_stats_by_service_specific_year(sample_service):
|
||||
|
||||
email_template = create_template(service=sample_service, template_type="email")
|
||||
|
||||
stats1 = StatsTemplateUsageByMonth(
|
||||
db.session.add(StatsTemplateUsageByMonth(
|
||||
template_id=email_template.id,
|
||||
month=1,
|
||||
year=2016,
|
||||
count=10
|
||||
)
|
||||
|
||||
stats2 = StatsTemplateUsageByMonth(
|
||||
template_id=email_template.id,
|
||||
month=2,
|
||||
month=3,
|
||||
year=2017,
|
||||
count=10
|
||||
)
|
||||
))
|
||||
|
||||
db.session.add(stats1)
|
||||
db.session.add(stats2)
|
||||
db.session.add(StatsTemplateUsageByMonth(
|
||||
template_id=email_template.id,
|
||||
month=4,
|
||||
year=2017,
|
||||
count=10
|
||||
))
|
||||
|
||||
db.session.add(StatsTemplateUsageByMonth(
|
||||
template_id=email_template.id,
|
||||
month=3,
|
||||
year=2018,
|
||||
count=10
|
||||
))
|
||||
|
||||
db.session.add(StatsTemplateUsageByMonth(
|
||||
template_id=email_template.id,
|
||||
month=4,
|
||||
year=2018,
|
||||
count=10
|
||||
))
|
||||
|
||||
result = dao_get_template_usage_stats_by_service(sample_service.id, 2017)
|
||||
|
||||
assert len(result) == 1
|
||||
assert len(result) == 2
|
||||
|
||||
assert result[0].template_id == email_template.id
|
||||
assert result[0].name == email_template.name
|
||||
assert result[0].template_type == email_template.template_type
|
||||
assert result[0].month == 2
|
||||
assert result[0].month == 4
|
||||
assert result[0].year == 2017
|
||||
assert result[0].count == 10
|
||||
|
||||
assert result[1].template_id == email_template.id
|
||||
assert result[1].name == email_template.name
|
||||
assert result[1].template_type == email_template.template_type
|
||||
assert result[1].month == 3
|
||||
assert result[1].year == 2018
|
||||
assert result[1].count == 10
|
||||
|
||||
Reference in New Issue
Block a user