declobber postgres state unit test mocking

This commit is contained in:
Justin Findlay 2015-07-01 12:01:42 -06:00
parent a162ffa3d8
commit 3c379dc115

View File

@ -30,9 +30,9 @@ MODS = (
OPTS = {'test': False}
for postgres in MODS:
postgres.__grains__ = None # in order to stub it w/patch below
postgres.__salt__ = None # in order to stub it w/patch below
postgres.__opts__ = OPTS # in order to stub it w/patch below
postgres.__grains__ = {} # in order to stub it w/patch below
postgres.__salt__ = {} # in order to stub it w/patch below
postgres.__opts__ = {} # in order to stub it w/patch below
if NO_MOCK is False:
SALT_STUB = {
@ -48,7 +48,8 @@ else:
@skipIf(NO_MOCK, NO_MOCK_REASON)
@patch.multiple(postgres_user,
__grains__={'os_family': 'Linux'},
__salt__=SALT_STUB)
__salt__=SALT_STUB,
__opts__={'test': False})
@patch('salt.utils.which', Mock(return_value='/usr/bin/pgsql'))
class PostgresUserTestCase(TestCase):
@ -58,7 +59,7 @@ class PostgresUserTestCase(TestCase):
})
def test_present__creation(self):
# test=True
with patch.dict(OPTS, {'test': True}):
with patch.dict(postgres_user.__opts__, {'test': True}):
ret = postgres_user.present('foo')
self.assertEqual(
ret,
@ -108,7 +109,7 @@ class PostgresUserTestCase(TestCase):
})
def test_present__update(self):
# test=True
with patch.dict(OPTS, {'test': True}):
with patch.dict(postgres_user.__opts__, {'test': True}):
ret = postgres_user.present('foo', login=True, replication=False)
self.assertEqual(
ret,
@ -180,7 +181,8 @@ class PostgresUserTestCase(TestCase):
@skipIf(NO_MOCK, NO_MOCK_REASON)
@patch.multiple(postgres_group,
__grains__={'os_family': 'Linux'},
__salt__=SALT_STUB)
__salt__=SALT_STUB,
__opts__={'test': False})
@patch('salt.utils.which', Mock(return_value='/usr/bin/pgsql'))
class PostgresGroupTestCase(TestCase):
@ -190,7 +192,7 @@ class PostgresGroupTestCase(TestCase):
})
def test_present__creation(self):
# test=True
with patch.dict(OPTS, {'test': True}):
with patch.dict(postgres_group.__opts__, {'test': True}):
ret = postgres_group.present('foo')
self.assertEqual(
ret,
@ -240,7 +242,7 @@ class PostgresGroupTestCase(TestCase):
})
def test_present__update(self):
# test=True
with patch.dict(OPTS, {'test': True}):
with patch.dict(postgres_group.__opts__, {'test': True}):
ret = postgres_group.present('foo', login=True, replication=False)
self.assertEqual(
ret,
@ -312,7 +314,8 @@ class PostgresGroupTestCase(TestCase):
@skipIf(NO_MOCK, NO_MOCK_REASON)
@patch.multiple(postgres_extension,
__grains__={'os_family': 'Linux'},
__salt__=SALT_STUB)
__salt__=SALT_STUB,
__opts__={'test': False})
@patch('salt.utils.which', Mock(return_value='/usr/bin/pgsql'))
class PostgresExtensionTestCase(TestCase):
@ -396,26 +399,27 @@ class PostgresExtensionTestCase(TestCase):
scenario of creating upgrading extensions with possible schema and
version specifications
'''
ret = postgres_extension.present('foo')
self.assertEqual(
ret,
{'comment': 'Extension foo is set to be installed',
'changes': {}, 'name': 'foo', 'result': None}
with patch.dict(postgres_extension.__opts__, {'test': True}):
ret = postgres_extension.present('foo')
self.assertEqual(
ret,
{'comment': 'Extension foo is set to be installed',
'changes': {}, 'name': 'foo', 'result': None}
)
ret = postgres_extension.present('foo')
self.assertEqual(
ret,
{'comment': "Extension foo is set to be created",
'changes': {}, 'name': 'foo', 'result': None}
)
ret = postgres_extension.present('foo')
self.assertEqual(
ret,
{'comment': "Extension foo is set to be created",
'changes': {}, 'name': 'foo', 'result': None}
)
ret = postgres_extension.present('foo')
self.assertEqual(
ret,
{'comment': "Extension foo is set to be upgraded",
'changes': {}, 'name': 'foo', 'result': None}
)
)
ret = postgres_extension.present('foo')
self.assertEqual(
ret,
{'comment': "Extension foo is set to be upgraded",
'changes': {}, 'name': 'foo', 'result': None}
)
@patch.dict(SALT_STUB, {
'postgres.is_installed_extension': Mock(side_effect=[
@ -477,7 +481,8 @@ class PostgresExtensionTestCase(TestCase):
]),
})
def test_absent_failedtest(self):
ret = postgres_extension.absent('foo')
with patch.dict(postgres_extension.__opts__, {'test': True}):
ret = postgres_extension.absent('foo')
self.assertEqual(
ret,
{'comment': 'Extension foo is set to be removed',
@ -488,7 +493,8 @@ class PostgresExtensionTestCase(TestCase):
@skipIf(NO_MOCK, NO_MOCK_REASON)
@patch.multiple(postgres_schema,
__grains__={'os_family': 'Linux'},
__salt__=SALT_STUB)
__salt__=SALT_STUB,
__opts__={'test': False})
@patch('salt.utils.which', Mock(return_value='/usr/bin/pgsql'))
class PostgresSchemaTestCase(TestCase):