mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-31 23:26:23 -05:00
Added some more tests.
Removed the validation in the schema - it was adding complexity, let the unique constraint on the db throw the exception. This should only ever happen on a race condition which seems unlikely (two people changing a service to the same name at the same time) Do no set debug=true to the test config. If debug=true it changes the behaviour of the error handlers, throwing the exception rather than returning a 500.
This commit is contained in:
@@ -73,21 +73,6 @@ class ServiceSchema(BaseSchema):
|
||||
model = models.Service
|
||||
exclude = ("updated_at", "created_at", "api_keys", "templates", "jobs", 'old_id')
|
||||
|
||||
@validates_schema
|
||||
def validate_all(self, data):
|
||||
# There are 2 instances where we want to check
|
||||
# for duplicate service name. One when they updating
|
||||
# an existing service and when they are creating a service
|
||||
name = data.get('name', None)
|
||||
service = models.Service.query.filter_by(name=name).first()
|
||||
error_msg = "Duplicate service name '{}'".format(name)
|
||||
if 'id' in data:
|
||||
if service and str(service.id) != data['id']:
|
||||
raise ValidationError(error_msg, 'name')
|
||||
else:
|
||||
if service:
|
||||
raise ValidationError(error_msg, 'name')
|
||||
|
||||
|
||||
class TemplateSchema(BaseSchema):
|
||||
class Meta:
|
||||
|
||||
Reference in New Issue
Block a user