-
Notifications
You must be signed in to change notification settings - Fork 5
/
tests.py
executable file
·123 lines (113 loc) · 3.36 KB
/
tests.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import re
from importd import d
d(no_atexit=True)
from smarturls import translate_regex, surl, url
assert url == surl
TESTS = {
"/<int:foo>/": (
["/123/", "/123123123123123/", "/1/"],
["/123", "/asd/", "/12/3/", "/123.123/", "/123a/"]
),
"/<int2:foo>/": (
["/12/", "/01/"],
["/123/", "/123", "/asd/", "/123.123/", "/123a/"]
),
"/<int4:foo>": (
["/0000", "/0122"],
["/1234/", "/123", "/asd/", "/123.123/", "/123a/"]
),
"/<word:foo>/": (
["/asd/", "/123/", "/a/"],
["/as-d/", "/asd.d/", "/asd"]
),
"/<digit:foo>/": (
["/1/", "/0/"],
["/123/", "/12/", "/1", "/123", "/asd/", "/123.123/", "/123a/"]
),
"/<slug:foo>/": (
["/asd/", "/123/", "/a/", "/asd-123/", "/asd-qwe-123---/"],
["/as-d", "/asd.d/", "/asd", "/asd.txt/"]
),
"/<username:foo>/": (
[
"/asd/", "/123/", "/---/", "/john.doe/",
"/amitu@foo/", "/[email protected]/"
], ["/asd", "/asd%20/"]
),
"/<uuid:foo>/": (
[
"/21EC2020-3AEA-4069-A2DD-08002B30309D/",
"/21EC20203AEA4069A2DD08002B30309D/"
],
[
"/21EC2020-3AEA-4069-A2DD_08002B30309D/",
"/21EC2020-3AEA-4069-A2DD-08002B30309G/",
"/21EC20203AEA4069A2DD08002B30309G/",
"/asd/", "/acs_asd/"
]
),
"/<base64:foo>/": (
[
"/21EC2020-3AEA-4069-A2DD-08002B30309D/",
"/21EC20203AEA4069A2DD08002B30309D/",
"/21EC20203AEA4069A2DD08002B30309D==/",
"/21EC20203AEA4069A2DD08002B30309D=/",
"/21EC20203a__EA4069A2DD08002B30309D/",
],
[
"/21EC20203AEA4069A2DD08002B30309D===/",
"/21EC2020.3AEA-4069-A2DD-08002B30309D/",
"/21EC20203,AEA4069A2DD08002B30309D/",
"/21EC20203A+EA4069A2==DD08002B30309D/",
"/21EC20203A EA4069A2DD08002B30309D/",
]
),
"/<ekey:foo>/": (
[
"/21EC2020-3AEA-4069-A2DD-08002B30309D/",
"/21EC20203AEA4069A2DD08002B30309D/",
"/21EC20203AEA4069A2DD08002B30309D/",
"/21EC20203AEA4069A2DD08002B30309D",
"/21EC20203a__EA4069A2DD08002B30309D/",
],
[
"/21EC20203AEA4069A2DD08002B30309D.../",
"/21EC2020.3AEA-4069-A2DD-08002B30309D/",
"/21EC20203,AEA4069A2DD08002B30309D/",
"/21EC20203A+EA4069A2..DD08002B30309D/",
"/21EC20203A EA4069A2DD08002B30309D/",
]
),
"/<something:foo>/": (
[
"/123/", "/aFRT23213/", "/sdf323$%3142-.@&*`~/",
],
[
"//",
],
),
"/<anything:foo>/": (
[
"/123/", "/aFRT23213/", "/sdf323$%3142-.@&*`~/",
"//",
],
[],
),
}
TESTS["/<foo>/"] = TESTS["/<word:foo>/"]
count = 0
for pattern in TESTS:
passing, failing = TESTS[pattern]
patternt = translate_regex(pattern)
patternc = re.compile(patternt)
for url in passing:
assert patternc.match(url[1:]), "p: %s %s %s" % (
url, pattern, patternt
)
count += 1
for url in failing:
assert not patternc.match(url[1:]), "f: %s %s %s" % (
url, pattern, patternt
)
count += 1
print("All {0} smarturls tests passed.".format(count))