reformat code with black
This commit is contained in:
+13
-7
@@ -5,7 +5,6 @@ from api.models.market import iter_markets
|
||||
|
||||
|
||||
class ValidationError(Exception):
|
||||
|
||||
def __init__(self, message):
|
||||
Exception.__init__(self)
|
||||
self.message = message
|
||||
@@ -13,7 +12,7 @@ class ValidationError(Exception):
|
||||
|
||||
def _check_parameter_exists(param):
|
||||
if not param in request.args:
|
||||
raise ValidationError('No {} is specified'.format(param))
|
||||
raise ValidationError("No {} is specified".format(param))
|
||||
|
||||
|
||||
def _is_number(s):
|
||||
@@ -29,7 +28,7 @@ def validate_jsonschema(schema):
|
||||
@wraps(f)
|
||||
def wrapper(*args, **kwargs):
|
||||
if not request.json:
|
||||
raise ValidationError('Payload is not valid json')
|
||||
raise ValidationError("Payload is not valid json")
|
||||
try:
|
||||
j = request.json
|
||||
jsonschema.validate(j, schema)
|
||||
@@ -38,7 +37,9 @@ def validate_jsonschema(schema):
|
||||
except jsonschema.SchemaError as e:
|
||||
raise ValidationError(e.message)
|
||||
return f(*args, **kwargs)
|
||||
|
||||
return wrapper
|
||||
|
||||
return decorator
|
||||
|
||||
|
||||
@@ -49,7 +50,9 @@ def validate_exists(*keys):
|
||||
for key in keys:
|
||||
_check_parameter_exists(key)
|
||||
return f(*args, **kwargs)
|
||||
|
||||
return wrapper
|
||||
|
||||
return decorator
|
||||
|
||||
|
||||
@@ -61,9 +64,11 @@ def validate_number(*keys):
|
||||
_check_parameter_exists(key)
|
||||
value = request.args.get(key)
|
||||
if not _is_number(value):
|
||||
raise ValidationError('{} is not a number'.format(key))
|
||||
raise ValidationError("{} is not a number".format(key))
|
||||
return f(*args, **kwargs)
|
||||
|
||||
return wrapper
|
||||
|
||||
return decorator
|
||||
|
||||
|
||||
@@ -73,7 +78,7 @@ def validate_territory(*keys):
|
||||
def wrapper(*args, **kwargs):
|
||||
for key in keys:
|
||||
if not key in request.args:
|
||||
raise ValidationError('No {} is specified'.format(key))
|
||||
raise ValidationError("No {} is specified".format(key))
|
||||
value = request.args.get(key)
|
||||
valid = False
|
||||
for market in iter_markets():
|
||||
@@ -82,9 +87,10 @@ def validate_territory(*keys):
|
||||
break
|
||||
|
||||
if not valid:
|
||||
raise ValidationError(
|
||||
'{} is not a valid territory'.format(value))
|
||||
raise ValidationError("{} is not a valid territory".format(value))
|
||||
|
||||
return f(*args, **kwargs)
|
||||
|
||||
return wrapper
|
||||
|
||||
return decorator
|
||||
|
||||
Reference in New Issue
Block a user