def test_absent(self):
        """
        Test to ensure that the named cluster admin or database user is absent.
        """
        name = "salt"

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

        mock = MagicMock(side_effect=[True, True, True, False])
        mock_t = MagicMock(side_effect=[True, False])
        with patch.dict(
            influxdb08_user.__salt__,
            {"influxdb08.user_exists": mock, "influxdb08.user_remove": mock_t},
        ):
            with patch.dict(influxdb08_user.__opts__, {"test": True}):
                comt = "User {0} is present and needs to be removed".format(name)
                ret.update({"comment": comt})
                self.assertDictEqual(influxdb08_user.absent(name), ret)

            with patch.dict(influxdb08_user.__opts__, {"test": False}):
                comt = "User {0} has been removed".format(name)
                ret.update(
                    {"comment": comt, "result": True, "changes": {"salt": "Absent"}}
                )
                self.assertDictEqual(influxdb08_user.absent(name), ret)

                comt = "Failed to remove user {0}".format(name)
                ret.update({"comment": comt, "result": False, "changes": {}})
                self.assertDictEqual(influxdb08_user.absent(name), ret)

            comt = "User {0} is not present, so it cannot be removed".format(name)
            ret.update({"comment": comt, "result": True})
            self.assertDictEqual(influxdb08_user.absent(name), ret)
Beispiel #2
0
    def test_absent(self):
        """
        Test to ensure that the named cluster admin or database user is absent.
        """
        name = "salt"

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

        mock = MagicMock(side_effect=[True, True, True, False])
        mock_t = MagicMock(side_effect=[True, False])
        with patch.dict(influxdb08_user.__salt__, {"influxdb08.user_exists": mock, "influxdb08.user_remove": mock_t}):
            with patch.dict(influxdb08_user.__opts__, {"test": True}):
                comt = "User {0} is present and needs to be removed".format(name)
                ret.update({"comment": comt})
                self.assertDictEqual(influxdb08_user.absent(name), ret)

            with patch.dict(influxdb08_user.__opts__, {"test": False}):
                comt = "User {0} has been removed".format(name)
                ret.update({"comment": comt, "result": True, "changes": {"salt": "Absent"}})
                self.assertDictEqual(influxdb08_user.absent(name), ret)

                comt = "Failed to remove user {0}".format(name)
                ret.update({"comment": comt, "result": False, "changes": {}})
                self.assertDictEqual(influxdb08_user.absent(name), ret)

            comt = "User {0} is not present, so it cannot be removed".format(name)
            ret.update({"comment": comt, "result": True})
            self.assertDictEqual(influxdb08_user.absent(name), ret)
Beispiel #3
0
    def test_absent(self):
        '''
        Test to ensure that the named cluster admin or database user is absent.
        '''
        name = 'salt'

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

        mock = MagicMock(side_effect=[True, True, True, False])
        mock_t = MagicMock(side_effect=[True, False])
        with patch.dict(influxdb08_user.__salt__, {
                'influxdb08.user_exists': mock,
                'influxdb08.user_remove': mock_t
        }):
            with patch.dict(influxdb08_user.__opts__, {'test': True}):
                comt = (
                    'User {0} is present and needs to be removed'.format(name))
                ret.update({'comment': comt})
                self.assertDictEqual(influxdb08_user.absent(name), ret)

            with patch.dict(influxdb08_user.__opts__, {'test': False}):
                comt = ('User {0} has been removed'.format(name))
                ret.update({
                    'comment': comt,
                    'result': True,
                    'changes': {
                        'salt': 'Absent'
                    }
                })
                self.assertDictEqual(influxdb08_user.absent(name), ret)

                comt = ('Failed to remove user {0}'.format(name))
                ret.update({'comment': comt, 'result': False, 'changes': {}})
                self.assertDictEqual(influxdb08_user.absent(name), ret)

            comt = ('User {0} is not present, so it cannot be removed'.format(
                name))
            ret.update({'comment': comt, 'result': True})
            self.assertDictEqual(influxdb08_user.absent(name), ret)