mirror of
https://github.com/GSA/notifications-api.git
synced 2026-07-09 02:43:55 -04:00
Return template type for jobs
This is so we can display letter jobs in a different way on the admin app (because it doesn’t make sense for them to have failed/delivered counts like it does for email and text message jobs). As elsewhere we use `fields.Method` to avoid serializing the whole template object.
This commit is contained in:
@@ -380,6 +380,11 @@ class JobSchema(BaseSchema):
|
||||
service_name = fields.Nested(
|
||||
ServiceSchema, attribute="service", dump_to="service_name", only=["name"], dump_only=True)
|
||||
|
||||
template_type = fields.Method('get_template_type', dump_only=True)
|
||||
|
||||
def get_template_type(self, job):
|
||||
return job.template.template_type
|
||||
|
||||
@validates('scheduled_for')
|
||||
def validate_scheduled_for(self, value):
|
||||
_validate_datetime_not_in_past(value)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import json
|
||||
import uuid
|
||||
from datetime import datetime, timedelta, date
|
||||
from unittest.mock import ANY
|
||||
|
||||
from freezegun import freeze_time
|
||||
import pytest
|
||||
@@ -653,6 +654,7 @@ def test_get_job_by_id_with_stats_for_old_job_where_notifications_have_been_purg
|
||||
assert resp_json['data']['created_by']['name'] == 'Test User'
|
||||
|
||||
|
||||
@freeze_time('2017-07-17 07:17')
|
||||
def test_get_jobs(admin_request, sample_template):
|
||||
_setup_jobs(sample_template)
|
||||
|
||||
@@ -660,6 +662,28 @@ def test_get_jobs(admin_request, sample_template):
|
||||
|
||||
resp_json = admin_request.get('job.get_jobs_by_service', service_id=service_id)
|
||||
assert len(resp_json['data']) == 5
|
||||
assert resp_json['data'][0] == {
|
||||
'archived': False,
|
||||
'created_at': '2017-07-17T07:17:00+00:00',
|
||||
'created_by': {
|
||||
'id': ANY,
|
||||
'name': 'Test User',
|
||||
},
|
||||
'id': ANY,
|
||||
'job_status': 'pending',
|
||||
'notification_count': 1,
|
||||
'original_file_name': 'some.csv',
|
||||
'processing_finished': None,
|
||||
'processing_started': None,
|
||||
'scheduled_for': None,
|
||||
'service': str(sample_template.service.id),
|
||||
'service_name': {'name': sample_template.service.name},
|
||||
'statistics': [],
|
||||
'template': str(sample_template.id),
|
||||
'template_type': 'sms',
|
||||
'template_version': 1,
|
||||
'updated_at': None,
|
||||
}
|
||||
|
||||
|
||||
def test_get_jobs_with_limit_days(admin_request, sample_template):
|
||||
|
||||
Reference in New Issue
Block a user