def test_absent(self):
        """
        Test to ensure that the named group 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_group.__salt__,
            {"postgres.user_exists": mock, "postgres.group_remove": mock_t},
        ):
            with patch.dict(postgres_group.__opts__, {"test": True}):
                comt = "Group {0} is set to be removed".format(name)
                ret.update({"comment": comt, "result": None})
                self.assertDictEqual(postgres_group.absent(name), ret)

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

            comt = "Group {0} is not present, so it cannot be removed".format(name)
            ret.update({"comment": comt, "result": True, "changes": {}})
            self.assertDictEqual(postgres_group.absent(name), ret)
Exemplo n.º 2
0
    def test_absent(self):
        '''
        Test to ensure that the named group 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_group.__salt__, {
                'postgres.user_exists': mock,
                'postgres.group_remove': mock_t
        }):
            with patch.dict(postgres_group.__opts__, {'test': True}):
                comt = ('Group {0} is set to be removed'.format(name))
                ret.update({'comment': comt, 'result': None})
                self.assertDictEqual(postgres_group.absent(name), ret)

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

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

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

    assert postgres_group.absent("groupname") == {
        "name": "groupname",
        "result": None,
        "changes": {},
        "comment": "Group groupname is set to be removed",
    }
    mocks["postgres.user_exists"].assert_called_once_with("groupname", **db_args)
    mocks["postgres.group_remove"].assert_not_called()
Exemplo n.º 5
0
def test_absent_delete(mocks, db_args):
    mocks["postgres.user_exists"].return_value = True

    assert postgres_group.absent("groupname") == {
        "name": "groupname",
        "result": True,
        "changes": {"groupname": "Absent"},
        "comment": "Group groupname has been removed",
    }
    mocks["postgres.user_exists"].assert_called_once_with("groupname", **db_args)
    mocks["postgres.group_remove"].assert_called_once_with("groupname", **db_args)
Exemplo n.º 6
0
def test_absent_error(mocks):
    mocks["postgres.user_exists"].return_value = True
    mocks["postgres.group_remove"].return_value = False

    assert postgres_group.absent("groupname") == {
        "name": "groupname",
        "result": False,
        "changes": {},
        "comment": "Group groupname failed to be removed",
    }
    mocks["postgres.user_exists"].assert_called_once()
    mocks["postgres.group_remove"].assert_called_once()
Exemplo n.º 7
0
    def test_absent(self):
        """
        Test to ensure that the named group 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_group.__salt__, {"postgres.user_exists": mock, "postgres.group_remove": mock_t}):
            with patch.dict(postgres_group.__opts__, {"test": True}):
                comt = "Group {0} is set to be removed".format(name)
                ret.update({"comment": comt, "result": None})
                self.assertDictEqual(postgres_group.absent(name), ret)

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

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