mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-16 14:33:00 +00:00
add mock single-user server for testing
This commit is contained in:
40
jupyterhub/tests/mocksu.py
Normal file
40
jupyterhub/tests/mocksu.py
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
"""Mock single-user server for testing
|
||||||
|
|
||||||
|
basic HTTP Server that echos URLs back,
|
||||||
|
and allow retrieval of sys.argv.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import json
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from tornado import web, httpserver, ioloop
|
||||||
|
|
||||||
|
|
||||||
|
class EchoHandler(web.RequestHandler):
|
||||||
|
def get(self):
|
||||||
|
self.write(self.request.path)
|
||||||
|
|
||||||
|
class ArgsHandler(web.RequestHandler):
|
||||||
|
def get(self):
|
||||||
|
self.write(json.dumps(sys.argv))
|
||||||
|
|
||||||
|
def main(args):
|
||||||
|
|
||||||
|
app = web.Application([
|
||||||
|
(r'.*/args', ArgsHandler),
|
||||||
|
(r'.*', EchoHandler),
|
||||||
|
])
|
||||||
|
|
||||||
|
server = httpserver.HTTPServer(app)
|
||||||
|
server.listen(args.port)
|
||||||
|
try:
|
||||||
|
ioloop.IOLoop.instance().start()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print('\nInterrupted')
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument('--port', type=int)
|
||||||
|
args, extra = parser.parse_known_args()
|
||||||
|
main(args)
|
Reference in New Issue
Block a user