Skip to content

Commit

Permalink
add test coverage that the env is set
Browse files Browse the repository at this point in the history
  • Loading branch information
crccheck committed May 13, 2014
1 parent 47d463e commit 0705506
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions test_postdoc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-

import os
try:
# for python 2.6 compatibility
import unittest2 as unittest
Expand Down Expand Up @@ -78,14 +79,38 @@ def test_main_exits_with_missing_env(self):
with self.assertRaises(SystemExit):
postdoc.main()

def test_main_passes_password_in_env(self):
my_password = 'oops'
meta = type('mock', (object, ),
{'password': my_password})
self.assertNotIn('DATABASE_URL', os.environ,
msg="Re-run tests in an environment without DATABASE_URL")
mock_subprocess = mock.MagicMock()
mock_pg_command = mock.MagicMock(return_value=['pg_command'])
mock_get_uri = mock.MagicMock(return_value=meta)
mock_sys = mock.MagicMock()
mock_sys.argv = ['foo', 'psql']

with mock.patch.multiple(
postdoc,
subprocess=mock_subprocess,
pg_command=mock_pg_command,
get_uri=mock_get_uri,
sys=mock_sys,
):
postdoc.main()
self.assertEqual(
mock_subprocess.call.call_args[1]['env']['PGPASSWORD'],
my_password)

def test_main_appends_additional_flags(self):
self.assertNotIn('DATABASE_URL', os.environ,
msg="Re-run tests in an environment without DATABASE_URL")
mock_subprocess = mock.MagicMock()
mock_pg_command = mock.MagicMock(return_value=['pg_command'])
mock_get_uri = mock.MagicMock()
mock_sys = mock.MagicMock()
mock_sys.argv = ['argv1', 'psql', 'argv3', 'argv4']
import os
self.assertNotIn('DATABASE_URL', os.environ) # sanity check

with mock.patch.multiple(
postdoc,
Expand Down

0 comments on commit 0705506

Please sign in to comment.