Exemple #1
0
    def test_dispatch_no_remaining_sources(self, fake_decrement, fake_find):
        fake_queue = Mock()
        fake_request = Mock()
        sources = []
        fake_request.sources = iter(sources)
        fake_find.return_value = fake_queue

        # test
        canceled = Mock()
        canceled.is_set.return_value = False
        batch = Batch(canceled, None, None, None, None)
        dispatched = batch.dispatch(fake_request)

        # validation
        fake_decrement.assert_called_once_with()
        self.assertFalse(dispatched)
        self.assertFalse(fake_queue.put.called)
        self.assertFalse(fake_find.called)
Exemple #2
0
    def test_dispatch_no_remaining_sources(self, fake_decrement, fake_find):
        fake_queue = Mock()
        fake_request = Mock()
        sources = []
        fake_request.sources = iter(sources)
        fake_find.return_value = fake_queue

        # test
        canceled = Mock()
        canceled.is_set.return_value = False
        batch = Batch(canceled, None, None, None, None)
        dispatched = batch.dispatch(fake_request)

        # validation
        fake_decrement.assert_called_once_with()
        self.assertFalse(dispatched)
        self.assertFalse(fake_queue.put.called)
        self.assertFalse(fake_find.called)
Exemple #3
0
    def test_dispatch(self, fake_find, fake_item, fake_decrement):
        fake_queue = Mock()
        fake_request = Mock()
        sources = [(Mock(), 'http://')]
        fake_request.sources = iter(sources)
        fake_find.return_value = fake_queue
        # test
        canceled = Mock()
        canceled.is_set.return_value = False
        batch = Batch(canceled, None, None, None, None)
        dispatched = batch.dispatch(fake_request)

        # validation
        fake_find.assert_called_with(sources[0][0])
        fake_item.assert_called_with(fake_request, sources[0][1])
        fake_queue.put.assert_called_with(fake_item())
        self.assertTrue(dispatched)
        self.assertFalse(fake_decrement.called)
Exemple #4
0
    def test_dispatch(self, fake_find, fake_item, fake_decrement):
        fake_queue = Mock()
        fake_request = Mock()
        sources = [(Mock(), 'http://')]
        fake_request.sources = iter(sources)
        fake_find.return_value = fake_queue
        # test
        canceled = Mock()
        canceled.is_set.return_value = False
        batch = Batch(canceled, None, None, None, None)
        dispatched = batch.dispatch(fake_request)

        # validation
        fake_find.assert_called_with(sources[0][0])
        fake_item.assert_called_with(fake_request, sources[0][1])
        fake_queue.put.assert_called_with(fake_item())
        self.assertTrue(dispatched)
        self.assertFalse(fake_decrement.called)