Exemplo n.º 1
0
    def test_absent(self):
        '''
        Test to ensure that the named user is absent.
        '''
        name = 'frank'

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

        mock_t = MagicMock(return_value=True)
        mock = MagicMock(side_effect=[True, True, False])
        with patch.dict(postgres_user.__salt__, {
                'postgres.user_exists': mock,
                'postgres.user_remove': mock_t
        }):
            with patch.dict(postgres_user.__opts__, {'test': True}):
                comt = ('User {0} is set to be removed'.format(name))
                ret.update({'comment': comt, 'result': None})
                self.assertDictEqual(postgres_user.absent(name), ret)

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

            comt = ('User {0} is not present, so it cannot be removed'.format(
                name))
            ret.update({'comment': comt, 'result': True, 'changes': {}})
            self.assertDictEqual(postgres_user.absent(name), ret)
Exemplo n.º 2
0
def test_absent_error(mocks):
    mocks["postgres.user_exists"].return_value = True
    mocks["postgres.user_remove"].return_value = False

    assert postgres_user.absent("username") == {
        "name": "username",
        "result": False,
        "changes": {},
        "comment": "User username failed to be removed",
    }
    mocks["postgres.user_exists"].assert_called_once()
    mocks["postgres.user_remove"].assert_called_once()
Exemplo n.º 3
0
def test_absent_already(mocks, db_args):
    mocks["postgres.user_exists"].return_value = False

    assert postgres_user.absent("username") == {
        "name": "username",
        "result": True,
        "changes": {},
        "comment": "User username is not present, so it cannot be removed",
    }
    mocks["postgres.user_exists"].assert_called_once_with(
        "username", **db_args)
    mocks["postgres.user_remove"].assert_not_called()
Exemplo n.º 4
0
def test_absent_test(mocks, db_args):
    mocks["postgres.user_exists"].return_value = True

    assert postgres_user.absent("username") == {
        "name": "username",
        "result": None,
        "changes": {},
        "comment": "User username is set to be removed",
    }
    mocks["postgres.user_exists"].assert_called_once_with(
        "username", **db_args)
    mocks["postgres.user_remove"].assert_not_called()
Exemplo n.º 5
0
    def test_absent(self):
        """
        Test to ensure that the named user is absent.
        """
        name = "frank"

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

        mock_t = MagicMock(return_value=True)
        mock = MagicMock(side_effect=[True, True, False])
        with patch.dict(
                postgres_user.__salt__,
            {
                "postgres.user_exists": mock,
                "postgres.user_remove": mock_t
            },
        ):
            with patch.dict(postgres_user.__opts__, {"test": True}):
                comt = "User {0} is set to be removed".format(name)
                ret.update({"comment": comt, "result": None})
                self.assertDictEqual(postgres_user.absent(name), ret)

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

            comt = "User {0} is not present, so it cannot be removed".format(
                name)
            ret.update({"comment": comt, "result": True, "changes": {}})
            self.assertDictEqual(postgres_user.absent(name), ret)
Exemplo n.º 6
0
def test_absent_delete(mocks, db_args):
    mocks["postgres.user_exists"].return_value = True

    assert postgres_user.absent("username") == {
        "name": "username",
        "result": True,
        "changes": {
            "username": "******"
        },
        "comment": "User username has been removed",
    }
    mocks["postgres.user_exists"].assert_called_once_with(
        "username", **db_args)
    mocks["postgres.user_remove"].assert_called_once_with(
        "username", **db_args)
Exemplo n.º 7
0
    def test_absent(self):
        """
        Test to ensure that the named user is absent.
        """
        name = "frank"

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

        mock_t = MagicMock(return_value=True)
        mock = MagicMock(side_effect=[True, True, False])
        with patch.dict(postgres_user.__salt__, {"postgres.user_exists": mock, "postgres.user_remove": mock_t}):
            with patch.dict(postgres_user.__opts__, {"test": True}):
                comt = "User {0} is set to be removed".format(name)
                ret.update({"comment": comt, "result": None})
                self.assertDictEqual(postgres_user.absent(name), ret)

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

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