mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 18:31:13 -05:00
ensure old route still returns json in same shape
This commit is contained in:
@@ -21,13 +21,17 @@ register_errors(email_branding_blueprint)
|
|||||||
@email_branding_blueprint.route('', methods=['GET'])
|
@email_branding_blueprint.route('', methods=['GET'])
|
||||||
def get_email_branding_options():
|
def get_email_branding_options():
|
||||||
email_branding_options = [o.serialize() for o in dao_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)
|
return jsonify(email_branding=email_branding_options)
|
||||||
|
|
||||||
|
|
||||||
@email_branding_blueprint.route('/<uuid:email_branding_id>', methods=['GET'])
|
@email_branding_blueprint.route('/<uuid:email_branding_id>', methods=['GET'])
|
||||||
def get_email_branding_by_id(email_branding_id):
|
def get_email_branding_by_id(email_branding_id):
|
||||||
email_branding = dao_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'])
|
@email_branding_blueprint.route('', methods=['POST'])
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
|
import json
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from app.models import EmailBranding
|
from app.models import EmailBranding
|
||||||
|
|
||||||
|
from tests import create_authorization_header
|
||||||
|
|
||||||
|
|
||||||
def test_get_email_branding_options(admin_request, notify_db, notify_db_session):
|
def test_get_email_branding_options(admin_request, notify_db, notify_db_session):
|
||||||
email_branding1 = EmailBranding(colour='#FFFFFF', logo='/path/image.png', name='Org1')
|
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):
|
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')
|
email_branding = EmailBranding(colour='#FFFFFF', logo='/path/image.png', name='My Org')
|
||||||
notify_db.session.add(email_branding)
|
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)
|
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):
|
def test_post_create_email_branding(admin_request, notify_db_session):
|
||||||
data = {
|
data = {
|
||||||
'name': 'test email_branding',
|
'name': 'test email_branding',
|
||||||
|
|||||||
Reference in New Issue
Block a user