Esempio n. 1
0
    def test_present(self):
        '''
        Test to add a job to queue.
        '''
        name = 'jboss'
        timespec = '9:09 11/04/15'
        tag = 'love'
        user = '******'

        ret = {'name': name,
               'result': True,
               'changes': {},
               'comment': ''}

        mock = MagicMock(return_value=False)
        with patch.dict(at.__opts__, {'test': False}):
            with patch.dict(at.__grains__, {'os_family': 'Redhat'}):
                with patch.dict(at.__salt__, {'cmd.run': mock}):
                    ret.update({'comment': False})
                    self.assertDictEqual(at.present(name, timespec, tag),
                                         ret)

                with patch.dict(at.__salt__, {'user.info': mock}):
                    comt = 'User: {0} is not exists'.format(user)
                    ret.update({'comment': comt, 'result': False})
                    self.assertDictEqual(at.present(name, timespec, tag, user),
                                         ret)

        with patch.dict(at.__opts__, {'test': True}):
            comt = 'job {0} is add and will run on {1}'.format(name, timespec)
            ret.update({'comment': comt, 'result': None})
            self.assertDictEqual(at.present(name, timespec, tag, user), ret)
Esempio n. 2
0
    def test_present(self):
        '''
        Test to add a job to queue.
        '''
        name = 'jboss'
        timespec = '9:09 11/04/15'
        tag = 'love'
        user = '******'

        ret = {'name': name, 'result': True, 'changes': {}, 'comment': ''}

        mock = MagicMock(return_value=False)
        with patch.dict(at.__opts__, {'test': False}):
            with patch.dict(at.__grains__, {'os_family': 'Redhat'}):
                with patch.dict(at.__salt__, {'cmd.run': mock}):
                    ret.update({'comment': False})
                    self.assertDictEqual(at.present(name, timespec, tag), ret)

                with patch.dict(at.__salt__, {'user.info': mock}):
                    comt = 'User: {0} is not exists'.format(user)
                    ret.update({'comment': comt, 'result': False})
                    self.assertDictEqual(at.present(name, timespec, tag, user),
                                         ret)

        with patch.dict(at.__opts__, {'test': True}):
            comt = 'job {0} is add and will run on {1}'.format(name, timespec)
            ret.update({'comment': comt, 'result': None})
            self.assertDictEqual(at.present(name, timespec, tag, user), ret)
Esempio n. 3
0
    def test_present(self):
        '''
        Test to add a job to queue.
        '''

        # input variables
        name = 'jboss'
        timespec = '9:09 11/04/15'
        tag = 'love'
        user = '******'

        # mock for at.at module call
        mock_atat = {
            'jobs': [
                {
                    'date': '2015-11-04',
                    'job': '1476031633.a',
                    'queue': 'a',
                    'tag': tag,
                    'time': '09:09:00',
                    'user': user,
                },
            ],
        }

        # normale return
        ret = {
            'name':
            name,
            'result':
            True,
            'changes': {
                'date': '2015-11-04',
                'job': '1476031633.a',
                'queue': 'a',
                'tag': 'love',
                'time': '09:09:00',
                'user': '******',
            },
            'comment':
            'job {name} added and will run on {timespec}'.format(
                name=name, timespec=timespec),
        }

        # unknown user return
        ret_user = {}
        ret_user.update(ret)
        ret_user.update({
            'result': False,
            'changes': {},
            'comment': 'user {0} does not exists'.format(user),
        })

        # add a job
        mock = MagicMock(return_value=mock_atat)
        with patch.dict(at.__opts__, {'test': False}):
            with patch.dict(at.__salt__, {'at.at': mock}):
                self.assertDictEqual(at.present(name, timespec, tag), ret)

        # add a job with a non-existing user
        mock = MagicMock(return_value=False)
        with patch.dict(at.__opts__, {'test': False}):
            with patch.dict(at.__salt__, {'user.info': mock}):
                self.assertDictEqual(at.present(name, timespec, tag, user),
                                     ret_user)

        # add a job with test=True
        with patch.dict(at.__opts__, {'test': True}):
            ret_test = {}
            ret_test.update(ret)
            ret_test.update({'result': None, 'changes': {}})
            self.assertDictEqual(at.present(name, timespec, tag, user),
                                 ret_test)
