Ejemplo n.º 1
0
    def test_halt(self):
        # test
        queue = RequestQueue(Mock(), Mock())
        queue.halt()

        # validation
        self.assertTrue(queue._halted)
Ejemplo n.º 2
0
    def test_run(self, fake_feed):
        # test
        queue = RequestQueue(Mock(), Mock())
        queue.run()

        # validation
        queue.downloader.download.assert_called_with(fake_feed())
Ejemplo n.º 3
0
    def test_put(self, fake_queue):
        # test
        item = Mock()
        queue = RequestQueue(Mock(), Mock())
        queue.put(item)

        # validation
        fake_queue().put.assert_called_with(item, timeout=3)
Ejemplo n.º 4
0
    def test_put_halted(self, fake_queue):
        # test
        item = Mock()
        queue = RequestQueue(Mock(), Mock())
        queue.halt()
        queue.put(item)

        # validation
        self.assertFalse(fake_queue().put.called)
Ejemplo n.º 5
0
    def test_get_halted(self, fake_queue):
        # test
        queue = RequestQueue(Mock(), Mock())
        queue.halt()
        item = queue.get()

        # validation
        self.assertFalse(fake_queue().get.called)
        self.assertEqual(item, None)
Ejemplo n.º 6
0
    def test_run_with_exception(self, fake_feed, fake_drain):
        # test
        queue = RequestQueue(Mock(), Mock())
        queue.downloader.download.side_effect = ValueError()
        queue.run()

        # validation
        queue.downloader.download.assert_called_with(fake_feed())
        fake_drain.assert_called_with()
Ejemplo n.º 7
0
    def test_halt(self):
        canceled = Mock()
        canceled.is_set.return_value = False

        # test
        queue = RequestQueue(canceled, Mock())
        queue.halt()

        # validation
        self.assertTrue(queue._halted)
Ejemplo n.º 8
0
    def test_run(self, fake_feed):
        canceled = Mock()
        canceled.is_set.return_value = False

        # test
        queue = RequestQueue(canceled, Mock())
        queue.run()

        # validation
        queue.downloader.download.assert_called_with(fake_feed())
Ejemplo n.º 9
0
    def test_put_full(self, fake_queue):
        fake_queue().put.side_effect = SideEffect([Full(), Full(), None])

        # test
        item = Mock()
        queue = RequestQueue(Mock(), Mock())
        queue.put(item)

        # validation
        self.assertEqual(fake_queue().put.call_count, 3)
Ejemplo n.º 10
0
    def test_get_empty(self, fake_queue):
        fake_queue().get.side_effect = SideEffect([Empty(), Empty(), 123])

        # test
        queue = RequestQueue(Mock(), Mock())
        item = queue.get()

        # validation
        self.assertEqual(fake_queue().get.call_count, 3)
        self.assertEqual(item, 123)
Ejemplo n.º 11
0
    def test_get(self, fake_queue):
        fake_queue().get.return_value = 123

        # test
        queue = RequestQueue(Mock(), Mock())
        item = queue.get()

        # validation
        fake_queue().get.assert_called_with(timeout=3)
        self.assertEqual(item, 123)
Ejemplo n.º 12
0
    def test_put(self, fake_queue):
        canceled = Mock()
        canceled.is_set.return_value = False

        # test
        item = Mock()
        queue = RequestQueue(canceled, Mock())
        queue.put(item)

        # validation
        fake_queue().put.assert_called_with(item, timeout=3)
Ejemplo n.º 13
0
    def test_put_full(self, fake_queue):
        canceled = Mock()
        canceled.is_set.return_value = False
        fake_queue().put.side_effect = SideEffect([Full(), Full(), None])

        # test
        item = Mock()
        queue = RequestQueue(canceled, Mock())
        queue.put(item)

        # validation
        self.assertEqual(fake_queue().put.call_count, 3)
Ejemplo n.º 14
0
    def test_put_halted(self, fake_queue):
        canceled = Mock()
        canceled.is_set.return_value = False

        # test
        item = Mock()
        queue = RequestQueue(canceled, Mock())
        queue.halt()
        queue.put(item)

        # validation
        self.assertFalse(fake_queue().put.called)
Ejemplo n.º 15
0
    def test_get_halted(self, fake_queue):
        canceled = Mock()
        canceled.is_set.return_value = False

        # test
        queue = RequestQueue(canceled, Mock())
        queue.halt()
        item = queue.get()

        # validation
        self.assertFalse(fake_queue().get.called)
        self.assertEqual(item, None)
