From d8467bfc3cdca0f7dcd019f93ca20d981ef28760 Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Tue, 11 Oct 2016 14:30:40 +0100 Subject: [PATCH] filter out test jobs from the GET /service/{}/job endpoint this is so that the filtering, which we do on the admin side, is applied before pagination - so that the pages returned are all valid displayable jobs. unfortunately this means that another config value has to be copied to the server side but it's not the end of the world --- app/dao/jobs_dao.py | 6 +++++- config.py | 1 + tests/app/conftest.py | 5 +++-- tests/app/dao/test_jobs_dao.py | 13 +++++++++++++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/app/dao/jobs_dao.py b/app/dao/jobs_dao.py index f562a091f..a9f1bd9b9 100644 --- a/app/dao/jobs_dao.py +++ b/app/dao/jobs_dao.py @@ -1,5 +1,6 @@ from datetime import datetime +from flask import current_app from sqlalchemy import func, desc, asc, cast, Date as sql_date from app import db @@ -28,7 +29,10 @@ def dao_get_job_by_service_id_and_job_id(service_id, job_id): def dao_get_jobs_by_service_id(service_id, limit_days=None, page=1, page_size=50, statuses=None): - query_filter = [Job.service_id == service_id] + query_filter = [ + Job.service_id == service_id, + Job.original_file_name != current_app.config['TEST_MESSAGE_FILENAME'] + ] if limit_days is not None: query_filter.append(cast(Job.created_at, sql_date) >= days_ago(limit_days)) if statuses is not None and statuses != ['']: diff --git a/config.py b/config.py index fa676c79c..255444bb8 100644 --- a/config.py +++ b/config.py @@ -57,6 +57,7 @@ class Config(object): PAGE_SIZE = 50 SMS_CHAR_COUNT_LIMIT = 495 BRANDING_PATH = '/static/images/email-template/crests/' + TEST_MESSAGE_FILENAME = 'Test message' NOTIFY_SERVICE_ID = 'd6aa2c68-a2d9-4437-ab19-3ae8eb202553' INVITATION_EMAIL_TEMPLATE_ID = '4f46df42-f795-4cc4-83bb-65ca312f49cc' diff --git a/tests/app/conftest.py b/tests/app/conftest.py index 1dd226b7c..d5940f887 100644 --- a/tests/app/conftest.py +++ b/tests/app/conftest.py @@ -265,7 +265,8 @@ def sample_job(notify_db, created_at=None, job_status='pending', scheduled_for=None, - processing_started=None): + processing_started=None, + original_file_name='some.csv'): if service is None: service = sample_service(notify_db, notify_db_session) if template is None: @@ -277,7 +278,7 @@ def sample_job(notify_db, 'service': service, 'template_id': template.id, 'template_version': template.version, - 'original_file_name': 'some.csv', + 'original_file_name': original_file_name, 'notification_count': notification_count, 'created_at': created_at or datetime.utcnow(), 'created_by': service.created_by, diff --git a/tests/app/dao/test_jobs_dao.py b/tests/app/dao/test_jobs_dao.py index 59b32237e..9ea1cf6a9 100644 --- a/tests/app/dao/test_jobs_dao.py +++ b/tests/app/dao/test_jobs_dao.py @@ -300,3 +300,16 @@ def test_get_jobs_for_service_is_paginated(notify_db, notify_db_session, sample_ assert len(res.items) == 2 assert res.items[0].created_at == datetime(2015, 1, 1, 8) assert res.items[1].created_at == datetime(2015, 1, 1, 7) + + +def test_get_jobs_for_service_doesnt_return_test_messages(notify_db, notify_db_session, sample_template, sample_job): + test_job = create_job( + notify_db, + notify_db_session, + sample_template.service, + sample_template, + original_file_name='Test message') + + jobs = dao_get_jobs_by_service_id(sample_job.service_id).items + + assert jobs == [sample_job]