Merge pull request #1929 from alphagov/paginate-complaints

Paginate complaints
This commit is contained in:
Katie Smith
2018-07-04 15:34:46 +01:00
committed by GitHub
5 changed files with 80 additions and 15 deletions

View File

@@ -1966,11 +1966,11 @@ def test_fetch_aggregate_stats_by_date_range_for_all_services_groups_stats(
result = fetch_aggregate_stats_by_date_range_for_all_services(today, today)
assert len(result) == 5
assert result[0] == ('email', 'permanent-failure', 'normal', 3)
assert result[1] == ('email', 'sent', 'normal', 1)
assert result[2] == ('sms', 'sent', 'normal', 1)
assert result[3] == ('sms', 'sent', 'team', 1)
assert result[4] == ('letter', 'virus-scan-failed', 'normal', 1)
assert ('email', 'permanent-failure', 'normal', 3) in result
assert ('email', 'sent', 'normal', 1) in result
assert ('sms', 'sent', 'normal', 1) in result
assert ('sms', 'sent', 'team', 1) in result
assert ('letter', 'virus-scan-failed', 'normal', 1) in result
def test_fetch_aggregate_stats_by_date_range_for_all_services_uses_bst_date(sample_template):

View File

@@ -2,11 +2,40 @@ import uuid
from datetime import datetime, timedelta
from app.dao.complaint_dao import save_complaint, fetch_complaints_by_service, fetch_count_of_complaints
from app.dao.complaint_dao import (
fetch_complaints_by_service,
fetch_count_of_complaints,
fetch_paginated_complaints,
save_complaint,
)
from app.models import Complaint
from tests.app.db import create_service, create_template, create_notification, create_complaint
def test_fetch_paginated_complaints(mocker, sample_email_notification):
mocker.patch.dict('app.dao.complaint_dao.current_app.config', {'PAGE_SIZE': 2})
create_complaint(service=sample_email_notification.service,
notification=sample_email_notification,
created_at=datetime(2018, 1, 1))
create_complaint(service=sample_email_notification.service,
notification=sample_email_notification,
created_at=datetime(2018, 1, 2))
create_complaint(service=sample_email_notification.service,
notification=sample_email_notification,
created_at=datetime(2018, 1, 3))
res = fetch_paginated_complaints(page=1)
assert len(res.items) == 2
assert res.items[0].created_at == datetime(2018, 1, 3)
assert res.items[1].created_at == datetime(2018, 1, 2)
res = fetch_paginated_complaints(page=2)
assert len(res.items) == 1
assert res.items[0].created_at == datetime(2018, 1, 1)
def test_fetch_complaint_by_service_returns_one(sample_service, sample_email_notification):
complaint = Complaint(notification_id=sample_email_notification.id,
service_id=sample_service.id,