def test_present(self):
        """
        Test to ensure that the named database is present
        with the specified properties.
        """
        name = "frank"

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

        mock_t = MagicMock(return_value=True)
        mock = MagicMock(return_value={name: {}})
        with patch.dict(
                postgres_database.__salt__,
            {
                "postgres.db_list": mock,
                "postgres.db_alter": mock_t
            },
        ):
            comt = "Database {0} is already present".format(name)
            ret.update({"comment": comt, "result": True})
            self.assertDictEqual(postgres_database.present(name), ret)

            comt = ("Database frank has wrong parameters "
                    "which couldn't be changed on fly.")
            ret.update({"comment": comt, "result": False})
            self.assertDictEqual(
                postgres_database.present(name,
                                          tablespace="A",
                                          lc_collate=True), ret)

            with patch.dict(postgres_database.__opts__, {"test": True}):
                comt = "Database frank exists, " "but parameters need to be changed"
                ret.update({"comment": comt, "result": None})
                self.assertDictEqual(
                    postgres_database.present(name, tablespace="A"), ret)

            with patch.dict(postgres_database.__opts__, {"test": False}):
                comt = "Parameters for database frank have been changed"
                ret.update({
                    "comment": comt,
                    "result": True,
                    "changes": {
                        name: "Parameters changed"
                    },
                })
                self.assertDictEqual(
                    postgres_database.present(name, tablespace="A"), ret)
Ejemplo n.º 2
0
    def test_present(self):
        '''
        Test to ensure that the named database is present
        with the specified properties.
        '''
        name = 'frank'

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

        mock_t = MagicMock(return_value=True)
        mock = MagicMock(return_value={name: {}})
        with patch.dict(postgres_database.__salt__, {
                'postgres.db_list': mock,
                'postgres.db_alter': mock_t
        }):
            comt = ('Database {0} is already present'.format(name))
            ret.update({'comment': comt, 'result': True})
            self.assertDictEqual(postgres_database.present(name), ret)

            comt = ("Database frank has wrong parameters "
                    "which couldn't be changed on fly.")
            ret.update({'comment': comt, 'result': False})
            self.assertDictEqual(
                postgres_database.present(name,
                                          tablespace='A',
                                          lc_collate=True), ret)

            with patch.dict(postgres_database.__opts__, {'test': True}):
                comt = ('Database frank exists, '
                        'but parameters need to be changed')
                ret.update({'comment': comt, 'result': None})
                self.assertDictEqual(
                    postgres_database.present(name, tablespace='A'), ret)

            with patch.dict(postgres_database.__opts__, {'test': False}):
                comt = ('Parameters for database frank have been changed')
                ret.update({
                    'comment': comt,
                    'result': True,
                    'changes': {
                        name: 'Parameters changed'
                    }
                })
                self.assertDictEqual(
                    postgres_database.present(name, tablespace='A'), ret)
Ejemplo n.º 3
0
    def test_present(self):
        '''
        Test to ensure that the named database is present
        with the specified properties.
        '''
        name = 'frank'

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

        mock_t = MagicMock(return_value=True)
        mock = MagicMock(return_value={name: {}})
        with patch.dict(postgres_database.__salt__,
                        {'postgres.db_list': mock,
                         'postgres.db_alter': mock_t}):
            comt = ('Database {0} is already present'.format(name))
            ret.update({'comment': comt, 'result': True})
            self.assertDictEqual(postgres_database.present(name), ret)

            comt = ("Database frank has wrong parameters "
                    "which couldn't be changed on fly.")
            ret.update({'comment': comt, 'result': False})
            self.assertDictEqual(postgres_database.present(name, tablespace='A',
                                                           lc_collate=True),
                                 ret)

            with patch.dict(postgres_database.__opts__, {'test': True}):
                comt = ('Database frank exists, '
                        'but parameters need to be changed')
                ret.update({'comment': comt, 'result': None})
                self.assertDictEqual(postgres_database.present(name,
                                                               tablespace='A'),
                                     ret)

            with patch.dict(postgres_database.__opts__, {'test': False}):
                comt = ('Parameters for database frank have been changed')
                ret.update({'comment': comt, 'result': True,
                            'changes': {name: 'Parameters changed'}})
                self.assertDictEqual(postgres_database.present(name,
                                                               tablespace='A'),
                                     ret)