Esempio n. 4
0
    def test_present(self):
        """
        Test to add a job to queue.
        """

        # input variables
        name = "jboss"
        timespec = "9:09 11/04/15"
        tag = "love"
        user = "******"

        # mock for at.at module call
        mock_atat = {
            "jobs": [
                {
                    "date": "2015-11-04",
                    "job": "1476031633.a",
                    "queue": "a",
                    "tag": tag,
                    "time": "09:09:00",
                    "user": user,
                },
            ],
        }

        # normale return
        ret = {
            "name":
            name,
            "result":
            True,
            "changes": {
                "date": "2015-11-04",
                "job": "1476031633.a",
                "queue": "a",
                "tag": "love",
                "time": "09:09:00",
                "user": "******",
            },
            "comment":
            "job {name} added and will run on {timespec}".format(
                name=name, timespec=timespec),
        }

        # unknown user return
        ret_user = {}
        ret_user.update(ret)
        ret_user.update({
            "result": False,
            "changes": {},
            "comment": "user {0} does not exists".format(user),
        })

        # add a job
        mock = MagicMock(return_value=mock_atat)
        with patch.dict(at.__opts__, {"test": False}):
            with patch.dict(at.__salt__, {"at.at": mock}):
                self.assertDictEqual(at.present(name, timespec, tag), ret)

        # add a job with a non-existing user
        mock = MagicMock(return_value=False)
        with patch.dict(at.__opts__, {"test": False}):
            with patch.dict(at.__salt__, {"user.info": mock}):
                self.assertDictEqual(at.present(name, timespec, tag, user),
                                     ret_user)

        # add a job with test=True
        with patch.dict(at.__opts__, {"test": True}):
            ret_test = {}
            ret_test.update(ret)
            ret_test.update({"result": None, "changes": {}})
            self.assertDictEqual(at.present(name, timespec, tag, user),
                                 ret_test)
Esempio n. 5
0
    def test_present(self):
        '''
        Test to add a job to queue.
        '''

        # input variables
        name = 'jboss'
        timespec = '9:09 11/04/15'
        tag = 'love'
        user = '******'

        # mock for at.at module call
        mock_atat = {
            'jobs': [
                {
                    'date': '2015-11-04',
                    'job': '1476031633.a',
                    'queue': 'a',
                    'tag': tag,
                    'time': '09:09:00',
                    'user': user,
                },
            ],
        }

        # normale return
        ret = {
            'name': name,
            'result': True,
            'changes': {
                'date': '2015-11-04',
                'job': '1476031633.a',
                'queue': 'a',
                'tag': 'love',
                'time': '09:09:00',
                'user': '******',
            },
            'comment': 'job {name} added and will run on {timespec}'.format(
                name=name,
                timespec=timespec
            ),
        }

        # unknown user return
        ret_user = {}
        ret_user.update(ret)
        ret_user.update({
            'result': False,
            'changes': {},
            'comment': 'user {0} does not exists'.format(user),
        })

        # add a job
        mock = MagicMock(return_value=mock_atat)
        with patch.dict(at.__opts__, {'test': False}):
            with patch.dict(at.__salt__, {'at.at': mock}):
                self.assertDictEqual(at.present(name, timespec, tag), ret)

        # add a job with a non-existing user
        mock = MagicMock(return_value=False)
        with patch.dict(at.__opts__, {'test': False}):
            with patch.dict(at.__salt__, {'user.info': mock}):
                self.assertDictEqual(at.present(name, timespec, tag, user), ret_user)

        # add a job with test=True
        with patch.dict(at.__opts__, {'test': True}):
            ret_test = {}
            ret_test.update(ret)
            ret_test.update({'result': None, 'changes': {}})
            self.assertDictEqual(at.present(name, timespec, tag, user), ret_test)