Exemple #1
0
    def test_get_schedule_token(self, repository_mock, time_mock):
        repository = mock.Mock()
        repository_mock.return_value = repository

        schedule_config = WorkflowScheduleConfig()
        schedule_config.workflow = 'some_workflow'
        schedule_config.start_date = '2012-01-01'
        schedule_config.time = '00.00.01.000'
        schedule_config.recurrence = '1d'
        schedule_config.overrun_policy = 'START_NEW'
        schedule_config.emails = [
            '*****@*****.**', '*****@*****.**'
        ]
        repository.get_schedule.return_value = schedule_config

        time_mock.return_value = 100.  # the value must be a float

        parser = RepositoryConfigParser()

        schedule_token = parser.get_schedule_token('some_workflow')

        self.assertEqual('/schedule/workflow/some_workflow',
                         schedule_token.name)
        # 1325376000 = 01 Jan 2012 00:00:00 UTC
        self.assertEqual(1325376000, schedule_token.expirationTime)
        schedule = pickle.loads(schedule_token.data)
        self.assertEqual(1325376000, schedule.next_run_time)
        self.assertEqual(24 * 60 * 60, schedule.recurrence_seconds)
        self.assertEqual(OverrunPolicy.START_NEW, schedule.overrun_policy)
        self.assertEqual('some_workflow', schedule.workflow)
        self.assertEqual(
            ['*****@*****.**', '*****@*****.**'],
            schedule.emails)

        repository.get_schedule.assert_called_once_with('some_workflow')
Exemple #2
0
 def test_put_schedule(self):
     schedule_config = WorkflowScheduleConfig.from_json(
         _SCHEDULE_TEMPLATE % '1w')
     self._repository.put_schedule(schedule_config)
     self.assertEqual(1, len(self._repository.configs))
     self.assertEqual(
         _SCHEDULE_TEMPLATE % '1w',
         self._repository.configs['/workflow/some_workflow/schedule'])
Exemple #3
0
 def test_from_json(self):
     schedule_config = WorkflowScheduleConfig.from_json(WorkflowScheduleConfigTestCase._SCHEDULE_JSON)
     self.assertEqual(["*****@*****.**", "*****@*****.**"], schedule_config.emails)
     self.assertEqual("DELAY", schedule_config.overrun_policy)
     self.assertEqual("1d", schedule_config.recurrence)
     self.assertEqual("2012-01-01", schedule_config.start_date)
     self.assertEqual("00.00.01.000", schedule_config.time)
     self.assertEqual("some_workflow", schedule_config.workflow)
 def test_put_schedule(self):
     schedule_config = WorkflowScheduleConfig.from_json(
         _SCHEDULE_TEMPLATE % '1w')
     self._repository.put_schedule(schedule_config)
     self.assertEqual(1, len(self._repository.configs))
     self.assertEqual(
         _SCHEDULE_TEMPLATE % '1w',
         self._repository.configs['/workflow/some_workflow/schedule'])
    def test_get_schedule_token(self, repository_mock, time_mock):
        repository = mock.Mock()
        repository_mock.return_value = repository

        schedule_config = WorkflowScheduleConfig()
        schedule_config.workflow = 'some_workflow'
        schedule_config.start_date = '2012-01-01'
        schedule_config.time = '00.00.01.000'
        schedule_config.recurrence = '1d'
        schedule_config.overrun_policy = 'START_NEW'
        schedule_config.emails = ['*****@*****.**',
                                  '*****@*****.**']
        repository.get_schedule.return_value = schedule_config

        time_mock.return_value = 100.  # the value must be a float

        parser = RepositoryConfigParser()

        schedule_token = parser.get_schedule_token('some_workflow')

        self.assertEqual('/schedule/workflow/some_workflow',
                         schedule_token.name)
        # 1325376000 = 01 Jan 2012 00:00:00 UTC
        self.assertEqual(1325376000, schedule_token.expirationTime)
        schedule = pickle.loads(schedule_token.data)
        self.assertEqual(1325376000, schedule.next_run_time)
        self.assertEqual(24 * 60 * 60, schedule.recurrence_seconds)
        self.assertEqual(OverrunPolicy.START_NEW, schedule.overrun_policy)
        self.assertEqual('some_workflow', schedule.workflow)
        self.assertEqual(['*****@*****.**',
                          '*****@*****.**'], schedule.emails)

        repository.get_schedule.assert_called_once_with('some_workflow')
