def get_app(self): port = self.get_http_port() base_url = 'http://localhost:%s' % port self.spark = Spark(base_url=base_url) return tornado.web.Application([ (spark.proxy_root + '.*', SparkHandler, {'spark': self.spark}), (FakeReplaceHandler.handler_root, FakeReplaceHandler), (FakeVerbatimHandler.handler_root, FakeVerbatimHandler), ])
# -*- coding: utf-8 -*- import pytest import six import tornado import tornado.httpclient import tornado.testing import tornado.web from bs4 import BeautifulSoup from jupyter_spark.handlers import SparkHandler from jupyter_spark.spark import BEAUTIFULSOUP_BUILDER, Spark PROXY_PREFIX = "/proxy/application_1234556789012_3456" spark = Spark(base_url='http://localhost:8888') class FakeHandler(tornado.web.RequestHandler): def get(self): self.set_header('Content-Type', self.CONTENT_TYPE) self.write(self.RESPONSE) class FakeReplaceHandler(FakeHandler): handler_root = '/backend/replace' RESPONSE = six.b('<img src="/image.png" />') REPLACED = six.b('<img src="/spark/image.png"/>') CONTENT_TYPE = 'text/html' class FakeVerbatimHandler(FakeHandler): handler_root = '/backend/verbatim'