FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
validators/tests/test_url.py at master · pythonthings/validators · GitHub
pythonthings
validators
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
validators
/
tests
/
test_url.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
147 lines (137 loc) · 4.42 KB
Breadcrumbs
validators
/
tests
/
test_url.py
Copy path
File metadata and controls
147 lines (137 loc) · 4.42 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# -*- coding: utf-8 -*-
import
pytest
from
validators
import
url
,
ValidationFailure
@
pytest
.
mark
.
parametrize
(
'address'
, [
u'http://foobar.dk'
,
u'http://foobar.museum/foobar'
,
u'http://fo.com'
,
u'http://FOO.com'
,
u'http://foo.com/blah_blah'
,
u'http://foo.com/blah_blah/'
,
u'http://foo.com/blah_blah_(wikipedia)'
,
u'http://foo.com/blah_blah_(wikipedia)_(again)'
,
u'http://www.example.com/wpstyle/?p=364'
,
u'https://www.example.com/foo/?bar=baz&inga=42&quux'
,
u'https://www.example.com?bar=baz'
,
u'http://✪df.ws/123'
,
u'http://userid:password@example.com:8080'
,
u'http://userid:password@example.com:8080/'
,
u'http://userid@example.com'
,
u'http://userid@example.com/'
,
u'http://userid@example.com:8080'
,
u'http://userid@example.com:8080/'
,
u'http://userid:password@example.com'
,
u'http://userid:password@example.com/'
,
u'http://142.42.1.1/'
,
u'http://142.42.1.1:8080/'
,
u'http://➡.ws/䨹'
,
u'http://⌘.ws'
,
u'http://⌘.ws/'
,
u'http://foo.com/blah_(wikipedia)#cite-1'
,
u'http://foo.com/blah_(wikipedia)_blah#cite-1'
,
u'http://foo.com/unicode_(✪)_in_parens'
,
u'http://foo.com/(something)?after=parens'
,
u'http://☺.damowmow.com/'
,
u'http://code.google.com/events/#&product=browser'
,
u'http://j.mp'
,
u'ftp://foo.bar/baz'
,
u'http://foo.bar/?q=Test%20URL-encoded%20stuff'
,
u'http://مثال.إختبار'
,
u'http://例子.测试'
,
u'http://उदाहरण.परीक्षा'
,
u'http://-.~_!$&
\'
()*+,;=:%40:80%2f::::::@example.com'
,
u'http://1337.net'
,
u'http://a.b-c.de'
,
u'http://223.255.255.254'
,
u'http://10.1.1.1'
,
u'http://10.1.1.254'
,
u'http://127.0.0.1:8080'
,
u'http://127.0.10.150'
,
u'http://localhost'
,
u'http://localhost:8000'
,
u'http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html'
,
u'http://[1080:0:0:0:8:800:200C:417A]/index.html'
,
u'http://[3ffe:2a00:100:7031::1]'
,
u'http://[1080::8:800:200C:417A]/foo'
,
u'http://[::192.9.5.5]/ipng'
,
u'http://[::FFFF:129.144.52.38]:80/index.html'
,
u'http://[2010:836B:4179::836B:4179]'
,
])
def
test_returns_true_on_valid_url
(
address
):
assert
url
(
address
)
@
pytest
.
mark
.
parametrize
(
'address, public'
, [
(
u'http://foo.bar'
,
True
),
(
u'http://username:password@example.com:4010/'
,
False
),
(
u'http://username:password@112.168.10.10:4010/'
,
True
),
(
u'http://username:password@192.168.10.10:4010/'
,
False
),
(
u'http://10.0.10.1'
,
False
),
(
u'http://127.0.0.1'
,
False
),
])
def
test_returns_true_on_valid_public_url
(
address
,
public
):
assert
url
(
address
,
public
=
public
)
@
pytest
.
mark
.
parametrize
(
'address'
, [
'http://foobar'
,
'foobar.dk'
,
'http://127.0.0/asdf'
,
'http://foobar.d'
,
'http://foobar.12'
,
'http://foobar'
,
'htp://foobar.com'
,
'http://foobar..com'
,
'http://fo..com'
,
'http://'
,
'http://.'
,
'http://..'
,
'http://../'
,
'http://?'
,
'http://??'
,
'http://??/'
,
'http://#'
,
'http://##'
,
'http://##/'
,
'http://foo.bar?q=Spaces should be encoded'
,
'//'
,
'//a'
,
'///a'
,
'///'
,
'http:///a'
,
'foo.com'
,
'rdar://1234'
,
'h://test'
,
'http:// shouldfail.com'
,
':// should fail'
,
'http://foo.bar/foo(bar)baz quux'
,
'ftps://foo.bar/'
,
'http://-error-.invalid/'
,
'http://a.b--c.de/'
,
'http://-a.b.co'
,
'http://a.b-.co'
,
'http://0.0.0.0'
,
'http://10.1.1.0'
,
'http://10.1.1.255'
,
'http://224.1.1.1'
,
'http://1.1.1.1.1'
,
'http://123.123.123'
,
'http://3628126748'
,
'http://.www.foo.bar/'
,
'http://www.foo.bar./'
,
'http://.www.foo.bar./'
,
'http://127.12.0.260'
,
'http://example.com/">user@example.com'
,
'http://[2010:836B:4179::836B:4179'
,
'http://2010:836B:4179::836B:4179'
,
'http://2010:836B:4179::836B:4179:80/index.html'
,
])
def
test_returns_failed_validation_on_invalid_url
(
address
):
assert
isinstance
(
url
(
address
),
ValidationFailure
)
@
pytest
.
mark
.
parametrize
(
'address, public'
, [
(
u'http://username:password@192.168.10.10:4010/'
,
True
),
(
u'http://10.0.10.1'
,
True
),
(
u'http://127.0.0.1'
,
True
),
(
u'foo://127.0.0.1'
,
True
),
(
u'http://username:password@127.0.0.1:8080'
,
True
),
(
u'http://localhost'
,
True
),
(
u'http://localhost:8000'
,
True
),
])
def
test_returns_failed_validation_on_invalid_public_url
(
address
,
public
):
assert
isinstance
(
url
(
address
,
public
=
public
),
ValidationFailure
)
Back
|
FazBrowse Home
|
New Git URL