Ejemplo n.º 16
0
    def test_get_empty(self, fake_queue):
        canceled = Mock()
        canceled.is_set.return_value = False
        fake_queue().get.side_effect = SideEffect([Empty(), Empty(), 123])

        # test
        queue = RequestQueue(canceled, Mock())
        item = queue.get()

        # validation
        self.assertEqual(fake_queue().get.call_count, 3)
        self.assertEqual(item, 123)
Ejemplo n.º 17
0
    def test_run_with_exception(self, fake_feed, fake_drain):
        canceled = Mock()
        canceled.is_set.return_value = False

        # test
        queue = RequestQueue(canceled, Mock())
        queue.downloader.download.side_effect = ValueError()
        queue.run()

        # validation
        queue.downloader.download.assert_called_with(fake_feed())
        fake_drain.assert_called_with()
Ejemplo n.º 18
0
    def test_get(self, fake_queue):
        canceled = Mock()
        canceled.is_set.return_value = False
        fake_queue().get.return_value = 123

        # test
        queue = RequestQueue(canceled, Mock())
        item = queue.get()

        # validation
        fake_queue().get.assert_called_with(timeout=3)
        self.assertEqual(item, 123)
Ejemplo n.º 19
0
    def test_init(self, fake_queue, fake_setDaemon):
        source = Mock()
        source.id = 'fake_id'
        source.max_concurrent = 10

        # test
        queue = RequestQueue(source)
        queue.setDaemon = Mock()

        # validation
        fake_queue.assert_called_with(source.max_concurrent)
        fake_setDaemon.assert_called_with(True)
        self.assertEqual(queue._halted, False)
        self.assertEqual(queue.queue, fake_queue())
        self.assertEqual(queue.downloader, source.get_downloader())
Ejemplo n.º 20
0
    def test_drain(self, fake_feed, fake_from):
        queued = [1, 2, 3]
        fake_feed.return_value = queued
        fake_from.side_effect = queued

        # test
        queue = RequestQueue(Mock())
        queue.drain()

        # validation
        calls = fake_from.call_args_list
        self.assertEqual(len(calls), len(queued))
        for i, request in enumerate(queued):
            self.assertEqual(calls[i][0][0], request)
        calls = queue.downloader.fire_download_failed.call_args_list
        for i, request in enumerate(queued):
            self.assertEqual(calls[i][0][0], request)
Ejemplo n.º 21
0
    def test_construction(self, fake_queue, fake_setDaemon):
        source = Mock()
        source.id = 'fake_id'
        source.max_concurrent = 10

        # test
        canceled = Mock()
        canceled.is_set.return_value = False
        queue = RequestQueue(canceled, source)
        queue.setDaemon = Mock()

        # validation
        fake_queue.assert_called_with(source.max_concurrent)
        fake_setDaemon.assert_called_with(True)
        self.assertEqual(queue._halted, False)
        self.assertEqual(queue.canceled, canceled)
        self.assertEqual(queue.queue, fake_queue())
        self.assertEqual(queue.downloader, source.get_downloader())
Ejemplo n.º 22
0
    def test_put_halted(self, fake_queue):
        # test
        item = Mock()
        queue = RequestQueue(Mock())
        queue.halt()
        queue.put(item)

        # validation
        self.assertFalse(fake_queue().put.called)
Ejemplo n.º 23
0
    def test_put_halted(self, fake_queue):
        canceled = Mock()
        canceled.is_set.return_value = False

        # test
        item = Mock()
        queue = RequestQueue(canceled, Mock())
        queue.halt()
        queue.put(item)

        # validation
        self.assertFalse(fake_queue().put.called)
Ejemplo n.º 24
0
    def test__run(self):
        canceled = Mock()
        canceled.is_set.return_value = False

        # test
        queue = RequestQueue(canceled, Mock())

        # validation
        # all good
        queue._halted = False
        canceled.is_set.return_value = False
        self.assertTrue(queue._run)
        # halted only
        queue._halted = True
        canceled.is_set.return_value = False
        self.assertFalse(queue._run)
        # canceled only
        queue._halted = False
        canceled.is_set.return_value = True
        self.assertFalse(queue._run)
        # both
        queue._halted = True
        canceled.is_set.return_value = True
        self.assertFalse(queue._run)