Esempio n. 1
0
    def test_list(self):
        '''
        Test if it list the jobs currently scheduled on the minion.
        '''
        with patch.dict(schedule.__opts__, {
                'schedule': {
                    '_seconds': []
                },
                'sock_dir': SOCK_DIR
        }):
            mock = MagicMock(return_value=True)
            with patch.dict(schedule.__salt__, {'event.fire': mock}):
                _ret_value = {'complete': True, 'schedule': {'_seconds': []}}
                with patch.object(SaltEvent,
                                  'get_event',
                                  return_value=_ret_value):
                    self.assertEqual(schedule.list_(),
                                     'schedule:\n  _seconds: []\n')
                    self.assertDictEqual(
                        schedule.list_(show_all=True, return_yaml=False),
                        {'_seconds': []})

        with patch.dict(schedule.__opts__, {
                'schedule': {},
                'sock_dir': SOCK_DIR
        }):
            mock = MagicMock(return_value=True)
            with patch.dict(schedule.__salt__, {'event.fire': mock}):
                _ret_value = {'complete': True, 'schedule': {}}
                with patch.object(SaltEvent,
                                  'get_event',
                                  return_value=_ret_value):
                    self.assertDictEqual(schedule.list_(), {'schedule': {}})
Esempio n. 2
0
    def test_list(self):
        '''
        Test if it list the jobs currently scheduled on the minion.
        '''
        with patch.dict(schedule.__opts__, {'schedule': {'_seconds': []}}):
            self.assertEqual(schedule.list_(), 'schedule:\n  _seconds: []\n')
            self.assertDictEqual(schedule.list_(True, False), {'_seconds': []})

        with patch.dict(schedule.__opts__, {'schedule': {}}):
            self.assertDictEqual(schedule.list_(), {'schedule': {}})
Esempio n. 3
0
    def test_list(self):
        '''
        Test if it list the jobs currently scheduled on the minion.
        '''
        with patch.dict(schedule.__opts__, {'schedule': {'_seconds': []}, 'sock_dir': SOCK_DIR}):
            mock = MagicMock(return_value=True)
            with patch.dict(schedule.__salt__, {'event.fire': mock}):
                _ret_value = {'complete': True, 'schedule': {'_seconds': []}}
                with patch.object(SaltEvent, 'get_event', return_value=_ret_value):
                    self.assertEqual(schedule.list_(), 'schedule:\n  _seconds: []\n')
                    self.assertDictEqual(schedule.list_(show_all=True, return_yaml=False), {'_seconds': []})

        with patch.dict(schedule.__opts__, {'schedule': {}, 'sock_dir': SOCK_DIR}):
            mock = MagicMock(return_value=True)
            with patch.dict(schedule.__salt__, {'event.fire': mock}):
                _ret_value = {'complete': True, 'schedule': {}}
                with patch.object(SaltEvent, 'get_event', return_value=_ret_value):
                    self.assertDictEqual(schedule.list_(), {'schedule': {}})
Esempio n. 4
0
def test_list(sock_dir, job1):
    """
    Test schedule.list
    """
    _schedule_data = {"job1": job1}
    with patch.dict(schedule.__opts__, {"schedule": {}, "sock_dir": sock_dir}):
        mock = MagicMock(return_value=True)
        with patch.dict(schedule.__salt__, {"event.fire": mock}):
            _ret_schedule_data = {
                "function": "test.ping",
                "seconds": 10,
                "maxrunning": 1,
                "name": "job1",
                "enabled": True,
                "jid_include": True,
            }
            _ret_value = {
                "complete": True,
                "schedule": {
                    "job1": _ret_schedule_data
                }
            }
            saved_schedule = """schedule:
  job1: {enabled: true, function: test.ping, jid_include: true, maxrunning: 1, name: job1,
    seconds: 10}
"""

            expected = """schedule:
  job1:
    enabled: true
    function: test.ping
    jid_include: true
    maxrunning: 1
    name: job1
    saved: true
    seconds: 10
"""

            with patch.object(SaltEvent, "get_event", return_value=_ret_value):
                with patch(
                        "os.path.exists", MagicMock(return_value=True)), patch(
                            "salt.utils.files.fopen",
                            mock_open(read_data=saved_schedule)) as fopen_mock:
                    ret = schedule.list_(offline=True)
                    assert ret == expected

    _schedule_data = {"job1": job1}
    with patch.dict(schedule.__opts__, {"schedule": {}, "sock_dir": sock_dir}):
        mock = MagicMock(return_value=True)
        with patch.dict(schedule.__salt__, {"event.fire": mock}):
            _ret_schedule_data = {
                "function": "test.ping",
                "seconds": 10,
                "maxrunning": 1,
                "name": "job1",
                "enabled": True,
                "jid_include": True,
            }
            _ret_value = {
                "complete": True,
                "schedule": {
                    "job1": _ret_schedule_data
                }
            }
            expected = """schedule:
  job1:
    enabled: true
    function: test.ping
    jid_include: true
    maxrunning: 1
    name: job1
    saved: false
    seconds: 10
"""
            with patch.object(SaltEvent, "get_event", return_value=_ret_value):
                with patch("os.path.exists",
                           MagicMock(return_value=True)), patch(
                               "salt.utils.files.fopen",
                               mock_open(read_data="")) as fopen_mock:
                    ret = schedule.list_()
                    assert ret == expected

    _schedule_data = {"job1": job1}
    with patch.dict(schedule.__opts__, {"schedule": {}, "sock_dir": sock_dir}):
        mock = MagicMock(return_value=True)
        with patch.dict(schedule.__salt__, {"event.fire": mock}):
            _ret_schedule_data = {
                "function": "test.ping",
                "seconds": 10,
                "maxrunning": 1,
                "name": "job1",
                "enabled": True,
                "jid_include": True,
            }
            _ret_value = {
                "complete": True,
                "schedule": {
                    "job1": _ret_schedule_data
                }
            }
            saved_schedule = """schedule:
  job1: {enabled: true, function: test.ping, jid_include: true, maxrunning: 1, name: job1,
    seconds: 10}
"""

            expected = """schedule:
  job1:
    enabled: true
    function: test.ping
    jid_include: true
    maxrunning: 1
    name: job1
    saved: true
    seconds: 10
"""
            with patch.object(SaltEvent, "get_event", return_value=_ret_value):
                with patch(
                        "os.path.exists", MagicMock(return_value=True)), patch(
                            "salt.utils.files.fopen",
                            mock_open(read_data=saved_schedule)) as fopen_mock:
                    ret = schedule.list_()
                    assert ret == expected