Merge "UnitTests: fix mock assertions usage"

This commit is contained in:
Jenkins 2014-07-02 15:40:17 +00:00 committed by Gerrit Code Review
commit 2209dbbba7
2 changed files with 11 additions and 13 deletions

View File

@ -2987,12 +2987,10 @@ class ThreadGroupManagerTest(HeatTestCase):
self.stlock_mock.StackLock.assert_called_with(self.cnxt,
self.stack,
self.engine_id)
self.lock_mock.acquire.assert_called_once()
thm.start_with_acquired_lock.assert_called_once()
calls = thm.start_with_acquired_lock.call_args
self.assertEqual((self.stack, self.lock_mock, self.f) + self.fargs,
calls[0])
self.assertEqual(self.fkwargs, calls[1])
thm.start_with_acquired_lock.assert_called_once_with(
self.stack, self.lock_mock,
self.f, *self.fargs, **self.fkwargs)
def test_tgm_start(self):
stack_id = 'test'

View File

@ -170,17 +170,17 @@ class StackLockTest(HeatTestCase):
slock = stack_lock.StackLock(self.context, self.stack, self.engine_id)
try:
with slock.thread_lock(self.stack.id):
db_api.stack_lock_create.assert_called_once()
self.assertEqual(1, db_api.stack_lock_create.call_count)
raise Exception
except:
db_api.stack_lock_release.assert_called_once()
self.assertEqual(1, db_api.stack_lock_release.call_count)
def test_thread_lock_context_mgr_no_exception(self):
db_api.stack_lock_create = mock.Mock(return_value=None)
db_api.stack_lock_release = mock.Mock(return_value=None)
slock = stack_lock.StackLock(self.context, self.stack, self.engine_id)
with slock.thread_lock(self.stack.id):
db_api.stack_lock_create.assert_called_once()
self.assertEqual(1, db_api.stack_lock_create.call_count)
assert not db_api.stack_lock_release.called
def test_try_thread_lock_context_mgr_exception(self):
@ -189,17 +189,17 @@ class StackLockTest(HeatTestCase):
slock = stack_lock.StackLock(self.context, self.stack, self.engine_id)
try:
with slock.try_thread_lock(self.stack.id):
db_api.stack_lock_create.assert_called_once()
self.assertEqual(1, db_api.stack_lock_create.call_count)
raise Exception
except:
db_api.stack_lock_release.assert_called_once()
self.assertEqual(1, db_api.stack_lock_release.call_count)
def test_try_thread_lock_context_mgr_no_exception(self):
db_api.stack_lock_create = mock.Mock(return_value=None)
db_api.stack_lock_release = mock.Mock(return_value=None)
slock = stack_lock.StackLock(self.context, self.stack, self.engine_id)
with slock.try_thread_lock(self.stack.id):
db_api.stack_lock_create.assert_called_once()
self.assertEqual(1, db_api.stack_lock_create.call_count)
assert not db_api.stack_lock_release.called
def test_try_thread_lock_context_mgr_existing_lock(self):
@ -208,7 +208,7 @@ class StackLockTest(HeatTestCase):
slock = stack_lock.StackLock(self.context, self.stack, self.engine_id)
try:
with slock.try_thread_lock(self.stack.id):
db_api.stack_lock_create.assert_called_once()
self.assertEqual(1, db_api.stack_lock_create.call_count)
raise Exception
except:
assert not db_api.stack_lock_release.called