Add tests for dao_get_paginated_inbound_sms_for_service

This commit is contained in:
Ken Tsang
2017-11-09 15:23:45 +00:00
parent 36fb2fb28c
commit 362072129f

View File

@@ -6,7 +6,8 @@ from app.dao.inbound_sms_dao import (
dao_get_inbound_sms_for_service,
dao_count_inbound_sms_for_service,
delete_inbound_sms_created_more_than_a_week_ago,
dao_get_inbound_sms_by_id
dao_get_inbound_sms_by_id,
dao_get_paginated_inbound_sms_for_service
)
from tests.app.db import create_inbound_sms, create_service
@@ -89,9 +90,83 @@ def test_should_not_delete_inbound_sms_before_seven_days(sample_service):
assert len(InboundSms.query.all()) == 2
def test_get_inbound_sms_by_id_returns(sample_service):
inbound = create_inbound_sms(sample_service)
def test_get_inbound_sms_by_id_returns(sample_inbound_sms):
inbound_from_db = dao_get_inbound_sms_by_id(sample_inbound_sms.service.id, sample_inbound_sms.id)
inbound_from_db = dao_get_inbound_sms_by_id(sample_service.id, inbound.id)
assert sample_inbound_sms == inbound_from_db
assert inbound == inbound_from_db
def test_dao_get_paginated_inbound_sms_for_service(sample_inbound_sms):
inbound_from_db = dao_get_paginated_inbound_sms_for_service(sample_inbound_sms.service.id)
assert sample_inbound_sms == inbound_from_db[0]
def test_dao_get_paginated_inbound_sms_for_service_return_only_for_service(sample_inbound_sms):
another_service = create_service(service_name='another service')
another_inbound_sms = create_inbound_sms(another_service)
inbound_from_db = dao_get_paginated_inbound_sms_for_service(sample_inbound_sms.service.id)
assert sample_inbound_sms in inbound_from_db
assert another_inbound_sms not in inbound_from_db
def test_dao_get_paginated_inbound_sms_for_service_no_inbound_sms_returns_empty_list(sample_service):
inbound_from_db = dao_get_paginated_inbound_sms_for_service(sample_service.id)
assert inbound_from_db == []
def test_dao_get_paginated_inbound_sms_for_service_page_size_returns_correct_size(sample_service):
inbound_sms_list = [
create_inbound_sms(sample_service),
create_inbound_sms(sample_service),
create_inbound_sms(sample_service),
create_inbound_sms(sample_service),
]
reversed_inbound_sms = sorted(inbound_sms_list, key=lambda sms: sms.created_at, reverse=True)
inbound_from_db = dao_get_paginated_inbound_sms_for_service(
sample_service.id,
older_than=reversed_inbound_sms[1].id,
page_size=2
)
assert len(inbound_from_db) == 2
def test_dao_get_paginated_inbound_sms_for_service_older_than_returns_correct_list(sample_service):
inbound_sms_list = [
create_inbound_sms(sample_service),
create_inbound_sms(sample_service),
create_inbound_sms(sample_service),
create_inbound_sms(sample_service),
]
reversed_inbound_sms = sorted(inbound_sms_list, key=lambda sms: sms.created_at, reverse=True)
inbound_from_db = dao_get_paginated_inbound_sms_for_service(
sample_service.id,
older_than=reversed_inbound_sms[1].id,
page_size=2
)
expected_inbound_sms = reversed_inbound_sms[2:]
assert expected_inbound_sms == inbound_from_db
def test_dao_get_paginated_inbound_sms_for_service_older_than_end_returns_empty_list(sample_service):
inbound_sms_list = [
create_inbound_sms(sample_service),
create_inbound_sms(sample_service),
]
reversed_inbound_sms = sorted(inbound_sms_list, key=lambda sms: sms.created_at, reverse=True)
inbound_from_db = dao_get_paginated_inbound_sms_for_service(
sample_service.id,
older_than=reversed_inbound_sms[1].id,
page_size=2
)
assert inbound_from_db == []