diff --git a/app/job/rest.py b/app/job/rest.py index 338e4d8cf..d9cf14404 100644 --- a/app/job/rest.py +++ b/app/job/rest.py @@ -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 }) diff --git a/app/schemas.py b/app/schemas.py index e0300dbd3..3cc1acc16 100644 --- a/app/schemas.py +++ b/app/schemas.py @@ -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 diff --git a/config.py b/config.py index 6d9539552..e71a5d51a 100644 --- a/config.py +++ b/config.py @@ -52,7 +52,7 @@ class Config(object): CELERYBEAT_SCHEDULE = { 'run-scheduled-jobs': { 'task': 'run-scheduled-jobs', - 'schedule': crontab(minute=1), + 'schedule': crontab(), 'options': {'queue': 'periodic'} }, 'delete-verify-codes': { diff --git a/tests/app/notifications/rest/test_notification_statistics.py b/tests/app/notifications/rest/test_notification_statistics.py index 769fd7395..6e9de437a 100644 --- a/tests/app/notifications/rest/test_notification_statistics.py +++ b/tests/app/notifications/rest/test_notification_statistics.py @@ -2,6 +2,7 @@ from datetime import date, timedelta from flask import json from freezegun import freeze_time +from datetime import datetime from tests import create_authorization_header from tests.app.conftest import ( @@ -196,7 +197,6 @@ def test_get_notification_statistics_returns_both_existing_stats_and_generated_z assert response.status_code == 200 -@freeze_time('1955-11-05T12:00:00') def test_get_notification_statistics_returns_zeros_when_only_stats_for_different_date( notify_api, sample_notification_statistics @@ -208,7 +208,7 @@ def test_get_notification_statistics_returns_zeros_when_only_stats_for_different service_id=sample_notification_statistics.service_id ) response = client.get( - '/notifications/statistics?day={}'.format(date.today().isoformat()), + '/notifications/statistics?day={}'.format(datetime.utcnow().isoformat()), headers=[auth_header] )