-
Notifications
You must be signed in to change notification settings - Fork 323
/
Copy pathtest_paths.py
68 lines (59 loc) · 1.66 KB
/
test_paths.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import re
import pytest
import tornado
from jupyter_server.base.handlers import path_regex
from jupyter_server.utils import url_path_join
# build regexps that tornado uses:
path_pat = re.compile("^" + "/x%s" % path_regex + "$")
def test_path_regex():
for path in (
"/x",
"/x/",
"/x/foo",
"/x/foo.ipynb",
"/x/foo/bar",
"/x/foo/bar.txt",
):
assert re.match(path_pat, path)
def test_path_regex_bad():
for path in (
"/xfoo",
"/xfoo/",
"/xfoo/bar",
"/xfoo/bar/",
"/x/foo/bar/",
"/x//foo",
"/y",
"/y/x/foo",
):
assert re.match(path_pat, path) is None
@pytest.mark.parametrize(
"uri,expected",
[
("/notebooks/mynotebook/", "/notebooks/mynotebook"),
("////foo///", "/foo"),
("//example.com/", "/example.com"),
("/has/param/?hasparam=true", "/has/param?hasparam=true"),
],
)
async def test_trailing_slash(
uri,
expected,
http_server_client,
jp_auth_header,
jp_base_url,
):
# http_server_client raises an exception when follow_redirects=False
with pytest.raises(tornado.httpclient.HTTPClientError) as err:
await http_server_client.fetch(
url_path_join(jp_base_url, uri),
headers=jp_auth_header,
request_timeout=20,
follow_redirects=False,
)
# Capture the response from the raised exception value.
response = err.value.response
assert response is not None
assert response.code == 302
assert "Location" in response.headers
assert response.headers["Location"] == url_path_join(jp_base_url, expected)