Fix broken tests caused by new mock release(1.1.0)

`assert_called_once` has never been a valid mock.Mock method; the latest
release of mock causes its usage to raise an AttributeError.

Conflicts:
	akanda/rug/test/unit/test_main.py

Change-Id: I69afab5409a10b6b3b0a652be496dcd34ba19bf7
This commit is contained in:
Ryan Petrello 2015-07-13 10:43:34 -04:00
parent 1023978760
commit fb40092f6f
6 changed files with 25 additions and 18 deletions

View File

@ -255,8 +255,8 @@ class TestNeutronWrapper(unittest.TestCase):
neutron_wrapper = neutron.Neutron(conf)
neutron_wrapper.purge_management_interface()
driver.get_device_name.assert_called_once()
driver.unplug.assert_called_once()
self.assertEqual(driver.get_device_name.call_count, 1)
self.assertEqual(driver.unplug.call_count, 1)
def test_clear_device_id(self):
neutron_wrapper = neutron.Neutron(mock.Mock())

View File

@ -253,7 +253,7 @@ class TestBridgeInterfaceDriver(TestBase):
with mock.patch('akanda.rug.common.linux.interface.LOG.debug') as log:
br = interface.BridgeInterfaceDriver(self.conf)
br.unplug('tap0')
log.assert_called_once()
self.assertEqual(log.call_count, 1)
self.ip_dev.assert_has_calls([mock.call('tap0', 'sudo', None),
mock.call().link.delete()])

View File

@ -55,4 +55,4 @@ class TestDebug(unittest.TestCase):
automaton.return_value.send_message.assert_called_once_with(
CrudMatch('update')
)
automaton.return_value.update.assert_called
self.assertEqual(automaton.return_value.update.call_count, 1)

View File

@ -31,12 +31,11 @@ from akanda.rug import notifications as ak_notifications
@mock.patch('akanda.rug.main.scheduler')
@mock.patch('akanda.rug.main.populate')
@mock.patch('akanda.rug.main.health')
@mock.patch('akanda.rug.main.shuffle_notifications')
class TestMainPippo(unittest.TestCase):
def test_shuffle_notifications(self, shuffle_notifications,
health, populate, scheduler, notifications,
multiprocessing, neutron_api, cfg):
def test_shuffle_notifications(self, health, populate, scheduler,
notifications, multiprocessing, neutron_api,
cfg):
queue = mock.Mock()
queue.get.side_effect = [
('9306bbd8-f3cc-11e2-bd68-080027e60b25', 'message'),
@ -44,12 +43,13 @@ class TestMainPippo(unittest.TestCase):
]
sched = scheduler.Scheduler.return_value
main.shuffle_notifications(queue, sched)
sched.handle_message.assert_called_once('message')
sched.stop.assert_called_once()
sched.handle_message.assert_called_once_with(
'9306bbd8-f3cc-11e2-bd68-080027e60b25',
'message'
)
def test_shuffle_notifications_error(
self, shuffle_notifications,
health, populate, scheduler, notifications,
self, health, populate, scheduler, notifications,
multiprocessing, neutron_api, cfg):
queue = mock.Mock()
queue.get.side_effect = [
@ -59,9 +59,11 @@ class TestMainPippo(unittest.TestCase):
]
sched = scheduler.Scheduler.return_value
main.shuffle_notifications(queue, sched)
sched.handle_message.assert_called_once('message')
sched.stop.assert_called_once()
sched.handle_message.assert_called_once_with(
'9306bbd8-f3cc-11e2-bd68-080027e60b25', 'message'
)
@mock.patch('akanda.rug.main.shuffle_notifications')
def test_ensure_local_service_port(self, shuffle_notifications, health,
populate, scheduler, notifications,
multiprocessing, neutron_api, cfg):
@ -69,6 +71,7 @@ class TestMainPippo(unittest.TestCase):
neutron = neutron_api.Neutron.return_value
neutron.ensure_local_service_port.assert_called_once_with()
@mock.patch('akanda.rug.main.shuffle_notifications')
def test_ceilometer_disabled(self, shuffle_notifications, health,
populate, scheduler, notifications,
multiprocessing, neutron_api, cfg):
@ -80,6 +83,7 @@ class TestMainPippo(unittest.TestCase):
self.assertEqual(len(notifications.Publisher.mock_calls), 0)
self.assertEqual(len(notifications.NoopPublisher.mock_calls), 1)
@mock.patch('akanda.rug.main.shuffle_notifications')
def test_ceilometer_enabled(self, shuffle_notifications, health,
populate, scheduler, notifications,
multiprocessing, neutron_api, cfg):

View File

@ -44,9 +44,12 @@ class TestScheduler(unittest.TestCase):
s = scheduler.Scheduler(2, mock.Mock)
s.stop()
for w in s.workers:
w['queue'].put.assert_called_once(None)
w['queue'].close.assert_called_once()
w['worker'].join.assert_called_once()
self.assertEqual(
w['queue'].put.call_args_list,
[mock.call(None), mock.call(None)] # one put for each worker
)
self.assertEqual(w['queue'].close.call_count, 2)
self.assertEqual(w['worker'].join.call_count, 2)
class TestDispatcher(unittest.TestCase):

View File

@ -245,7 +245,7 @@ class TestDebugRouters(WorkerTestBase):
'router_id': 'this-router-id'}}),
)
self.assertEqual(set(), self.w._debug_routers)
lock.release.assert_called_once()
self.assertEqual(lock.release.call_count, 1)
def testManageNoLock(self):
self.w._debug_routers = set(['this-router-id'])