Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
f8d52521
Kaydet (Commit)
f8d52521
authored
Şub 01, 2017
tarafından
Tim Graham
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Refs #27804 -- Used subTest() in tests.utils_tests.test_html.
üst
2af8cd22
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
44 deletions
+53
-44
test_html.py
tests/utils_tests/test_html.py
+53
-44
No files found.
tests/utils_tests/test_html.py
Dosyayı görüntüle @
f8d52521
...
...
@@ -32,11 +32,13 @@ class TestUtilsHtml(SimpleTestCase):
# Substitution patterns for testing the above items.
patterns
=
(
"
%
s"
,
"asdf
%
sfdsa"
,
"
%
s1"
,
"1
%
sb"
)
for
value
,
output
in
items
:
for
pattern
in
patterns
:
self
.
check_output
(
escape
,
pattern
%
value
,
pattern
%
output
)
self
.
check_output
(
escape
,
lazystr
(
pattern
%
value
),
pattern
%
output
)
# Check repeated values.
self
.
check_output
(
escape
,
value
*
2
,
output
*
2
)
with
self
.
subTest
(
value
=
value
,
output
=
output
):
for
pattern
in
patterns
:
with
self
.
subTest
(
value
=
value
,
output
=
output
,
pattern
=
pattern
):
self
.
check_output
(
escape
,
pattern
%
value
,
pattern
%
output
)
self
.
check_output
(
escape
,
lazystr
(
pattern
%
value
),
pattern
%
output
)
# Check repeated values.
self
.
check_output
(
escape
,
value
*
2
,
output
*
2
)
# Verify it doesn't double replace &.
self
.
check_output
(
escape
,
'<&'
,
'<&'
)
...
...
@@ -60,8 +62,9 @@ class TestUtilsHtml(SimpleTestCase):
(
"para1
\t
more
\n\n
para2"
,
"<p>para1
\t
more</p>
\n\n
<p>para2</p>"
),
)
for
value
,
output
in
items
:
self
.
check_output
(
linebreaks
,
value
,
output
)
self
.
check_output
(
linebreaks
,
lazystr
(
value
),
output
)
with
self
.
subTest
(
value
=
value
,
output
=
output
):
self
.
check_output
(
linebreaks
,
value
,
output
)
self
.
check_output
(
linebreaks
,
lazystr
(
value
),
output
)
def
test_strip_tags
(
self
):
items
=
(
...
...
@@ -83,37 +86,36 @@ class TestUtilsHtml(SimpleTestCase):
# caused infinite loop on Pythons not patched with
# http://bugs.python.org/issue20288
(
'&gotcha&#;<>'
,
'&gotcha&#;<>'
),
(
'<sc<!-- -->ript>test<<!-- -->/script>'
,
'ript>test'
),
(
'<script>alert()</script>&h'
,
'alert()h'
),
)
for
value
,
output
in
items
:
self
.
check_output
(
strip_tags
,
value
,
output
)
self
.
check_output
(
strip_tags
,
lazystr
(
value
),
output
)
# Some convoluted syntax for which parsing may differ between python versions
output
=
strip_tags
(
'<sc<!-- -->ript>test<<!-- -->/script>'
)
self
.
assertNotIn
(
'<script>'
,
output
)
self
.
assertIn
(
'test'
,
output
)
output
=
strip_tags
(
'<script>alert()</script>&h'
)
self
.
assertNotIn
(
'<script>'
,
output
)
self
.
assertIn
(
'alert()'
,
output
)
with
self
.
subTest
(
value
=
value
,
output
=
output
):
self
.
check_output
(
strip_tags
,
value
,
output
)
self
.
check_output
(
strip_tags
,
lazystr
(
value
),
output
)
def
test_strip_tags_files
(
self
):
# Test with more lengthy content (also catching performance regressions)
for
filename
in
(
'strip_tags1.html'
,
'strip_tags2.txt'
):
path
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'files'
,
filename
)
with
open
(
path
,
'r'
)
as
fp
:
content
=
fp
.
read
()
start
=
datetime
.
now
()
stripped
=
strip_tags
(
content
)
elapsed
=
datetime
.
now
()
-
start
self
.
assertEqual
(
elapsed
.
seconds
,
0
)
self
.
assertIn
(
"Please try again."
,
stripped
)
self
.
assertNotIn
(
'<'
,
stripped
)
with
self
.
subTest
(
filename
=
filename
):
path
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'files'
,
filename
)
with
open
(
path
,
'r'
)
as
fp
:
content
=
fp
.
read
()
start
=
datetime
.
now
()
stripped
=
strip_tags
(
content
)
elapsed
=
datetime
.
now
()
-
start
self
.
assertEqual
(
elapsed
.
seconds
,
0
)
self
.
assertIn
(
"Please try again."
,
stripped
)
self
.
assertNotIn
(
'<'
,
stripped
)
def
test_strip_spaces_between_tags
(
self
):
# Strings that should come out untouched.
items
=
(
' <adf>'
,
'<adf> '
,
' </adf> '
,
' <f> x</f>'
)
for
value
in
items
:
self
.
check_output
(
strip_spaces_between_tags
,
value
)
self
.
check_output
(
strip_spaces_between_tags
,
lazystr
(
value
))
with
self
.
subTest
(
value
=
value
):
self
.
check_output
(
strip_spaces_between_tags
,
value
)
self
.
check_output
(
strip_spaces_between_tags
,
lazystr
(
value
))
# Strings that have spaces to strip.
items
=
(
(
'<d> </d>'
,
'<d></d>'
),
...
...
@@ -121,8 +123,9 @@ class TestUtilsHtml(SimpleTestCase):
(
'
\n
<p>
\t
</p>
\n
<p> </p>
\n
'
,
'
\n
<p></p><p></p>
\n
'
),
)
for
value
,
output
in
items
:
self
.
check_output
(
strip_spaces_between_tags
,
value
,
output
)
self
.
check_output
(
strip_spaces_between_tags
,
lazystr
(
value
),
output
)
with
self
.
subTest
(
value
=
value
,
output
=
output
):
self
.
check_output
(
strip_spaces_between_tags
,
value
,
output
)
self
.
check_output
(
strip_spaces_between_tags
,
lazystr
(
value
),
output
)
def
test_escapejs
(
self
):
items
=
(
...
...
@@ -139,23 +142,29 @@ class TestUtilsHtml(SimpleTestCase):
),
)
for
value
,
output
in
items
:
self
.
check_output
(
escapejs
,
value
,
output
)
self
.
check_output
(
escapejs
,
lazystr
(
value
),
output
)
with
self
.
subTest
(
value
=
value
,
output
=
output
):
self
.
check_output
(
escapejs
,
value
,
output
)
self
.
check_output
(
escapejs
,
lazystr
(
value
),
output
)
def
test_smart_urlquote
(
self
):
quote
=
smart_urlquote
items
=
(
(
'http://öäü.com/'
,
'http://xn--4ca9at.com/'
),
(
'http://öäü.com/öäü/'
,
'http://xn--4ca9at.com/
%
C3
%
B6
%
C3
%
A4
%
C3
%
BC/'
),
# Everything unsafe is quoted, !*'();:@&=+$,/?#[]~ is considered
# safe as per RFC.
(
'http://example.com/path/öäü/'
,
'http://example.com/path/
%
C3
%
B6
%
C3
%
A4
%
C3
%
BC/'
),
(
'http://example.com/
%
C3
%
B6/ä/'
,
'http://example.com/
%
C3
%
B6/
%
C3
%
A4/'
),
(
'http://example.com/?x=1&y=2+3&z='
,
'http://example.com/?x=1&y=2+3&z='
),
(
'http://example.com/?x=<>"
\'
'
,
'http://example.com/?x=
%3
C
%3
E
%22%27
'
),
(
'http://example.com/?q=http://example.com/?x=1
%26
q=django'
,
'http://example.com/?q=http
%3
A
%2
F
%2
Fexample.com
%2
F
%3
Fx
%3
D1
%26
q
%3
Ddjango'
),
(
'http://example.com/?q=http
%3
A
%2
F
%2
Fexample.com
%2
F
%3
Fx
%3
D1
%26
q
%3
Ddjango'
,
'http://example.com/?q=http
%3
A
%2
F
%2
Fexample.com
%2
F
%3
Fx
%3
D1
%26
q
%3
Ddjango'
),
)
# IDNs are properly quoted
self
.
assertEqual
(
quote
(
'http://öäü.com/'
),
'http://xn--4ca9at.com/'
)
self
.
assertEqual
(
quote
(
'http://öäü.com/öäü/'
),
'http://xn--4ca9at.com/
%
C3
%
B6
%
C3
%
A4
%
C3
%
BC/'
)
# Everything unsafe is quoted, !*'();:@&=+$,/?#[]~ is considered safe as per RFC
self
.
assertEqual
(
quote
(
'http://example.com/path/öäü/'
),
'http://example.com/path/
%
C3
%
B6
%
C3
%
A4
%
C3
%
BC/'
)
self
.
assertEqual
(
quote
(
'http://example.com/
%
C3
%
B6/ä/'
),
'http://example.com/
%
C3
%
B6/
%
C3
%
A4/'
)
self
.
assertEqual
(
quote
(
'http://example.com/?x=1&y=2+3&z='
),
'http://example.com/?x=1&y=2+3&z='
)
self
.
assertEqual
(
quote
(
'http://example.com/?x=<>"
\'
'
),
'http://example.com/?x=
%3
C
%3
E
%22%27
'
)
self
.
assertEqual
(
quote
(
'http://example.com/?q=http://example.com/?x=1
%26
q=django'
),
'http://example.com/?q=http
%3
A
%2
F
%2
Fexample.com
%2
F
%3
Fx
%3
D1
%26
q
%3
Ddjango'
)
self
.
assertEqual
(
quote
(
'http://example.com/?q=http
%3
A
%2
F
%2
Fexample.com
%2
F
%3
Fx
%3
D1
%26
q
%3
Ddjango'
),
'http://example.com/?q=http
%3
A
%2
F
%2
Fexample.com
%2
F
%3
Fx
%3
D1
%26
q
%3
Ddjango'
)
for
value
,
output
in
items
:
with
self
.
subTest
(
value
=
value
,
output
=
output
):
self
.
assertEqual
(
smart_urlquote
(
value
),
output
)
def
test_conditional_escape
(
self
):
s
=
'<h1>interop</h1>'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment