And an endpoint to get uploaded letters for a day

Because we won’t be showing uploaded letters individually on the uploads
page any more we need a way of listing them. This should be by printing
day, to match how we’re grouping them on the uploads page.

The response matches a normal `get_notifications` response so we can
reuse the same code in the admin app.
This commit is contained in:
Chris Hill-Scott
2020-05-11 10:51:40 +01:00
parent 421c1aac96
commit 864c6772b3
4 changed files with 185 additions and 2 deletions

View File

@@ -1,7 +1,7 @@
from datetime import datetime, timedelta
from freezegun import freeze_time
from app.dao.uploads_dao import dao_get_uploads_by_service_id
from app.dao.uploads_dao import dao_get_uploads_by_service_id, dao_get_uploaded_letters_by_print_date
from app.models import LETTER_TYPE, JOB_STATUS_IN_PROGRESS
from tests.app.db import create_job, create_service, create_service_data_retention, create_template, create_notification
@@ -302,3 +302,56 @@ def test_get_uploads_is_paginated(sample_template):
def test_get_uploads_returns_empty_list(sample_service):
items = dao_get_uploads_by_service_id(sample_service.id).items
assert items == []
@freeze_time('2020-02-02 14:00')
def test_get_uploaded_letters_by_print_date(sample_template):
letter_template = create_uploaded_template(sample_template.service)
# Letters for the previous days run
for i in range(3):
create_uploaded_letter(
letter_template, sample_template.service, status='delivered',
created_at=datetime.utcnow().replace(day=1, hour=17, minute=29, second=59)
)
# Letters from yesterday that rolled into todays run
for i in range(30):
create_uploaded_letter(
letter_template, sample_template.service, status='delivered',
created_at=datetime.utcnow().replace(day=1, hour=17, minute=30, second=0)
)
# Letters that just made todays run
for i in range(30):
create_uploaded_letter(
letter_template, sample_template.service, status='delivered',
created_at=datetime.utcnow().replace(hour=17, minute=29, second=59)
)
# Letters that just missed todays run
for i in range(3):
create_uploaded_letter(
letter_template, sample_template.service, status='delivered',
created_at=datetime.utcnow().replace(hour=17, minute=30, second=0)
)
result = dao_get_uploaded_letters_by_print_date(
sample_template.service_id,
datetime.utcnow(),
)
assert result.total == 60
assert len(result.items) == 50
assert result.has_next is True
assert result.has_prev is False
result = dao_get_uploaded_letters_by_print_date(
sample_template.service_id,
datetime.utcnow(),
page=10,
page_size=2,
)
assert result.total == 60
assert len(result.items) == 2
assert result.has_next is True
assert result.has_prev is True