2013-06-27 13:03:01 +00:00
|
|
|
# Import Salt Testing libs
|
|
|
|
from salttesting import skipIf, TestCase
|
|
|
|
from salttesting.helpers import ensure_in_syspath
|
2013-08-26 09:56:18 +00:00
|
|
|
from salttesting.mock import NO_MOCK, NO_MOCK_REASON, Mock, patch
|
2013-06-27 13:03:01 +00:00
|
|
|
ensure_in_syspath('../../')
|
2013-03-21 22:48:18 +00:00
|
|
|
|
2013-06-27 13:03:01 +00:00
|
|
|
# Import salt libs
|
2013-03-12 18:10:02 +00:00
|
|
|
from salt.modules import postgres
|
2013-03-21 22:49:41 +00:00
|
|
|
postgres.__grains__ = None # in order to stub it w/patch below
|
|
|
|
postgres.__salt__ = None # in order to stub it w/patch below
|
2013-03-12 18:10:02 +00:00
|
|
|
|
2013-08-26 09:56:18 +00:00
|
|
|
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 = {}
|
2013-03-12 18:10:02 +00:00
|
|
|
|
|
|
|
|
2013-08-26 09:56:18 +00:00
|
|
|
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
2013-03-12 18:10:02 +00:00
|
|
|
class PostgresTestCase(TestCase):
|
2013-03-21 22:49:41 +00:00
|
|
|
@patch.multiple(postgres,
|
|
|
|
__grains__={'os_family': 'Linux'},
|
|
|
|
__salt__=SALT_STUB)
|
2013-03-12 18:10:02 +00:00
|
|
|
def test_run_psql(self):
|
|
|
|
postgres._run_psql('echo "hi"')
|
2013-03-21 22:49:41 +00:00
|
|
|
cmd = SALT_STUB['cmd.run_all']
|
2013-03-12 18:10:02 +00:00
|
|
|
|
2013-10-24 09:39:04 +00:00
|
|
|
self.assertEqual('postgres', cmd.call_args[1]['runas'])
|
2013-03-12 18:10:02 +00:00
|
|
|
|
2013-06-25 08:24:45 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
from integration import run_tests
|
|
|
|
run_tests(PostgresTestCase, needs_daemon=False)
|