From f9c87bafa3aa1bfa2bac5a7c860c7e1f3b381ff8 Mon Sep 17 00:00:00 2001 From: David McDonald Date: Fri, 12 Feb 2021 17:22:09 +0000 Subject: [PATCH] Add `go_live_at` timestamp to set_as_broadcast_service Note, I haven't added anything for the `go_live_user` because it doesn't quite make sense because here a user isn't requesting to go live. So there should be no reason to record this. We will in time though want to add audit events to capture every change to the service broadcast settings, that will actually capture who has done what. --- app/service/rest.py | 8 ++++++++ tests/app/service/test_rest.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/app/service/rest.py b/app/service/rest.py index 5e3754e1b..49b93e4ab 100644 --- a/app/service/rest.py +++ b/app/service/rest.py @@ -1116,6 +1116,14 @@ def set_as_broadcast_service(service_id): service.count_as_live = False + if data["service_mode"] == "live": + if service.restricted == True: + # Only update the go live at timestamp if this if moving from training mode + # to live mode, not if it's moving from one type of live mode service to another + service.go_live_at = datetime.utcnow() + else: + service.go_live_at = None + service.restricted = True if data["service_mode"] == "live": service.restricted = False diff --git a/tests/app/service/test_rest.py b/tests/app/service/test_rest.py index 88a714349..1be4e1fa3 100644 --- a/tests/app/service/test_rest.py +++ b/tests/app/service/test_rest.py @@ -3872,6 +3872,7 @@ def test_set_as_broadcast_service_does_not_error_if_run_on_a_service_that_is_alr ) +@freeze_time('2021-02-02') def test_set_as_broadcast_service_sets_service_to_live_mode( admin_request, notify_db, sample_service, broadcast_organisation ): @@ -3879,6 +3880,7 @@ def test_set_as_broadcast_service_sets_service_to_live_mode( notify_db.session.add(sample_service) notify_db.session.commit() assert sample_service.restricted == True + assert sample_service.go_live_at == None data = { 'broadcast_channel': 'severe', 'service_mode': 'live', @@ -3892,15 +3894,43 @@ def test_set_as_broadcast_service_sets_service_to_live_mode( ) assert result['data']['name'] == 'Sample service' assert result['data']['restricted'] == False + assert result['data']['go_live_at'] == '2021-02-02 00:00:00.000000' + + +def test_set_as_broadcast_service_doesnt_override_existing_go_live_at( + admin_request, notify_db, sample_broadcast_service +): + sample_broadcast_service.restricted = False + sample_broadcast_service.go_live_at = datetime(2021, 1, 1) + notify_db.session.add(sample_broadcast_service) + notify_db.session.commit() + assert sample_broadcast_service.restricted == False + assert sample_broadcast_service.go_live_at is not None + data = { + 'broadcast_channel': 'severe', + 'service_mode': 'live', + 'provider_restriction': None, + } + + result = admin_request.post( + 'service.set_as_broadcast_service', + service_id=sample_broadcast_service.id, + _data=data, + ) + assert result['data']['name'] == 'Sample broadcast service' + assert result['data']['restricted'] == False + assert result['data']['go_live_at'] == '2021-01-01 00:00:00.000000' def test_set_as_broadcast_service_sets_service_to_training_mode( admin_request, notify_db, sample_broadcast_service ): sample_broadcast_service.restricted = False + sample_broadcast_service.go_live_at = datetime(2021, 1, 1) notify_db.session.add(sample_broadcast_service) notify_db.session.commit() assert sample_broadcast_service.restricted == False + assert sample_broadcast_service.go_live_at is not None data = { 'broadcast_channel': 'severe', @@ -3915,6 +3945,7 @@ def test_set_as_broadcast_service_sets_service_to_training_mode( ) assert result['data']['name'] == 'Sample broadcast service' assert result['data']['restricted'] == True + assert result['data']['go_live_at'] is None @pytest.mark.parametrize('service_mode', ["testing", ""])