From 55a65a22a9b4039ad17d02b079a0e10c1ea35aab Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Tue, 16 Apr 2019 12:33:07 +0100 Subject: [PATCH] Added test for go_live_user and go_live_at in the response for get_service_by_id --- app/models.py | 2 -- app/schemas.py | 1 + tests/app/db.py | 8 ++++++-- tests/app/service/test_rest.py | 8 ++++++++ 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/models.py b/app/models.py index 1f8175e61..f95f35c70 100644 --- a/app/models.py +++ b/app/models.py @@ -438,8 +438,6 @@ class Service(db.Model, Versioned): uselist=False, backref=db.backref('services', lazy='dynamic')) - - @classmethod def from_json(cls, data): """ diff --git a/app/schemas.py b/app/schemas.py index b65c2f5b4..455b23470 100644 --- a/app/schemas.py +++ b/app/schemas.py @@ -210,6 +210,7 @@ class ServiceSchema(BaseSchema): organisation = field_for(models.Service, 'organisation') override_flag = False letter_contact_block = fields.Method(serialize="get_letter_contact") + go_live_at = field_for(models.Service, 'go_live_at', format='%Y-%m-%d %H:%M:%S.%f') def get_letter_logo_filename(self, service): return service.letter_branding and service.letter_branding.filename diff --git a/tests/app/db.py b/tests/app/db.py index bac88fe59..baf4cad52 100644 --- a/tests/app/db.py +++ b/tests/app/db.py @@ -93,7 +93,9 @@ def create_service( prefix_sms=True, message_limit=1000, organisation_type='central', - check_if_service_exists=False + check_if_service_exists=False, + go_live_user=None, + go_live_at=None ): if check_if_service_exists: service = Service.query.filter_by(name=service_name).first() @@ -105,7 +107,9 @@ def create_service( email_from=email_from if email_from else service_name.lower().replace(' ', '.'), created_by=user if user else create_user(email='{}@digital.cabinet-office.gov.uk'.format(uuid.uuid4())), prefix_sms=prefix_sms, - organisation_type=organisation_type + organisation_type=organisation_type, + go_live_user=go_live_user, + go_live_at=go_live_at ) dao_create_service(service, service.created_by, service_id, service_permissions=service_permissions) diff --git a/tests/app/service/test_rest.py b/tests/app/service/test_rest.py index 75b03f730..d447ee559 100644 --- a/tests/app/service/test_rest.py +++ b/tests/app/service/test_rest.py @@ -221,6 +221,14 @@ def test_get_service_by_id_should_404_if_no_service_for_user(notify_api, sample_ assert json_resp['message'] == 'No result found' +def test_get_service_by_id_returns_go_live_user_and_go_live_at(admin_request, sample_user): + now = datetime.utcnow() + service = create_service(user=sample_user, go_live_user=sample_user, go_live_at=now) + json_resp = admin_request.get('service.get_service_by_id', service_id=service.id) + assert json_resp['data']['go_live_user'] == str(sample_user.id) + assert json_resp['data']['go_live_at'] == str(now) + + @pytest.mark.parametrize('platform_admin, expected_count_as_live', ( (True, False), (False, True),