예제 #1
0
def read_datetime_from_config(key, config_obj, *, default=None):
    value = config_obj.get(key)
    if value is None:
        return default

    if isinstance(value, datetime):
        return value

    if isinstance(value, str):
        return date_utils.parse_iso_datetime(value)

    raise InvalidValueTypeException('"' + key + '" field should be a datetime, but was ' + repr(value))
예제 #2
0
def to_datetime(short_datetime_string):
    dt_string = short_datetime_string + ':0.000000Z'
    return date_utils.parse_iso_datetime(dt_string.replace(' ', 'T'))
import os
import time
from datetime import timedelta
from typing import Sequence
from unittest import TestCase
from unittest.mock import patch, ANY, MagicMock

from auth.user import User
from scheduling import schedule_service
from scheduling.schedule_config import ScheduleConfig, InvalidScheduleException
from scheduling.schedule_service import ScheduleService, InvalidUserException, UnavailableScriptException
from scheduling.scheduling_job import SchedulingJob
from tests import test_utils
from utils import date_utils, audit_utils, file_utils

mocked_now = date_utils.parse_iso_datetime('2020-07-24T12:30:59.000000Z')
mocked_now_epoch = mocked_now.timestamp()


class ScheduleServiceTestCase(TestCase):
    def assert_schedule_calls(self, expected_job_time_pairs):
        self.assertEqual(len(expected_job_time_pairs), len(self.scheduler_mock.enterabs.call_args_list))

        for i, pair in enumerate(expected_job_time_pairs):
            expected_time = date_utils.sec_to_datetime(pair[1])
            expected_job = pair[0]

            # the first item of call_args is actual arguments, passed to the method
            args = self.scheduler_mock.enterabs.call_args_list[i][0]

            # we schedule job as enterabs(expected_time, priority, self._execute_job, (job,))
예제 #4
0
 def test_parse_correct_time(self):
     parsed = date_utils.parse_iso_datetime('2020-07-10T15:30:59.123456Z')
     expected = datetime(2020, 7, 10, 15, 30, 59, 123456, timezone.utc)
     self.assertEqual(expected, parsed)