mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #24331 from jayeshka/postgres_extension-states-unit-test
adding states/postgres_extension unit test case.
This commit is contained in:
commit
ada8fe57d4
1 changed files with 101 additions and 0 deletions
101
tests/unit/states/postgres_extension_test.py
Normal file
101
tests/unit/states/postgres_extension_test.py
Normal file
|
@ -0,0 +1,101 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
:codeauthor: :email:`Jayesh Kariya <jayeshk@saltstack.com>`
|
||||
'''
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
|
||||
# Import Salt Testing Libs
|
||||
from salttesting import skipIf, TestCase
|
||||
from salttesting.mock import (
|
||||
NO_MOCK,
|
||||
NO_MOCK_REASON,
|
||||
MagicMock,
|
||||
patch
|
||||
)
|
||||
|
||||
from salttesting.helpers import ensure_in_syspath
|
||||
|
||||
ensure_in_syspath('../../')
|
||||
|
||||
# Import Salt Libs
|
||||
from salt.states import postgres_extension
|
||||
|
||||
postgres_extension.__opts__ = {}
|
||||
postgres_extension.__salt__ = {}
|
||||
|
||||
|
||||
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||
class PostgresExtensionTestCase(TestCase):
|
||||
'''
|
||||
Test cases for salt.states.postgres_extension
|
||||
'''
|
||||
# 'present' function tests: 1
|
||||
|
||||
def test_present(self):
|
||||
'''
|
||||
Test to ensure that the named extension is present
|
||||
with the specified privileges.
|
||||
'''
|
||||
name = 'frank'
|
||||
|
||||
ret = {'name': name,
|
||||
'changes': {},
|
||||
'result': False,
|
||||
'comment': ''}
|
||||
|
||||
mock = MagicMock(return_value={})
|
||||
with patch.dict(postgres_extension.__salt__,
|
||||
{'postgres.create_metadata': mock}):
|
||||
with patch.dict(postgres_extension.__opts__, {'test': True}):
|
||||
comt = ('Extension {0} is set to be created'.format(name))
|
||||
ret.update({'comment': comt, 'result': None})
|
||||
self.assertDictEqual(postgres_extension.present(name), ret)
|
||||
|
||||
with patch.dict(postgres_extension.__opts__, {'test': False}):
|
||||
comt = ('Extension {0} is already present'.format(name))
|
||||
ret.update({'comment': comt, 'result': True})
|
||||
self.assertDictEqual(postgres_extension.present(name), ret)
|
||||
|
||||
# 'absent' function tests: 1
|
||||
|
||||
def test_absent(self):
|
||||
'''
|
||||
Test to ensure that the named extension is absent.
|
||||
'''
|
||||
name = 'frank'
|
||||
|
||||
ret = {'name': name,
|
||||
'changes': {},
|
||||
'result': False,
|
||||
'comment': ''}
|
||||
|
||||
mock_t = MagicMock(side_effect=[True, False])
|
||||
mock = MagicMock(side_effect=[True, True, True, False])
|
||||
with patch.dict(postgres_extension.__salt__,
|
||||
{'postgres.is_installed_extension': mock,
|
||||
'postgres.drop_extension': mock_t}):
|
||||
with patch.dict(postgres_extension.__opts__, {'test': True}):
|
||||
comt = ('Extension {0} is set to be removed'.format(name))
|
||||
ret.update({'comment': comt, 'result': None})
|
||||
self.assertDictEqual(postgres_extension.absent(name), ret)
|
||||
|
||||
with patch.dict(postgres_extension.__opts__, {'test': False}):
|
||||
comt = ('Extension {0} has been removed'.format(name))
|
||||
ret.update({'comment': comt, 'result': True,
|
||||
'changes': {name: 'Absent'}})
|
||||
self.assertDictEqual(postgres_extension.absent(name), ret)
|
||||
|
||||
comt = ('Extension {0} failed to be removed'.format(name))
|
||||
ret.update({'comment': comt, 'result': False, 'changes': {}})
|
||||
self.assertDictEqual(postgres_extension.absent(name), ret)
|
||||
|
||||
comt = ('Extension {0} is not present, so it cannot be removed'
|
||||
.format(name))
|
||||
ret.update({'comment': comt, 'result': True})
|
||||
self.assertDictEqual(postgres_extension.absent(name), ret)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from integration import run_tests
|
||||
run_tests(PostgresExtensionTestCase, needs_daemon=False)
|
Loading…
Add table
Reference in a new issue