Exemple #6
0
 def test_format(self):
     schedule_config = WorkflowScheduleConfig.from_json(WorkflowScheduleConfigTestCase._SCHEDULE_JSON)
     formatted_config = schedule_config.format()
     self.assertEqual(["*****@*****.**", "*****@*****.**"], formatted_config["emails"])
     self.assertEqual("DELAY", formatted_config["overrun_policy"])
     self.assertEqual("1d", formatted_config["recurrence"])
     self.assertEqual("2012-01-01", formatted_config["start_date"])
     self.assertEqual("00.00.01.000", formatted_config["time"])
     self.assertEqual("some_workflow", formatted_config["workflow"])
Exemple #7
0
 def test_from_json(self):
     schedule_config = WorkflowScheduleConfig.from_json(
         WorkflowScheduleConfigTestCase._SCHEDULE_JSON)
     self.assertEqual(['*****@*****.**',
                       '*****@*****.**'],
                      schedule_config.emails)
     self.assertEqual('DELAY', schedule_config.overrun_policy)
     self.assertEqual('1d', schedule_config.recurrence)
     self.assertEqual('2012-01-01', schedule_config.start_date)
     self.assertEqual('00.00.01.000', schedule_config.time)
     self.assertEqual('some_workflow', schedule_config.workflow)
Exemple #8
0
 def test_from_json(self):
     schedule_config = WorkflowScheduleConfig.from_json(
         WorkflowScheduleConfigTestCase._SCHEDULE_JSON)
     self.assertEqual(['*****@*****.**',
                       '*****@*****.**'],
                      schedule_config.emails)
     self.assertEqual('DELAY', schedule_config.overrun_policy)
     self.assertEqual('1d', schedule_config.recurrence)
     self.assertEqual('2012-01-01', schedule_config.start_date)
     self.assertEqual('00.00.01.000', schedule_config.time)
     self.assertEqual('some_workflow', schedule_config.workflow)
Exemple #9
0
    def get_schedule(self, workflow):
        """Retrieve schedule config for a given workflow.

        Args:
            workflow: The workflow name whose schedule should be retrieved.
        Returns:
            The schedule config.
        """
        path = Path(workflow=workflow)
        schedule_json = self._get_config(path.get_schedule_path())
        return WorkflowScheduleConfig.from_json(schedule_json)
Exemple #10
0
    def get_schedule(self, workflow):
        """Retrieve schedule config for a given workflow.

        Args:
            workflow: The workflow name whose schedule should be retrieved.
        Returns:
            The schedule config.
        """
        path = Path(workflow=workflow)
        schedule_json = self._get_config(path.get_schedule_path())
        return WorkflowScheduleConfig.from_json(schedule_json)
Exemple #11
0
 def test_format(self):
     schedule_config = WorkflowScheduleConfig.from_json(
         WorkflowScheduleConfigTestCase._SCHEDULE_JSON)
     formatted_config = schedule_config.format()
     self.assertEqual(['*****@*****.**',
                       '*****@*****.**'],
                      formatted_config['emails'])
     self.assertEqual('DELAY', formatted_config['overrun_policy'])
     self.assertEqual('1d', formatted_config['recurrence'])
     self.assertEqual('2012-01-01', formatted_config['start_date'])
     self.assertEqual('00.00.01.000', formatted_config['time'])
     self.assertEqual('some_workflow', formatted_config['workflow'])
Exemple #12
0
 def test_format(self):
     schedule_config = WorkflowScheduleConfig.from_json(
         WorkflowScheduleConfigTestCase._SCHEDULE_JSON)
     formatted_config = schedule_config.format()
     self.assertEqual(['*****@*****.**',
                       '*****@*****.**'],
                      formatted_config['emails'])
     self.assertEqual('DELAY', formatted_config['overrun_policy'])
     self.assertEqual('1d', formatted_config['recurrence'])
     self.assertEqual('2012-01-01', formatted_config['start_date'])
     self.assertEqual('00.00.01.000', formatted_config['time'])
     self.assertEqual('some_workflow', formatted_config['workflow'])
Exemple #13
0
 def test_delete_schedule(self):
     schedule_config = WorkflowScheduleConfig.from_json(
         _SCHEDULE_TEMPLATE % 100)
     self._repository.put_schedule(schedule_config)
     self._repository.delete_schedule('some_workflow')
     self.assertEqual({}, self._repository.configs)
 def test_delete_schedule(self):
     schedule_config = WorkflowScheduleConfig.from_json(
         _SCHEDULE_TEMPLATE % 100)
     self._repository.put_schedule(schedule_config)
     self._repository.delete_schedule('some_workflow')
     self.assertEqual({}, self._repository.configs)