Scrapy, a fast high-level web crawling & scraping framework for Python.
Test for not calling the download function when downloader middleware returns a response in process_request.
Artur Gaspar2748b38592b7
diff --git a/tests/test_downloadermiddleware.py b/tests/test_downloadermiddleware.pyindex 257eab609..a5e765d9d 100644--- a/tests/test_downloadermiddleware.py+++ b/tests/test_downloadermiddleware.py@@ -5,6 +5,7 @@ from scrapy.http import Request, Responsefrom scrapy.spiders import Spiderfrom scrapy.core.downloader.middleware import DownloaderMiddlewareManagerfrom scrapy.utils.test import get_crawler+from tests import mockclass ManagerTestCase(TestCase):@@ -90,3 +91,24 @@ class DefaultsTest(ManagerTestCase):'Location': 'http://example.com/login',})self.assertRaises(IOError, self._download, request=req, response=resp)+++class ResponseFromProcessRequestTest(ManagerTestCase):+ """Tests middleware returning a response from process_request."""++ def test_download_func_not_called(self):+ class ResponseMiddleware(object):+ def process_request(self, request, spider):+ return Response(request.url)++ self.mwman._add_middleware(ResponseMiddleware())++ req = Request('http://example.com/index.html')+ download_func = mock.MagicMock()+ dfd = self.mwman.download(download_func, req, self.spider)+ results = []+ dfd.addBoth(results.append)+ self._wait(dfd)++ self.assertIsInstance(results[0], Response)+ self.assertFalse(download_func.called)