def test_find_queue(self, fake_add, fake_lock): fake_source = Mock() fake_source.id = 'fake-id' fake_lock.__enter__ = Mock() fake_lock.__exit__ = Mock() # test canceled = Mock() canceled.is_set.return_value = False batch = Batch(canceled, None, None, None, None) batch.queues[fake_source.id] = Mock() queue = batch.find_queue(fake_source) # validation self.assertFalse(fake_add.called) self.assertEqual(queue, batch.queues[fake_source.id])
def test_find_queue_not_found(self, fake_add, fake_lock): fake_source = Mock() fake_source.id = 'fake-id' fake_lock.__enter__ = Mock() fake_lock.__exit__ = Mock() # test canceled = Mock() canceled.is_set.return_value = False batch = Batch(canceled, None, None, None, None) queue = batch.find_queue(fake_source) # validation fake_add.assert_called_with(fake_source) self.assertEqual(batch._mutex.__enter__.call_count, 1) self.assertEqual(batch._mutex.__exit__.call_count, 1) self.assertEqual(queue, fake_add())