mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-12 09:24:15 -04:00
Limit jobs sent from contact list by data retention
On the uploads page we only show jobs which are within a service’s data retention. This commit does the same for when we’re listing the jobs for a contact list. This matches the UI, which says a contact list has been ‘used `<count_of_jobs>` in the last <data_retention> days’
This commit is contained in:
@@ -517,7 +517,10 @@ def contact_list(service_id, contact_list_id):
|
||||
return render_template(
|
||||
'views/uploads/contact-list/contact-list.html',
|
||||
contact_list=contact_list,
|
||||
jobs=contact_list.get_jobs(page=1),
|
||||
jobs=contact_list.get_jobs(
|
||||
page=1,
|
||||
limit_days=current_service.get_days_of_retention(contact_list.template_type),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -137,11 +137,12 @@ class ContactList(JSONModel):
|
||||
file_name, extention = path.splitext(self.original_file_name)
|
||||
return f'{file_name}.csv'
|
||||
|
||||
def get_jobs(self, *, page):
|
||||
def get_jobs(self, *, page, limit_days=None):
|
||||
return PaginatedJobsAndScheduledJobs(
|
||||
self.service_id,
|
||||
contact_list_id=self.id,
|
||||
page=page,
|
||||
limit_days=limit_days,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -235,12 +235,13 @@ class PaginatedJobs(PaginatedModelList, ImmediateJobs):
|
||||
client_method = job_api_client.get_page_of_jobs
|
||||
statuses = None
|
||||
|
||||
def __init__(self, service_id, *, contact_list_id=None, page=None):
|
||||
def __init__(self, service_id, *, contact_list_id=None, page=None, limit_days=None):
|
||||
super().__init__(
|
||||
service_id,
|
||||
contact_list_id=contact_list_id,
|
||||
statuses=self.statuses,
|
||||
page=page,
|
||||
limit_days=limit_days,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -53,12 +53,13 @@ class JobApiClient(NotifyAdminAPIClient):
|
||||
if job['job_status'] != 'cancelled'
|
||||
)
|
||||
|
||||
def get_page_of_jobs(self, service_id, *, page, statuses=None, contact_list_id=None):
|
||||
def get_page_of_jobs(self, service_id, *, page, statuses=None, contact_list_id=None, limit_days=None):
|
||||
return self.get_jobs(
|
||||
service_id,
|
||||
statuses=statuses or self.NON_SCHEDULED_JOB_STATUSES,
|
||||
page=page,
|
||||
contact_list_id=contact_list_id,
|
||||
limit_days=limit_days,
|
||||
)
|
||||
|
||||
def get_immediate_jobs(self, service_id):
|
||||
|
||||
@@ -491,6 +491,21 @@ def test_view_contact_list(
|
||||
service_id=SERVICE_ONE_ID,
|
||||
contact_list_id=fake_uuid,
|
||||
)
|
||||
mock_get_no_jobs.assert_called_once_with(
|
||||
SERVICE_ONE_ID,
|
||||
contact_list_id=fake_uuid,
|
||||
limit_days=7,
|
||||
statuses={
|
||||
'finished',
|
||||
'in progress',
|
||||
'pending',
|
||||
'ready to send',
|
||||
'scheduled',
|
||||
'sending limits exceeded',
|
||||
'sent to dvla',
|
||||
},
|
||||
page=1,
|
||||
)
|
||||
assert normalize_spaces(page.select_one('h1').text) == (
|
||||
'EmergencyContactList.xls'
|
||||
)
|
||||
|
||||
@@ -28,4 +28,5 @@ def test_get_jobs(mock_get_jobs):
|
||||
'in progress',
|
||||
},
|
||||
page=123,
|
||||
limit_days=None,
|
||||
)
|
||||
|
||||
@@ -2034,7 +2034,7 @@ def mock_get_no_uploads(mocker, api_user_active):
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def mock_get_no_jobs(mocker, api_user_active):
|
||||
mocker.patch(
|
||||
return mocker.patch(
|
||||
'app.models.job.PaginatedJobs.client_method',
|
||||
return_value={
|
||||
'data': [],
|
||||
|
||||
Reference in New Issue
Block a user