Skip to content

Commit

Permalink
Fix postgres.db_alter test, add test for owner_recurse=True
Browse files Browse the repository at this point in the history
The old db_alter test was probably failing anyway. The new test tests
owner_to is called when owner_recurse is set to true.
  • Loading branch information
lucacorti committed Apr 5, 2015
1 parent 3aa4b3b commit b9b307f
Showing 1 changed file with 34 additions and 6 deletions.
40 changes: 34 additions & 6 deletions tests/unit/modules/postgres_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# Import python libs
from __future__ import absolute_import, print_function
from mock import call
import re

# Import Salt Testing libs
Expand Down Expand Up @@ -68,12 +69,39 @@ def test_db_alter(self):
tablespace='testspace',
owner='otheruser',
runas='foo')
postgres._run_psql.assert_called_once_with(
'/usr/bin/pgsql --no-align --no-readline --no-password --username testuser '
'--host testhost --port testport --dbname maint_db '
'-c \'ALTER DATABASE "dbname" OWNER TO "otheruser"\'',
host='testhost', user='testuser',
password='foo', runas='foo', port='testport')
postgres._run_psql.assert_has_calls([
call('/usr/bin/pgsql --no-align --no-readline --no-password --username testuser '
'--host testhost --port testport --dbname maint_db '
'-c \'ALTER DATABASE "dbname" OWNER TO "otheruser"\'',
host='testhost', user='testuser',
password='foo', runas='foo', port='testport'),
call('/usr/bin/pgsql --no-align --no-readline --no-password --username testuser '
'--host testhost --port testport --dbname maint_db '
'-c \'ALTER DATABASE "dbname" SET TABLESPACE "testspace"\'',
host='testhost', user='testuser',
password='foo', runas='foo', port='testport')
])

@patch('salt.modules.postgres.owner_to',
Mock(return_value={'retcode': None}))
def test_db_alter_owner_recurse(self):
postgres.db_alter('dbname',
user='testuser',
host='testhost',
port='testport',
maintenance_db='maint_db',
password='foo',
tablespace='testspace',
owner='otheruser',
owner_recurse=True,
runas='foo')
postgres.owner_to.assert_called_once_with('dbname',
'otheruser',
user='testuser',
host='testhost',
port='testport',
password='foo',
runas='foo')

@patch('salt.modules.postgres._run_psql',
Mock(return_value={'retcode': None}))
Expand Down

0 comments on commit b9b307f

Please sign in to comment.