def test_middleware(self): mw = HttpCacheMiddleware(self._get_settings(), self.crawler.stats) assert mw.process_request(self.request, self.spider) is None mw.process_response(self.request, self.response, self.spider) response = mw.process_request(self.request, self.spider) assert isinstance(response, HtmlResponse) self.assertEqualResponse(self.response, response) assert 'cached' in response.flags
def _middleware(self, **new_settings): settings = self._get_settings(**new_settings) mw = HttpCacheMiddleware(settings, self.crawler.stats) mw.spider_opened(self.spider) try: yield mw finally: mw.spider_closed(self.spider)
def test_different_request_response_urls(self): mw = HttpCacheMiddleware(self._get_settings(), self.crawler.stats) req = Request('http://host.com/path') res = Response('http://host2.net/test.html') assert mw.process_request(req, self.spider) is None mw.process_response(req, res, self.spider) cached = mw.process_request(req, self.spider) assert isinstance(cached, Response) self.assertEqualResponse(res, cached) assert 'cached' in cached.flags
def _get_middleware(self, **new_settings): mw = HttpCacheMiddleware(self._get_settings(**new_settings), self.crawler.stats) mw.spider_opened(self.spider) return mw
def _get_middleware(self, **new_settings): return HttpCacheMiddleware(self._get_settings(**new_settings), self.crawler.stats)
def _get_middleware(self, **new_settings): return HttpCacheMiddleware(self._get_settings(**new_settings))