mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-17 02:32:32 -05:00
Added endpoints for letter-branding.
This commit is contained in:
@@ -214,7 +214,7 @@ def register_blueprint(application):
|
|||||||
template_folder_blueprint.before_request(requires_admin_auth)
|
template_folder_blueprint.before_request(requires_admin_auth)
|
||||||
application.register_blueprint(template_folder_blueprint)
|
application.register_blueprint(template_folder_blueprint)
|
||||||
|
|
||||||
letter_branding_blueprint.before_request(requires_admin_auth())
|
letter_branding_blueprint.before_request(requires_admin_auth)
|
||||||
application.register_blueprint(letter_branding_blueprint)
|
application.register_blueprint(letter_branding_blueprint)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ from app.letter_branding.letter_branding_schema import post_letter_branding_sche
|
|||||||
from app.models import LetterBranding
|
from app.models import LetterBranding
|
||||||
from app.schema_validation import validate
|
from app.schema_validation import validate
|
||||||
|
|
||||||
letter_branding_blueprint = Blueprint('letter_branding', __name__, url_prefix='letter-branding')
|
letter_branding_blueprint = Blueprint('letter_branding', __name__, url_prefix='/letter-branding')
|
||||||
register_errors(letter_branding_blueprint)
|
register_errors(letter_branding_blueprint)
|
||||||
|
|
||||||
|
|
||||||
@@ -65,12 +65,12 @@ def create_letter_brand():
|
|||||||
return jsonify(letter_branding.serialize()), 201
|
return jsonify(letter_branding.serialize()), 201
|
||||||
|
|
||||||
|
|
||||||
@letter_branding_blueprint.route('/<uuid: letter_branding_id>', methods=['POST'])
|
@letter_branding_blueprint.route('/<uuid:letter_branding_id>', methods=['POST'])
|
||||||
def create_letter_branding(letter_branding_id):
|
def update_letter_branding(letter_branding_id):
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
|
|
||||||
validate(data, post_letter_branding_schema)
|
validate(data, post_letter_branding_schema)
|
||||||
|
|
||||||
letter_branding = dao_update_letter_branding(letter_branding_id, )
|
letter_branding = dao_update_letter_branding(letter_branding_id, **data)
|
||||||
|
|
||||||
return jsonify(letter_branding.serialize()), 201
|
return jsonify(letter_branding.serialize()), 201
|
||||||
|
|||||||
@@ -7,5 +7,8 @@ post_letter_branding_schema = {
|
|||||||
"filename": {"type": ["string", "null"]},
|
"filename": {"type": ["string", "null"]},
|
||||||
"domain": {"type": ["string", "null"]},
|
"domain": {"type": ["string", "null"]},
|
||||||
},
|
},
|
||||||
"required": ("name", "filename", "domain")
|
"required": ("name", "filename", "domain"),
|
||||||
|
# Typically we allow additional properties but we don't want to update letter_branding platform_admin,
|
||||||
|
# this can handle this without adding extra code in the rest endpoint.
|
||||||
|
"additionalProperties": False
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,106 @@
|
|||||||
|
import json
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from app.models import LetterBranding
|
||||||
from tests import create_authorization_header
|
from tests import create_authorization_header
|
||||||
from tests.app.db import create_letter_branding
|
from tests.app.db import create_letter_branding
|
||||||
|
|
||||||
|
|
||||||
def test_get_letter_brandings(client, notify_db_session):
|
def test_get_all_letter_brands(client, notify_db_session):
|
||||||
platform_default = create_letter_branding()
|
platform_default = create_letter_branding()
|
||||||
test_domain_branding = create_letter_branding(
|
test_domain_branding = create_letter_branding(
|
||||||
name='test domain', filename='test-domain', domain='test.domain', platform_default=False
|
name='test domain', filename='test-domain', domain='test.domain', platform_default=False
|
||||||
)
|
)
|
||||||
response = client.get('/letter-branding', headers=[create_authorization_header()])
|
response = client.get('/letter-branding', headers=[create_authorization_header()])
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
json_response = response.get_data(as_text=True)
|
json_response = json.loads(response.get_data(as_text=True))
|
||||||
assert platform_default.serialize() in json_response
|
assert len(json_response) == 2
|
||||||
assert test_domain_branding.serialize() in json_response
|
for brand in json_response:
|
||||||
|
if brand['id'] == platform_default:
|
||||||
|
platform_default.serialize() == brand
|
||||||
|
else:
|
||||||
|
test_domain_branding.serialize() == brand
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_letter_branding(client, notify_db_session):
|
||||||
|
form = {
|
||||||
|
'name': 'super brand',
|
||||||
|
'domain': 'super.brand',
|
||||||
|
'filename': 'super-brand'
|
||||||
|
}
|
||||||
|
|
||||||
|
response = client.post(
|
||||||
|
'/letter-branding',
|
||||||
|
data=json.dumps(form),
|
||||||
|
headers=[('Content-Type', 'application/json'), create_authorization_header()],
|
||||||
|
)
|
||||||
|
|
||||||
|
assert response.status_code == 201
|
||||||
|
json_response = json.loads(response.get_data(as_text=True))
|
||||||
|
letter_brand = LetterBranding.query.get(json_response['id'])
|
||||||
|
assert letter_brand.name == form['name']
|
||||||
|
assert letter_brand.domain == form['domain']
|
||||||
|
assert letter_brand.filename == form['filename']
|
||||||
|
assert not letter_brand.platform_default
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_letter_branding_returns_400_if_platform_default_is_passed_in_the_form(client, notify_db_session):
|
||||||
|
form = {
|
||||||
|
'name': 'super brand',
|
||||||
|
'domain': 'super.brand',
|
||||||
|
'filename': 'super-brand',
|
||||||
|
'platform_default': True
|
||||||
|
}
|
||||||
|
|
||||||
|
response = client.post(
|
||||||
|
'/letter-branding',
|
||||||
|
data=json.dumps(form),
|
||||||
|
headers=[('Content-Type', 'application/json'), create_authorization_header()],
|
||||||
|
)
|
||||||
|
assert response.status_code == 400
|
||||||
|
json_resp = json.loads(response.get_data(as_text=True))
|
||||||
|
assert json_resp['errors'][0]['message'] == \
|
||||||
|
"Additional properties are not allowed (platform_default was unexpected)"
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_letter_branding_returns_400_if_name_already_exists(client, notify_db_session):
|
||||||
|
create_letter_branding(name='duplicate', domain='duplicate', filename='duplicate')
|
||||||
|
form = {
|
||||||
|
'name': 'duplicate',
|
||||||
|
'domain': 'super.brand',
|
||||||
|
'filename': 'super-brand',
|
||||||
|
}
|
||||||
|
|
||||||
|
response = client.post(
|
||||||
|
'/letter-branding',
|
||||||
|
headers=[('Content-Type', 'application/json'), create_authorization_header()],
|
||||||
|
data=json.dumps(form)
|
||||||
|
)
|
||||||
|
|
||||||
|
assert response.status_code == 400
|
||||||
|
json_resp = json.loads(response.get_data(as_text=True))
|
||||||
|
assert json_resp['message'] == {'name': ["Duplicate domain 'super.brand'"]}
|
||||||
|
|
||||||
|
|
||||||
|
def test_update_letter_branding_returns_400_when_integrity_error_is_thrown(
|
||||||
|
client, notify_db_session
|
||||||
|
):
|
||||||
|
create_letter_branding(name='duplicate', domain='duplicate', filename='duplicate')
|
||||||
|
brand_to_update = create_letter_branding(name='super brand', domain='super brand', filename='super brand')
|
||||||
|
form = {
|
||||||
|
'name': 'super brand',
|
||||||
|
'domain': 'duplicate',
|
||||||
|
'filename': 'super-brand',
|
||||||
|
}
|
||||||
|
|
||||||
|
response = client.post(
|
||||||
|
'/letter-branding/{}'.format(brand_to_update.id),
|
||||||
|
headers=[('Content-Type', 'application/json'), create_authorization_header()],
|
||||||
|
data=json.dumps(form)
|
||||||
|
)
|
||||||
|
|
||||||
|
assert response.status_code == 400
|
||||||
|
json_resp = json.loads(response.get_data(as_text=True))
|
||||||
|
# Why is this name and not domain? copied this pattern from email_branding
|
||||||
|
assert json_resp['message'] == {"name": ["Duplicate domain 'duplicate'"]}
|
||||||
|
|||||||
Reference in New Issue
Block a user