Esempio n. 1
0
    def test_build_schedule_item(self):
        '''
        Test if it build a schedule job.
        '''
        comment = 'Unable to use "seconds", "minutes", "hours", ' \
                  'or "days" with "when" or "cron" options.'
        comment1 = 'Unable to use "when" and "cron" ' \
                   'options together.  Ignoring.'
        with patch.dict(schedule.__opts__, {'job1': {}}):
            self.assertDictEqual(schedule.build_schedule_item(''),
                                 {'comment': 'Job name is required.',
                                  'result': False})

            self.assertDictEqual(schedule.build_schedule_item
                                 ('job1', function='test.ping'),
                                 {'function': 'test.ping', 'maxrunning': 1,
                                  'name': 'job1', 'jid_include': True,
                                  'enabled': True})

            self.assertDictEqual(schedule.build_schedule_item
                                 ('job1', function='test.ping', seconds=3600,
                                  when='2400'),
                                 {'comment': comment, 'result': False})

            self.assertDictEqual(schedule.build_schedule_item
                                 ('job1', function='test.ping', when='2400',
                                  cron='2'),
                                 {'comment': comment1, 'result': False})
Esempio n. 2
0
    def test_build_schedule_item(self):
        '''
        Test if it build a schedule job.
        '''
        comment = 'Unable to use "seconds", "minutes", "hours", ' \
                  'or "days" with "when" or "cron" options.'
        comment1 = 'Unable to use "when" and "cron" ' \
                   'options together.  Ignoring.'
        with patch.dict(schedule.__opts__, {'job1': {}}):
            self.assertDictEqual(schedule.build_schedule_item(''),
                                 {'comment': 'Job name is required.',
                                  'result': False})

            self.assertDictEqual(schedule.build_schedule_item
                                 ('job1', function='test.ping'),
                                 {'function': 'test.ping', 'maxrunning': 1,
                                  'name': 'job1', 'jid_include': True,
                                  'enabled': True})

            self.assertDictEqual(schedule.build_schedule_item
                                 ('job1', function='test.ping', seconds=3600,
                                  when='2400'),
                                 {'comment': comment, 'result': False})

            self.assertDictEqual(schedule.build_schedule_item
                                 ('job1', function='test.ping', when='2400',
                                  cron='2'),
                                 {'comment': comment1, 'result': False})
Esempio n. 3
0
    def test_build_schedule_item(self):
        """
        Test if it build a schedule job.
        """
        comment = ('Unable to use "seconds", "minutes", "hours", '
                   'or "days" with "when" or "cron" options.')
        comment1 = 'Unable to use "when" and "cron" ' "options together.  Ignoring."
        with patch.dict(schedule.__opts__, {"job1": {}}):
            self.assertDictEqual(
                schedule.build_schedule_item(""),
                {
                    "comment": "Job name is required.",
                    "result": False
                },
            )

            self.assertDictEqual(
                schedule.build_schedule_item("job1", function="test.ping"),
                {
                    "function": "test.ping",
                    "maxrunning": 1,
                    "name": "job1",
                    "jid_include": True,
                    "enabled": True,
                },
            )

            self.assertDictEqual(
                schedule.build_schedule_item("job1",
                                             function="test.ping",
                                             seconds=3600,
                                             when="2400"),
                {
                    "comment": comment,
                    "result": False
                },
            )

            self.assertDictEqual(
                schedule.build_schedule_item("job1",
                                             function="test.ping",
                                             when="2400",
                                             cron="2"),
                {
                    "comment": comment1,
                    "result": False
                },
            )
Esempio n. 4
0
 def test_build_schedule_item_invalid_when(self):
     '''
     Test if it build a schedule job.
     '''
     comment = 'Schedule item garbage for "when" in invalid.'
     with patch.dict(schedule.__opts__, {'job1': {}}):
         self.assertDictEqual(schedule.build_schedule_item
                              ('job1', function='test.ping', when='garbage'),
                              {'comment': comment, 'result': False})
Esempio n. 5
0
 def test_build_schedule_item_invalid_when(self):
     """
     Test if it build a schedule job.
     """
     comment = 'Schedule item garbage for "when" in invalid.'
     with patch.dict(schedule.__opts__, {"job1": {}}):
         self.assertDictEqual(
             schedule.build_schedule_item(
                 "job1", function="test.ping", when="garbage"
             ),
             {"comment": comment, "result": False},
         )
Esempio n. 6
0
def test_build_schedule_item_invalid_jobs_args(sock_dir):
    """
    Test failure if job_arg and job_kwargs are passed correctly
    """
    comment1 = "job_kwargs is not a dict. please correct and try again."
    comment2 = "job_args is not a list. please correct and try again."
    with patch.dict(schedule.__opts__, {"job1": {}}):
        assert schedule.build_schedule_item("job1",
                                            function="test.args",
                                            job_kwargs=[{
                                                "key1": "value1"
                                            }]) == {
                                                "comment": comment1,
                                                "result": False
                                            }
    with patch.dict(schedule.__opts__, {"job1": {}}):
        assert schedule.build_schedule_item("job1",
                                            function="test.args",
                                            job_args={"positional"}) == {
                                                "comment": comment2,
                                                "result": False
                                            }