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:
Rebecca Law
2016-04-01 13:42:11 +01:00
parent 8df4919029
commit 8493e29acc
3 changed files with 71 additions and 27 deletions

View File

@@ -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: