From 0c67a61604c113a8f064dde5d951b737ac9258d5 Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Tue, 6 Feb 2018 12:10:00 +0000 Subject: [PATCH] ensure old route still returns json in same shape --- app/email_branding/rest.py | 6 +++- tests/app/email_branding/test_rest.py | 42 +++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/app/email_branding/rest.py b/app/email_branding/rest.py index 277d27714..9ff339158 100644 --- a/app/email_branding/rest.py +++ b/app/email_branding/rest.py @@ -21,13 +21,17 @@ register_errors(email_branding_blueprint) @email_branding_blueprint.route('', methods=['GET']) def get_email_branding_options(): email_branding_options = [o.serialize() for o in dao_get_email_branding_options()] + key = 'organisations' if request.path.startswith('/organisation') else 'email_branding' + return jsonify(**{key: email_branding_options}) return jsonify(email_branding=email_branding_options) @email_branding_blueprint.route('/', methods=['GET']) def get_email_branding_by_id(email_branding_id): email_branding = dao_get_email_branding_by_id(email_branding_id) - return jsonify(email_branding=email_branding.serialize()) + # TODO: remove this switch after admin is updated to refer to email branding + key = 'organisation' if request.path.startswith('/organisation') else 'email_branding' + return jsonify(**{key: email_branding.serialize()}) @email_branding_blueprint.route('', methods=['POST']) diff --git a/tests/app/email_branding/test_rest.py b/tests/app/email_branding/test_rest.py index 19294e5ab..d624dd2dd 100644 --- a/tests/app/email_branding/test_rest.py +++ b/tests/app/email_branding/test_rest.py @@ -1,7 +1,11 @@ +import json + import pytest from app.models import EmailBranding +from tests import create_authorization_header + def test_get_email_branding_options(admin_request, notify_db, notify_db_session): email_branding1 = EmailBranding(colour='#FFFFFF', logo='/path/image.png', name='Org1') @@ -21,6 +25,29 @@ def test_get_email_branding_options(admin_request, notify_db, notify_db_session) } +def test_get_email_branding_options_from_old_endpoint(client, notify_db, notify_db_session): + email_branding1 = EmailBranding(colour='#FFFFFF', logo='/path/image.png', name='Org1') + email_branding2 = EmailBranding(colour='#000000', logo='/path/other.png', name='Org2') + notify_db.session.add_all([email_branding1, email_branding2]) + notify_db.session.commit() + + response = client.get( + '/organisation', + headers=[create_authorization_header()] + ) + assert response.status_code == 200 + json_resp = json.loads(response.get_data(as_text=True)) + + email_branding = json_resp['organisations'] + + assert len(email_branding) == 2 + assert { + email_branding['id'] for email_branding in email_branding + } == { + str(email_branding1.id), str(email_branding2.id) + } + + def test_get_email_branding_by_id(admin_request, notify_db, notify_db_session): email_branding = EmailBranding(colour='#FFFFFF', logo='/path/image.png', name='My Org') notify_db.session.add(email_branding) @@ -39,6 +66,21 @@ def test_get_email_branding_by_id(admin_request, notify_db, notify_db_session): assert response['email_branding']['id'] == str(email_branding.id) +def test_get_email_branding_by_id_from_old_endpoint(client, notify_db, notify_db_session): + email_branding = EmailBranding(colour='#FFFFFF', logo='/path/image.png', name='My Org') + notify_db.session.add(email_branding) + notify_db.session.commit() + + response = client.get( + '/organisation/{}'.format(email_branding.id), + headers=[create_authorization_header()] + ) + assert response.status_code == 200 + json_resp = json.loads(response.get_data(as_text=True)) + + assert json_resp['organisation']['id'] == str(email_branding.id) + + def test_post_create_email_branding(admin_request, notify_db_session): data = { 'name': 'test email_branding',