Пример #1
0
    def test_absent(self):
        '''
        Test to ensure that the named user is absent.
        '''
        name = 'myapp'

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

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

            with patch.dict(mongodb_user.__opts__, {'test': False}):
                comt = ('User {0} has been removed'.format(name))
                ret.update({'comment': comt, 'result': True,
                            'changes': {name: 'Absent'}})
                self.assertDictEqual(mongodb_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(mongodb_user.absent(name), ret)
Пример #2
0
    def test_absent(self):
        '''
        Test to ensure that the named user is absent.
        '''
        name = 'myapp'

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

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

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

            comt = 'User {0} is not present'.format(name)
            ret.update({'comment': comt, 'result': True, 'changes': {}})
            self.assertDictEqual(mongodb_user.absent(name), ret)
Пример #3
0
def test_absent():
    """
    Test to ensure that the named user is absent.
    """
    name = "myapp"

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

    mock = MagicMock(side_effect=[True, True, False])
    mock_t = MagicMock(return_value=True)
    with patch.dict(
        mongodb_user.__salt__,
        {"mongodb.user_exists": mock, "mongodb.user_remove": mock_t},
    ):
        with patch.dict(mongodb_user.__opts__, {"test": True}):
            comt = "User {} is present and needs to be removed".format(name)
            ret.update({"comment": comt, "result": None})
            assert mongodb_user.absent(name) == ret

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

        comt = "User {} is not present".format(name)
        ret.update({"comment": comt, "result": True, "changes": {}})
        assert mongodb_user.absent(name) == ret