Skip to content

Commit

Permalink
Added postgres test
Browse files Browse the repository at this point in the history
  • Loading branch information
arecker committed Sep 19, 2015
1 parent bfc09f0 commit 869d295
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion msg/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def _run_command(self, cmd):


class PostgresController(BaseDatabaseController):
pass
user = 'postgres'


class MysqlController(BaseDatabaseController):
Expand Down
8 changes: 5 additions & 3 deletions tests/mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ def __init__(self):
self._files = MockFiles(self._callback)
self._operations = MockOperations(self._callback)

def sudo(self, cmd):
self._shell_command(cmd, True)
def sudo(self, cmd, user=None):
self._shell_command(cmd, True, user=user)

def run(self, cmd):
self._shell_command(cmd, False)
Expand All @@ -71,11 +71,13 @@ def _callback(self, obj):
self.history.append(obj)
self.last = obj

def _shell_command(self, cmd, sudo):
def _shell_command(self, cmd, sudo, user=None):
self.last = {
'command': cmd,
'sudo': sudo
}
if user:
self.last['user'] = user
self.history.append(self.last)


Expand Down
11 changes: 11 additions & 0 deletions tests/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,14 @@ def test_run_command_without_user(self):
self.fail('able to run an incomplete controller')
except NotImplementedError as e:
self.assertEqual(e.message, '\'user\' required')


class PostgresDatabaseController(MockFabricTestCase):
def test_run_command_without_user(self):
d = db.PostgresController()
d._run_command('drop everything')
self.assertEqual(self.mock.last, {
'command': 'drop everything',
'sudo': True,
'user': 'postgres'
})

0 comments on commit 869d295

Please sign in to comment.