Exemplo n.º 1
0
    def test_absent(self):
        '''
        Test to ensure that the named database 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_database.__salt__, {
                'postgres.db_exists': mock,
                'postgres.db_remove': mock_t
        }):
            with patch.dict(postgres_database.__opts__, {'test': True}):
                comt = ('Database {0} is set to be removed'.format(name))
                ret.update({'comment': comt, 'result': None})
                self.assertDictEqual(postgres_database.absent(name), ret)

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

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

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

                comt = ('Database {0} is not present, so it cannot be removed'
                        .format(name))
                ret.update({'comment': comt, 'result': True, 'changes': {}})
                self.assertDictEqual(postgres_database.absent(name), ret)
    def test_absent(self):
        """
        Test to ensure that the named database 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_database.__salt__,
            {
                "postgres.db_exists": mock,
                "postgres.db_remove": mock_t
            },
        ):
            with patch.dict(postgres_database.__opts__, {"test": True}):
                comt = "Database {0} is set to be removed".format(name)
                ret.update({"comment": comt, "result": None})
                self.assertDictEqual(postgres_database.absent(name), ret)

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

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