mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 09:15:19 -05:00
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
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
from flask import current_app
|
||||||
from sqlalchemy import func, desc, asc, cast, Date as sql_date
|
from sqlalchemy import func, desc, asc, cast, Date as sql_date
|
||||||
|
|
||||||
from app import db
|
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):
|
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:
|
if limit_days is not None:
|
||||||
query_filter.append(cast(Job.created_at, sql_date) >= days_ago(limit_days))
|
query_filter.append(cast(Job.created_at, sql_date) >= days_ago(limit_days))
|
||||||
if statuses is not None and statuses != ['']:
|
if statuses is not None and statuses != ['']:
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ class Config(object):
|
|||||||
PAGE_SIZE = 50
|
PAGE_SIZE = 50
|
||||||
SMS_CHAR_COUNT_LIMIT = 495
|
SMS_CHAR_COUNT_LIMIT = 495
|
||||||
BRANDING_PATH = '/static/images/email-template/crests/'
|
BRANDING_PATH = '/static/images/email-template/crests/'
|
||||||
|
TEST_MESSAGE_FILENAME = 'Test message'
|
||||||
|
|
||||||
NOTIFY_SERVICE_ID = 'd6aa2c68-a2d9-4437-ab19-3ae8eb202553'
|
NOTIFY_SERVICE_ID = 'd6aa2c68-a2d9-4437-ab19-3ae8eb202553'
|
||||||
INVITATION_EMAIL_TEMPLATE_ID = '4f46df42-f795-4cc4-83bb-65ca312f49cc'
|
INVITATION_EMAIL_TEMPLATE_ID = '4f46df42-f795-4cc4-83bb-65ca312f49cc'
|
||||||
|
|||||||
@@ -265,7 +265,8 @@ def sample_job(notify_db,
|
|||||||
created_at=None,
|
created_at=None,
|
||||||
job_status='pending',
|
job_status='pending',
|
||||||
scheduled_for=None,
|
scheduled_for=None,
|
||||||
processing_started=None):
|
processing_started=None,
|
||||||
|
original_file_name='some.csv'):
|
||||||
if service is None:
|
if service is None:
|
||||||
service = sample_service(notify_db, notify_db_session)
|
service = sample_service(notify_db, notify_db_session)
|
||||||
if template is None:
|
if template is None:
|
||||||
@@ -277,7 +278,7 @@ def sample_job(notify_db,
|
|||||||
'service': service,
|
'service': service,
|
||||||
'template_id': template.id,
|
'template_id': template.id,
|
||||||
'template_version': template.version,
|
'template_version': template.version,
|
||||||
'original_file_name': 'some.csv',
|
'original_file_name': original_file_name,
|
||||||
'notification_count': notification_count,
|
'notification_count': notification_count,
|
||||||
'created_at': created_at or datetime.utcnow(),
|
'created_at': created_at or datetime.utcnow(),
|
||||||
'created_by': service.created_by,
|
'created_by': service.created_by,
|
||||||
|
|||||||
@@ -300,3 +300,16 @@ def test_get_jobs_for_service_is_paginated(notify_db, notify_db_session, sample_
|
|||||||
assert len(res.items) == 2
|
assert len(res.items) == 2
|
||||||
assert res.items[0].created_at == datetime(2015, 1, 1, 8)
|
assert res.items[0].created_at == datetime(2015, 1, 1, 8)
|
||||||
assert res.items[1].created_at == datetime(2015, 1, 1, 7)
|
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]
|
||||||
|
|||||||
Reference in New Issue
Block a user