Skip to content

Commit 4675a3e

Browse files
committed
Basic travis test
1 parent 4a4be7f commit 4675a3e

File tree

4 files changed

+61
-1
lines changed

4 files changed

+61
-1
lines changed

.travis.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ python:
33
- 3.5
44

55
script:
6-
- true
6+
- pip3 install .
7+
- pip3 install pytest
8+
- JUPYTER_TOKEN=secret jupyter-notebook --config=./tests/resources/jupyter_server_config.py &
9+
- sleep 5
10+
- pytest
711

812
deploy:
913
provider: pypi

tests/resources/httpinfo.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from http.server import HTTPServer, BaseHTTPRequestHandler
2+
import sys
3+
4+
class EchoRequestInfo(BaseHTTPRequestHandler):
5+
def do_GET(self):
6+
self.send_response(200)
7+
self.send_header("Content-type", "text/plain")
8+
self.end_headers()
9+
self.wfile.write('{}\n'.format(self.requestline).encode())
10+
self.wfile.write('{}\n'.format(self.headers).encode())
11+
12+
13+
if __name__ == '__main__':
14+
port = int(sys.argv[1])
15+
server_address = ('', port)
16+
httpd = HTTPServer(server_address, EchoRequestInfo)
17+
httpd.serve_forever()
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
c.ServerProxy.servers = {
2+
'python-http': {
3+
'command': ['python3', './tests/resources/httpinfo.py', '{port}'],
4+
},
5+
'python-http-abs': {
6+
'command': ['python3', './tests/resources/httpinfo.py', '{port}'],
7+
'rewrite': '',
8+
},
9+
}
10+
#c.Application.log_level = 'DEBUG'

tests/test_proxies.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import os
2+
from http.client import HTTPConnection
3+
4+
PORT = os.getenv('TEST_PORT', 8888)
5+
TOKEN = os.getenv('JUPYTER_TOKEN', 'secret')
6+
7+
8+
def request_get(port, path, token):
9+
h = HTTPConnection('localhost', port, 10)
10+
h.request('GET', '{}?token={}'.format(path, token))
11+
return h.getresponse()
12+
13+
14+
def test_server_proxy_rewrite():
15+
r = request_get(PORT, '/python-http/abc', TOKEN)
16+
assert r.code == 200
17+
s = r.read().decode('ascii')
18+
assert s.startswith('GET /abc?token=')
19+
assert 'X-Forwarded-Context: /python-http\n' in s
20+
assert 'X-Proxycontextpath: /python-http\n' in s
21+
22+
23+
def test_server_proxy_absolute():
24+
r = request_get(PORT, '/python-http-abs/def', TOKEN)
25+
assert r.code == 200
26+
s = r.read().decode('ascii')
27+
assert s.startswith('GET /python-http-abs/def?token=')
28+
assert 'X-Forwarded-Context' not in s
29+
assert 'X-Proxycontextpath' not in s

0 commit comments

Comments
 (0)