From 8601b1359540a4404c1a34c6855e9574b4be62c2 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Tue, 25 Feb 2020 16:05:39 +0000 Subject: [PATCH] Return template type for jobs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- app/schemas.py | 5 +++++ tests/app/job/test_rest.py | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/app/schemas.py b/app/schemas.py index fc740c53e..5dd616617 100644 --- a/app/schemas.py +++ b/app/schemas.py @@ -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) diff --git a/tests/app/job/test_rest.py b/tests/app/job/test_rest.py index e94cb2076..80383804a 100644 --- a/tests/app/job/test_rest.py +++ b/tests/app/job/test_rest.py @@ -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):