make inbound sms page respect data retention

also, it should default to last 7 days, not last 6 days. also change
count_inbound_sms to have the days passed in, so that it's more
explicit at the endpoint that we only return 7 days regardless of your
service's data retention
This commit is contained in:
Leo Hemsted
2019-03-27 17:44:53 +00:00
parent b764eae738
commit 97110e293b
4 changed files with 59 additions and 39 deletions

View File

@@ -76,15 +76,17 @@ def test_count_inbound_sms_for_service(notify_db_session):
create_inbound_sms(service_one)
create_inbound_sms(service_two)
assert dao_count_inbound_sms_for_service(service_one.id) == 2
assert dao_count_inbound_sms_for_service(service_one.id, limit_days=1) == 2
def test_count_inbound_sms_for_service_filters_messages_older_than_seven_days(sample_service, notify_db_session):
create_inbound_sms(sample_service, user_number='447700900111', content='111 2', created_at=datetime(2017, 1, 2))
create_inbound_sms(sample_service, user_number='447700900111', content='111 2', created_at=datetime(2017, 1, 3))
def test_count_inbound_sms_for_service_filters_messages_older_than_n_days(sample_service):
# test between evening sunday 2nd of june and morning of monday 3rd
create_inbound_sms(sample_service, created_at=datetime(2019, 6, 2, 22, 59))
create_inbound_sms(sample_service, created_at=datetime(2019, 6, 2, 22, 59))
create_inbound_sms(sample_service, created_at=datetime(2019, 6, 2, 23, 1))
with freeze_time('2017-01-09'):
assert dao_count_inbound_sms_for_service(sample_service.id) == 1
with freeze_time('Monday 10th June 2019 12:00'):
assert dao_count_inbound_sms_for_service(sample_service.id, limit_days=7) == 1
@freeze_time("2017-06-08 12:00:00")
@@ -222,7 +224,7 @@ def test_most_recent_inbound_sms_only_returns_most_recent_for_each_number(notify
with set_config(notify_api, 'PAGE_SIZE', 3):
with freeze_time('2017-01-02'):
res = dao_get_paginated_most_recent_inbound_sms_by_user_number_for_service(sample_service.id, page=1)
res = dao_get_paginated_most_recent_inbound_sms_by_user_number_for_service(sample_service.id, limit_days=7, page=1) # noqa
assert len(res.items) == 2
assert res.has_next is False
@@ -244,7 +246,7 @@ def test_most_recent_inbound_sms_paginates_properly(notify_api, sample_service):
with set_config(notify_api, 'PAGE_SIZE', 2):
with freeze_time('2017-01-02'):
# first page has most recent 444 and 333
res = dao_get_paginated_most_recent_inbound_sms_by_user_number_for_service(sample_service.id, page=1)
res = dao_get_paginated_most_recent_inbound_sms_by_user_number_for_service(sample_service.id, limit_days=7, page=1) # noqa
assert len(res.items) == 2
assert res.has_next is True
assert res.per_page == 2
@@ -252,30 +254,21 @@ def test_most_recent_inbound_sms_paginates_properly(notify_api, sample_service):
assert res.items[1].content == '333 2'
# second page has no 444 or 333 - just most recent 222 and 111
res = dao_get_paginated_most_recent_inbound_sms_by_user_number_for_service(sample_service.id, page=2)
res = dao_get_paginated_most_recent_inbound_sms_by_user_number_for_service(sample_service.id, limit_days=7, page=2) # noqa
assert len(res.items) == 2
assert res.has_next is False
assert res.items[0].content == '222 2'
assert res.items[1].content == '111 2'
def test_most_recent_inbound_sms_only_returns_values_within_7_days(notify_api, sample_service):
create_inbound_sms(sample_service, user_number='447700900111', content='111 1', created_at=datetime(2017, 4, 1))
create_inbound_sms(sample_service, user_number='447700900111', content='111 2', created_at=datetime(2017, 4, 1))
create_inbound_sms(sample_service, user_number='447700900222', content='222 1', created_at=datetime(2017, 4, 1))
create_inbound_sms(sample_service, user_number='447700900222', content='222 2', created_at=datetime(2017, 4, 1))
create_inbound_sms(sample_service, user_number='447700900333', content='333 1', created_at=datetime(2017, 4, 2))
create_inbound_sms(sample_service, user_number='447700900333', content='333 2', created_at=datetime(2017, 4, 3))
create_inbound_sms(sample_service, user_number='447700900444', content='444 1', created_at=datetime(2017, 4, 4))
create_inbound_sms(sample_service, user_number='447700900444', content='444 2', created_at=datetime(2017, 4, 5))
def test_most_recent_inbound_sms_only_returns_values_within_7_days(sample_service):
# just out of bounds
create_inbound_sms(sample_service, user_number='1', content='old', created_at=datetime(2017, 4, 2, 22, 59, 59))
# just in bounds
create_inbound_sms(sample_service, user_number='2', content='new', created_at=datetime(2017, 4, 2, 23, 0, 0))
# 7 days ago BST midnight
create_inbound_sms(sample_service, user_number='447700900666', content='666 1', created_at='2017-04-02T23:00:00')
with freeze_time('Monday 10th April 2017 12:00:00'):
res = dao_get_paginated_most_recent_inbound_sms_by_user_number_for_service(sample_service.id, limit_days=7, page=1) # noqa
with freeze_time('2017-04-09T12:00:00'):
res = dao_get_paginated_most_recent_inbound_sms_by_user_number_for_service(sample_service.id, page=1)
assert len(res.items) == 3
assert res.items[0].content == '444 2'
assert res.items[1].content == '333 2'
assert res.items[2].content == '666 1'
assert len(res.items) == 1
assert res.items[0].content == 'new'