mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-25 18:02:40 -05:00
The regex to validate uuids was not rejecting uuids with a space at the end.
Switched to using a isinstance check on the string. Added an order by clause to dao_get_template_usage_stats_by_service, it was causing an itermitten failure in the tests.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from notifications_utils.statsd_decorators import statsd
|
||||
from sqlalchemy import or_, and_
|
||||
from sqlalchemy import or_, and_, desc
|
||||
|
||||
from app import db
|
||||
from app.dao.dao_utils import transactional
|
||||
@@ -54,4 +54,6 @@ def dao_get_template_usage_stats_by_service(service_id, year):
|
||||
StatsTemplateUsageByMonth.year == year + 1
|
||||
)
|
||||
)
|
||||
).order_by(
|
||||
desc(StatsTemplateUsageByMonth.month)
|
||||
).all()
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import json
|
||||
from datetime import datetime, timedelta
|
||||
from uuid import UUID
|
||||
|
||||
from iso8601 import iso8601, ParseError
|
||||
from jsonschema import (Draft4Validator, ValidationError, FormatChecker)
|
||||
@@ -10,6 +11,12 @@ from notifications_utils.recipients import (validate_phone_number, validate_emai
|
||||
def validate(json_to_validate, schema):
|
||||
format_checker = FormatChecker()
|
||||
|
||||
@format_checker.checks("validate_uuid", raises=Exception)
|
||||
def validate_uuid(instance):
|
||||
if isinstance(instance, str):
|
||||
UUID(instance)
|
||||
return True
|
||||
|
||||
@format_checker.checks('phone_number', raises=InvalidPhoneError)
|
||||
def validate_schema_phone_number(instance):
|
||||
if isinstance(instance, str):
|
||||
|
||||
@@ -5,7 +5,7 @@ If the definition is specific to a version put it in a definition file in the ve
|
||||
|
||||
uuid = {
|
||||
"type": "string",
|
||||
"pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$",
|
||||
"format": "validate_uuid",
|
||||
"validationMessage": "is not a valid UUID",
|
||||
"code": "1001", # yet to be implemented
|
||||
"link": "link to our error documentation not yet implemented"
|
||||
|
||||
Reference in New Issue
Block a user