Files
notifications-api/tests/app/govuk_alerts/test_get_broadcasts.py
Ben Thorner 6a53871455 Restructure govuk-alerts endpoint to be internal
In response to: https://github.com/alphagov/notifications-api/pull/3305#pullrequestreview-726672421

Previously this was added among the public /v2 endpoints, but it's
only meant for internal use. While only the govuk-alerts app would
be able to access it, the location and /v2 URL suggested otherwise.
This restructures the endpoint so it resembles other internal ones.
2021-09-15 15:36:17 +01:00

40 lines
1.4 KiB
Python

from datetime import datetime
from flask import current_app, json
from app.models import BROADCAST_TYPE
from tests import create_internal_authorization_header
from tests.app.db import create_broadcast_message, create_template
def test_get_all_broadcasts_returns_list_of_broadcasts_and_200(
client, sample_broadcast_service
):
template_1 = create_template(sample_broadcast_service, BROADCAST_TYPE)
broadcast_message_1 = create_broadcast_message(
template_1,
starts_at=datetime(2021, 6, 15, 12, 0, 0),
status='cancelled')
broadcast_message_2 = create_broadcast_message(
template_1,
starts_at=datetime(2021, 6, 22, 12, 0, 0),
status='broadcasting')
jwt_client_id = current_app.config['GOVUK_ALERTS_CLIENT_ID']
header = create_internal_authorization_header(jwt_client_id)
response = client.get('/govuk-alerts', headers=[header])
json_response = json.loads(response.get_data(as_text=True))
assert response.status_code == 200
assert len(json_response['alerts']) == 2
assert json_response['alerts'][0]['id'] == str(broadcast_message_2.id)
assert json_response['alerts'][0]['starts_at'] == '2021-06-22T12:00:00.000000Z'
assert json_response['alerts'][0]['finishes_at'] is None
assert json_response['alerts'][1]['id'] == str(broadcast_message_1.id)
assert json_response['alerts'][1]['starts_at'] == '2021-06-15T12:00:00.000000Z'