

def test_present(self):
    '\n        Test to ensure that the named database is present\n        with the specified properties.\n        '
    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)

dataset/ETHPy150Open saltstack/salt/tests/unit/states/postgres_database_test.py PostgresDatabaseTestCase.test_present/original