mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-16 10:12:32 -05:00
Removed template subject uniqueness
This commit is contained in:
@@ -178,7 +178,7 @@ class Template(db.Model, Versioned):
|
||||
archived = db.Column(db.Boolean, index=False, nullable=False, default=False)
|
||||
service_id = db.Column(UUID(as_uuid=True), db.ForeignKey('services.id'), index=True, unique=False, nullable=False)
|
||||
service = db.relationship('Service', backref=db.backref('templates', lazy='dynamic'))
|
||||
subject = db.Column(db.Text, index=False, unique=True, nullable=True)
|
||||
subject = db.Column(db.Text, index=False, unique=False, nullable=True)
|
||||
created_by_id = db.Column(UUID(as_uuid=True), db.ForeignKey('users.id'), index=True, nullable=False)
|
||||
created_by = db.relationship('User')
|
||||
|
||||
|
||||
@@ -50,16 +50,7 @@ def create_template(service_id):
|
||||
new_template.template_type)
|
||||
if over_limit:
|
||||
return json_resp, 400
|
||||
try:
|
||||
dao_create_template(new_template)
|
||||
except IntegrityError as ex:
|
||||
current_app.logger.debug(ex)
|
||||
message = "Failed to create template"
|
||||
if "templates_subject_key" in str(ex):
|
||||
message = 'Duplicate template subject'
|
||||
return jsonify(result="error", message={'subject': [message]}), 400
|
||||
return jsonify(result="error", message=message), 500
|
||||
|
||||
dao_create_template(new_template)
|
||||
return jsonify(data=template_schema.dump(new_template).data), 201
|
||||
|
||||
|
||||
|
||||
26
migrations/versions/0018_remove_subject_uniqueness.py
Normal file
26
migrations/versions/0018_remove_subject_uniqueness.py
Normal file
@@ -0,0 +1,26 @@
|
||||
"""empty message
|
||||
|
||||
Revision ID: 0018_remove_subject_uniqueness
|
||||
Revises: 0017_add_failure_types
|
||||
Create Date: 2016-05-18 09:39:22.512042
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '0018_remove_subject_uniqueness'
|
||||
down_revision = '0017_add_failure_types'
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
def upgrade():
|
||||
### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_constraint('templates_subject_key', 'templates', type_='unique')
|
||||
### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_unique_constraint('templates_subject_key', 'templates', ['subject'])
|
||||
### end Alembic commands ###
|
||||
@@ -155,49 +155,6 @@ def test_must_have_a_subject_on_an_email_template(notify_api, sample_user, sampl
|
||||
assert json_resp['message'] == {'subject': ['Invalid template subject']}
|
||||
|
||||
|
||||
def test_must_have_a_uniqe_subject_on_an_email_template(notify_api, sample_user, sample_service):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
data = {
|
||||
'name': 'my template',
|
||||
'template_type': 'email',
|
||||
'subject': 'subject',
|
||||
'content': 'template content',
|
||||
'service': str(sample_service.id),
|
||||
'created_by': str(sample_user.id)
|
||||
}
|
||||
data = json.dumps(data)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
response = client.post(
|
||||
'/service/{}/template'.format(sample_service.id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header],
|
||||
data=data
|
||||
)
|
||||
assert response.status_code == 201
|
||||
|
||||
data = {
|
||||
'name': 'my template',
|
||||
'template_type': 'email',
|
||||
'subject': 'subject',
|
||||
'content': 'template content',
|
||||
'service': str(sample_service.id),
|
||||
'created_by': str(sample_user.id)
|
||||
}
|
||||
data = json.dumps(data)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
response = client.post(
|
||||
'/service/{}/template'.format(sample_service.id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header],
|
||||
data=data
|
||||
)
|
||||
assert response.status_code == 400
|
||||
json_resp = json.loads(response.get_data(as_text=True))
|
||||
assert json_resp['result'] == 'error'
|
||||
assert json_resp['message']['subject'][0] == 'Duplicate template subject'
|
||||
|
||||
|
||||
def test_should_be_able_to_update_a_template(notify_api, sample_user, sample_service):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
|
||||
Reference in New Issue
Block a user