Scrapy, a fast high-level web crawling & scraping framework for Python.
Add file listing resource + redirecting resource to MockServer
Paul Tremberth7dcc86e61adf
diff --git a/tests/mockserver.py b/tests/mockserver.pyindex e611cc3ec..26ab51183 100644--- a/tests/mockserver.py+++ b/tests/mockserver.py@@ -5,13 +5,17 @@ from subprocess import Popen, PIPEfrom twisted.web.server import Site, NOT_DONE_YETfrom twisted.web.resource import Resource+from twisted.web.static import Filefrom twisted.web.test.test_webclient import PayloadResourcefrom twisted.web.server import GzipEncoderFactoryfrom twisted.web.resource import EncodingResourceWrapper+from twisted.web.util import redirectTofrom twisted.internet import reactor, sslfrom twisted.internet.task import deferLater+from scrapy.utils.python import to_bytes, to_unicode+from tests import tests_datadirdef getarg(request, name, default=None, type=None):@@ -120,6 +124,16 @@ class Echo(LeafResource):return to_bytes(json.dumps(output))+class RedirectTo(LeafResource):++ def render(self, request):+ goto = getarg(request, b'goto', b'/')+ # we force the body content, otherwise Twisted redirectTo()+ # returns HTML with <meta http-equiv="refresh"+ redirectTo(goto, request)+ return b'redirecting...'++class Partial(LeafResource):def render_GET(self, request):@@ -160,6 +174,8 @@ class Root(Resource):self.putChild(b"echo", Echo())self.putChild(b"payload", PayloadResource())self.putChild(b"xpayload", EncodingResourceWrapper(PayloadResource(), [GzipEncoderFactory()]))+ self.putChild(b"files", File(os.path.join(tests_datadir, 'test_site/files/')))+ self.putChild(b"redirect-to", RedirectTo())def getChild(self, name, request):return selfdiff --git a/tests/sample_data/test_site/files/images/python-logo-master-v3-TM-flattened.png b/tests/sample_data/test_site/files/images/python-logo-master-v3-TM-flattened.pngnew file mode 100644index 000000000..738f6ed41Binary files /dev/null and b/tests/sample_data/test_site/files/images/python-logo-master-v3-TM-flattened.png differdiff --git a/tests/sample_data/test_site/files/images/python-powered-h-50x65.png b/tests/sample_data/test_site/files/images/python-powered-h-50x65.pngnew file mode 100644index 000000000..37f6b4719Binary files /dev/null and b/tests/sample_data/test_site/files/images/python-powered-h-50x65.png differdiff --git a/tests/sample_data/test_site/files/images/scrapy.png b/tests/sample_data/test_site/files/images/scrapy.pngnew file mode 100644index 000000000..66e86f567Binary files /dev/null and b/tests/sample_data/test_site/files/images/scrapy.png differ