mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-12 00:02:36 -05:00
Instead of deleting the data in the name field just copy it to the text field.
The admin app still needs to use the name column. Add the text field to the post data schemas. If the text is not in the post data, then populate it with the data in the name field. This should make the migration to text easier, and will work until we are able to update the admin app.
This commit is contained in:
@@ -5,6 +5,7 @@ post_create_email_branding_schema = {
|
||||
"properties": {
|
||||
"colour": {"type": ["string", "null"]},
|
||||
"name": {"type": ["string", "null"]},
|
||||
"text": {"type": ["string", "null"]},
|
||||
"logo": {"type": ["string", "null"]}
|
||||
},
|
||||
"required": []
|
||||
@@ -17,6 +18,7 @@ post_update_email_branding_schema = {
|
||||
"properties": {
|
||||
"colour": {"type": ["string", "null"]},
|
||||
"name": {"type": ["string", "null"]},
|
||||
"text": {"type": ["string", "null"]},
|
||||
"logo": {"type": ["string", "null"]}
|
||||
},
|
||||
"required": []
|
||||
|
||||
@@ -37,6 +37,8 @@ def create_email_branding():
|
||||
validate(data, post_create_email_branding_schema)
|
||||
|
||||
email_branding = EmailBranding(**data)
|
||||
if not data.get('text'):
|
||||
email_branding.text = email_branding.name
|
||||
|
||||
dao_create_email_branding(email_branding)
|
||||
return jsonify(data=email_branding.serialize()), 201
|
||||
@@ -49,6 +51,8 @@ def update_email_branding(email_branding_id):
|
||||
validate(data, post_update_email_branding_schema)
|
||||
|
||||
fetched_email_branding = dao_get_email_branding_by_id(email_branding_id)
|
||||
if not data.get('text') and data.get('name'):
|
||||
data['text'] = data['name']
|
||||
dao_update_email_branding(fetched_email_branding, **data)
|
||||
|
||||
return jsonify(data=fetched_email_branding.serialize()), 200
|
||||
|
||||
@@ -14,14 +14,9 @@ down_revision = '0210_remove_monthly_billing'
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.add_column('email_branding', sa.Column('text', sa.String(length=255), nullable=True))
|
||||
op.execute('UPDATE email_branding SET text = name')
|
||||
op.execute('UPDATE email_branding SET name = NULL')
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.execute('UPDATE email_branding SET name = text')
|
||||
op.drop_column('email_branding', 'text')
|
||||
# ### end Alembic commands ###
|
||||
|
||||
@@ -54,6 +54,7 @@ def test_post_create_email_branding(admin_request, notify_db_session):
|
||||
assert data['name'] == response['data']['name']
|
||||
assert data['colour'] == response['data']['colour']
|
||||
assert data['logo'] == response['data']['logo']
|
||||
assert data['name'] == response['data']['text']
|
||||
|
||||
|
||||
def test_post_create_email_branding_without_logo_is_ok(admin_request, notify_db_session):
|
||||
@@ -81,6 +82,42 @@ def test_post_create_email_branding_without_name_or_colour_is_valid(admin_reques
|
||||
assert response['data']['logo'] == data['logo']
|
||||
assert response['data']['name'] is None
|
||||
assert response['data']['colour'] is None
|
||||
assert response['data']['text'] is None
|
||||
|
||||
|
||||
def test_post_create_email_branding_with_text(admin_request, notify_db_session):
|
||||
data = {
|
||||
'text': 'text for brand',
|
||||
'logo': 'images/text_x2.png'
|
||||
}
|
||||
response = admin_request.post(
|
||||
'email_branding.create_email_branding',
|
||||
_data=data,
|
||||
_expected_status=201
|
||||
)
|
||||
|
||||
assert response['data']['logo'] == data['logo']
|
||||
assert response['data']['name'] is None
|
||||
assert response['data']['colour'] is None
|
||||
assert response['data']['text'] == 'text for brand'
|
||||
|
||||
|
||||
def test_post_create_email_branding_with_text_and_name(admin_request, notify_db_session):
|
||||
data = {
|
||||
'name': 'name for brand',
|
||||
'text': 'text for brand',
|
||||
'logo': 'images/text_x2.png'
|
||||
}
|
||||
response = admin_request.post(
|
||||
'email_branding.create_email_branding',
|
||||
_data=data,
|
||||
_expected_status=201
|
||||
)
|
||||
|
||||
assert response['data']['logo'] == data['logo']
|
||||
assert response['data']['name'] == 'name for brand'
|
||||
assert response['data']['colour'] is None
|
||||
assert response['data']['text'] == 'text for brand'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('data_update', [
|
||||
@@ -108,6 +145,38 @@ def test_post_update_email_branding_updates_field(admin_request, notify_db_sessi
|
||||
|
||||
email_branding = EmailBranding.query.all()
|
||||
|
||||
assert len(email_branding) == 1
|
||||
assert str(email_branding[0].id) == email_branding_id
|
||||
for key in data_update.keys():
|
||||
assert getattr(email_branding[0], key) == data_update[key]
|
||||
assert email_branding[0].text == email_branding[0].name
|
||||
|
||||
|
||||
@pytest.mark.parametrize('data_update', [
|
||||
({'text': 'text email branding'}),
|
||||
({'text': 'new text', 'name': 'new name'}),
|
||||
])
|
||||
def test_post_update_email_branding_updates_field_with_text(admin_request, notify_db_session, data_update):
|
||||
data = {
|
||||
'name': 'test email_branding',
|
||||
'logo': 'images/text_x2.png'
|
||||
}
|
||||
response = admin_request.post(
|
||||
'email_branding.create_email_branding',
|
||||
_data=data,
|
||||
_expected_status=201
|
||||
)
|
||||
|
||||
email_branding_id = response['data']['id']
|
||||
|
||||
response = admin_request.post(
|
||||
'email_branding.update_email_branding',
|
||||
_data=data_update,
|
||||
email_branding_id=email_branding_id
|
||||
)
|
||||
|
||||
email_branding = EmailBranding.query.all()
|
||||
|
||||
assert len(email_branding) == 1
|
||||
assert str(email_branding[0].id) == email_branding_id
|
||||
for key in data_update.keys():
|
||||
|
||||
Reference in New Issue
Block a user