Using UTC dates on API validation for scheduled jobs.

This commit is contained in:
Martyn Inglis
2016-08-30 12:47:33 +01:00
parent 8b9319ac7a
commit b923392c49
4 changed files with 18 additions and 7 deletions

View File

@@ -101,6 +101,7 @@ def create_job(service_id):
dao_fetch_service_by_id(service_id)
data = request.get_json()
data.update({
"service": service_id
})

View File

@@ -39,7 +39,7 @@ def _validate_positive_number(value, msg="Not a positive integer"):
raise ValidationError(msg)
def _validate_not_more_than_24_hours_in_future(dte, msg="Date cannot be more than 24hrs in the future"):
def _validate_datetime_not_more_than_24_hours_in_future(dte, msg="Date cannot be more than 24hrs in the future"):
if dte > datetime.utcnow() + timedelta(hours=24):
raise ValidationError(msg)
@@ -50,7 +50,17 @@ def _validate_not_in_future(dte, msg="Date cannot be in the future"):
def _validate_not_in_past(dte, msg="Date cannot be in the past"):
if dte < datetime.today():
if dte < date.today():
raise ValidationError(msg)
def _validate_datetime_not_in_future(dte, msg="Date cannot be in the future"):
if dte > datetime.utcnow():
raise ValidationError(msg)
def _validate_datetime_not_in_past(dte, msg="Date cannot be in the past"):
if dte < datetime.utcnow():
raise ValidationError(msg)
@@ -223,8 +233,8 @@ class JobSchema(BaseSchema):
@validates('scheduled_for')
def validate_scheduled_for(self, value):
_validate_not_in_past(value)
_validate_not_more_than_24_hours_in_future(value)
_validate_datetime_not_in_past(value)
_validate_datetime_not_more_than_24_hours_in_future(value)
class Meta:
model = models.Job