Updates after review

- Modified the services_dao to return an int instead of a datetime to
make usage easier and removed the BST function on year as it is not
relevant for year
- Improved tests do there is less logic by ordering the result so there
is less reliance on the template id
- Renamed variable in stats_template_usage_by_month_dao.py to make it
consistent with the method
This commit is contained in:
Richard Chapman
2017-11-09 14:13:42 +00:00
parent 59df6bdbb6
commit b78d989d4e
14 changed files with 76 additions and 148 deletions

View File

@@ -1015,28 +1015,24 @@ def test_dao_fetch_monthly_historical_stats_by_template(notify_db, notify_db_ses
status='delivered'
)
template_one = create_sample_template(notify_db, notify_db_session)
template_two = create_sample_template(notify_db, notify_db_session)
template_one = create_sample_template(notify_db, notify_db_session, template_name='1')
template_two = create_sample_template(notify_db, notify_db_session, template_name='2')
notification_history(created_at=datetime(2017, 10, 1), sample_template=template_one)
notification_history(created_at=datetime(2016, 4, 1), sample_template=template_two)
notification_history(created_at=datetime(2016, 4, 1), sample_template=template_two)
notification_history(created_at=datetime.now(), sample_template=template_two)
results = dao_fetch_monthly_historical_stats_by_template()
result = sorted(dao_fetch_monthly_historical_stats_by_template(), key=lambda x: (x.month, x.year))
assert len(results) == 2
assert len(result) == 2
for result in results:
if result.template_id == template_one.id:
assert result.template_id == template_one.id
assert result.month.month == 10
assert result.year.year == 2017
assert result.count == 1
elif result.template_id == template_two.id:
assert result.template_id == template_two.id
assert result.month.month == 4
assert result.year.year == 2016
assert result.count == 2
else:
raise AssertionError()
assert result[0].template_id == template_two.id
assert result[0].month == 4
assert result[0].year == 2016
assert result[0].count == 2
assert result[1].template_id == template_one.id
assert result[1].month == 10
assert result[1].year == 2017
assert result[1].count == 1