From aff0abb78c5426c80ac552a3db3265f3389fbfa8 Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Wed, 11 May 2016 12:03:25 +0100 Subject: [PATCH] Add a load only and dump only for the created_by attribute of the JobSchema --- app/schemas.py | 4 ++++ tests/app/job/test_rest.py | 1 + 2 files changed, 5 insertions(+) diff --git a/app/schemas.py b/app/schemas.py index d01a4e978..bcd3c64e8 100644 --- a/app/schemas.py +++ b/app/schemas.py @@ -143,6 +143,10 @@ class ApiKeySchema(BaseSchema): class JobSchema(BaseSchema): + created_by_user = fields.Nested(UserSchema, attribute="created_by", + dump_to="created_by", only=["id", "name"], dump_only=True) + created_by = field_for(models.Job, 'created_by', required=True, load_only=True) + class Meta: model = models.Job diff --git a/tests/app/job/test_rest.py b/tests/app/job/test_rest.py index f80400f45..9733c932a 100644 --- a/tests/app/job/test_rest.py +++ b/tests/app/job/test_rest.py @@ -71,6 +71,7 @@ def test_get_job_by_id(notify_api, sample_job): assert response.status_code == 200 resp_json = json.loads(response.get_data(as_text=True)) assert resp_json['data']['id'] == job_id + assert resp_json['data']['created_by']['name'] == 'Test User' def test_create_job(notify_api, sample_template, mocker, fake_uuid):