From b1a0a6e25810353f46d314cea1fd34bd37109b0c Mon Sep 17 00:00:00 2001 From: Paul Tremberth Date: Tue, 25 Apr 2017 17:01:54 +0200 Subject: [PATCH] Make mockserver runnable outside of tox Add POST support for Echo resource --- tests/mockserver.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/mockserver.py b/tests/mockserver.py index 26ab51183..b95a6c3c4 100644 --- a/tests/mockserver.py +++ b/tests/mockserver.py @@ -15,7 +15,6 @@ from twisted.internet.task import deferLater from scrapy.utils.python import to_bytes, to_unicode -from tests import tests_datadir def getarg(request, name, default=None, type=None): @@ -122,6 +121,7 @@ class Echo(LeafResource): 'body': to_unicode(request.content.read()), } return to_bytes(json.dumps(output)) + render_POST = render_GET class RedirectTo(LeafResource): @@ -174,7 +174,11 @@ 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/'))) + try: + from tests import tests_datadir + self.putChild(b"files", File(os.path.join(tests_datadir, 'test_site/files/'))) + except: + pass self.putChild(b"redirect-to", RedirectTo()) def getChild(self, name, request):