mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-19 14:08:47 -04:00
use freeze_time whenever we mess with dates
also fixed a gotcha where an object was created in a fixture, so the freezetime decorator didn't apply
This commit is contained in:
@@ -459,9 +459,9 @@ def test_fetch_weekly_historical_stats_separates_weeks(notify_db, notify_db_sess
|
|||||||
last_sunday = notification_history(created_at=datetime(2016, 7, 24, 23, 59))
|
last_sunday = notification_history(created_at=datetime(2016, 7, 24, 23, 59))
|
||||||
last_monday_morning = notification_history(created_at=datetime(2016, 7, 25, 0, 0))
|
last_monday_morning = notification_history(created_at=datetime(2016, 7, 25, 0, 0))
|
||||||
last_monday_evening = notification_history(created_at=datetime(2016, 7, 25, 23, 59))
|
last_monday_evening = notification_history(created_at=datetime(2016, 7, 25, 23, 59))
|
||||||
today = notification_history(created_at=datetime.now(), status='delivered')
|
|
||||||
|
|
||||||
with freeze_time('Wed 27th July 2016'):
|
with freeze_time('Wed 27th July 2016'):
|
||||||
|
today = notification_history(created_at=datetime.now(), status='delivered')
|
||||||
ret = dao_fetch_weekly_historical_stats_for_service(sample_template.service_id)
|
ret = dao_fetch_weekly_historical_stats_for_service(sample_template.service_id)
|
||||||
|
|
||||||
assert [(row.week_start, row.status) for row in ret] == [
|
assert [(row.week_start, row.status) for row in ret] == [
|
||||||
|
|||||||
@@ -1123,18 +1123,19 @@ def test_get_detailed_service(notify_db, notify_db_session, notify_api, sample_s
|
|||||||
assert service['statistics']['sms'] == stats
|
assert service['statistics']['sms'] == stats
|
||||||
|
|
||||||
|
|
||||||
@freeze_time('2016-07-28')
|
def test_get_weekly_notification_stats(notify_api, notify_db, notify_db_session):
|
||||||
def test_get_weekly_notification_stats(notify_api, sample_notification):
|
with freeze_time('2000-01-01T12:00:00'):
|
||||||
with notify_api.test_request_context(), notify_api.test_client() as client:
|
noti = create_sample_notification(notify_db, notify_db_session)
|
||||||
|
with notify_api.test_request_context(), notify_api.test_client() as client, freeze_time('2000-01-02T12:00:00'):
|
||||||
resp = client.get(
|
resp = client.get(
|
||||||
'/service/{}/notifications/weekly'.format(sample_notification.service_id),
|
'/service/{}/notifications/weekly'.format(noti.service_id),
|
||||||
headers=[create_authorization_header()]
|
headers=[create_authorization_header()]
|
||||||
)
|
)
|
||||||
|
|
||||||
assert resp.status_code == 200
|
assert resp.status_code == 200
|
||||||
data = json.loads(resp.get_data(as_text=True))['data']
|
data = json.loads(resp.get_data(as_text=True))['data']
|
||||||
assert data == {
|
assert data == {
|
||||||
'2016-07-25': {
|
'1999-12-27': {
|
||||||
'sms': {
|
'sms': {
|
||||||
'requested': 1,
|
'requested': 1,
|
||||||
'delivered': 0,
|
'delivered': 0,
|
||||||
|
|||||||
Reference in New Issue
Block a user