salt/tests/unit/modules/postgres_test.py

38 lines
1.0 KiB
Python
Raw Normal View History

# Import Salt Testing libs
from salttesting import skipIf, TestCase
from salttesting.helpers import ensure_in_syspath
from salttesting.mock import NO_MOCK, NO_MOCK_REASON, Mock, patch
ensure_in_syspath('../../')
2013-03-21 22:48:18 +00:00
# Import salt libs
from salt.modules import postgres
postgres.__grains__ = None # in order to stub it w/patch below
postgres.__salt__ = None # in order to stub it w/patch below
if NO_MOCK is False:
2013-03-21 23:09:16 +00:00
SALT_STUB = {
'config.option': Mock(),
'cmd.run_all': Mock(),
2013-04-05 13:59:29 +00:00
'file.chown': Mock(),
'file.remove': Mock(),
2013-03-21 23:09:16 +00:00
}
else:
SALT_STUB = {}
@skipIf(NO_MOCK, NO_MOCK_REASON)
class PostgresTestCase(TestCase):
@patch.multiple(postgres,
__grains__={'os_family': 'Linux'},
__salt__=SALT_STUB)
def test_run_psql(self):
postgres._run_psql('echo "hi"')
cmd = SALT_STUB['cmd.run_all']
self.assertEqual('postgres', cmd.call_args[1]['runas'])
if __name__ == '__main__':
from integration import run_tests
run_tests(PostgresTestCase, needs_daemon=False)