Example #1
0
    def test_managed(self):
        '''
        Test to manage a memcached key.
        '''
        name = 'foo'

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

        mock_t = MagicMock(side_effect=[CommandExecutionError, 'salt', True,
                                        True, True])
        with patch.dict(memcached.__salt__, {'memcached.get': mock_t,
                                             'memcached.set': mock_t}):
            self.assertDictEqual(memcached.managed(name), ret)

            comt = ("Key 'foo' does not need to be updated")
            ret.update({'comment': comt, 'result': True})
            self.assertDictEqual(memcached.managed(name, 'salt'), ret)

            with patch.dict(memcached.__opts__, {'test': True}):
                comt = ("Value of key 'foo' would be changed")
                ret.update({'comment': comt, 'result': None})
                self.assertDictEqual(memcached.managed(name, 'salt'), ret)

            with patch.dict(memcached.__opts__, {'test': False}):
                comt = ("Successfully set key 'foo'")
                ret.update({'comment': comt, 'result': True,
                            'changes': {'new': 'salt', 'old': True}})
                self.assertDictEqual(memcached.managed(name, 'salt'), ret)
Example #2
0
    def test_managed(self):
        '''
        Test to manage a memcached key.
        '''
        name = 'foo'

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

        mock_t = MagicMock(
            side_effect=[CommandExecutionError, 'salt', True, True, True])
        with patch.dict(memcached.__salt__, {
                'memcached.get': mock_t,
                'memcached.set': mock_t
        }):
            self.assertDictEqual(memcached.managed(name), ret)

            comt = ("Key 'foo' does not need to be updated")
            ret.update({'comment': comt, 'result': True})
            self.assertDictEqual(memcached.managed(name, 'salt'), ret)

            with patch.dict(memcached.__opts__, {'test': True}):
                comt = ("Value of key 'foo' would be changed")
                ret.update({'comment': comt, 'result': None})
                self.assertDictEqual(memcached.managed(name, 'salt'), ret)

            with patch.dict(memcached.__opts__, {'test': False}):
                comt = ("Successfully set key 'foo'")
                ret.update({
                    'comment': comt,
                    'result': True,
                    'changes': {
                        'new': 'salt',
                        'old': True
                    }
                })
                self.assertDictEqual(memcached.managed(name, 'salt'), ret)
    def test_managed(self):
        """
        Test to manage a memcached key.
        """
        name = "foo"

        ret = {"name": name, "result": False, "comment": "", "changes": {}}

        mock_t = MagicMock(
            side_effect=[CommandExecutionError, "salt", True, True, True])
        with patch.dict(memcached.__salt__, {
                "memcached.get": mock_t,
                "memcached.set": mock_t
        }):
            self.assertDictEqual(memcached.managed(name), ret)

            comt = "Key 'foo' does not need to be updated"
            ret.update({"comment": comt, "result": True})
            self.assertDictEqual(memcached.managed(name, "salt"), ret)

            with patch.dict(memcached.__opts__, {"test": True}):
                comt = "Value of key 'foo' would be changed"
                ret.update({"comment": comt, "result": None})
                self.assertDictEqual(memcached.managed(name, "salt"), ret)

            with patch.dict(memcached.__opts__, {"test": False}):
                comt = "Successfully set key 'foo'"
                ret.update({
                    "comment": comt,
                    "result": True,
                    "changes": {
                        "new": "salt",
                        "old": True
                    },
                })
                self.assertDictEqual(memcached.managed(name, "salt"), ret)