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
b04fd579
Kaydet (Commit)
b04fd579
authored
Nis 12, 2013
tarafından
Claude Paroz
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #20237 (again) Allowed binary parameter to assertContains
üst
8fc68af9
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
7 deletions
+18
-7
testcases.py
django/test/testcases.py
+10
-4
tests.py
tests/test_client_regress/tests.py
+8
-3
No files found.
django/test/testcases.py
Dosyayı görüntüle @
b04fd579
...
@@ -622,6 +622,9 @@ class TransactionTestCase(SimpleTestCase):
...
@@ -622,6 +622,9 @@ class TransactionTestCase(SimpleTestCase):
if
not
isinstance
(
text
,
bytes
)
or
html
:
if
not
isinstance
(
text
,
bytes
)
or
html
:
text
=
force_text
(
text
,
encoding
=
response
.
_charset
)
text
=
force_text
(
text
,
encoding
=
response
.
_charset
)
content
=
content
.
decode
(
response
.
_charset
)
content
=
content
.
decode
(
response
.
_charset
)
text_repr
=
"'
%
s'"
%
text
else
:
text_repr
=
repr
(
text
)
if
html
:
if
html
:
content
=
assert_and_parse_html
(
self
,
content
,
None
,
content
=
assert_and_parse_html
(
self
,
content
,
None
,
"Response's content is not valid HTML:"
)
"Response's content is not valid HTML:"
)
...
@@ -630,11 +633,11 @@ class TransactionTestCase(SimpleTestCase):
...
@@ -630,11 +633,11 @@ class TransactionTestCase(SimpleTestCase):
real_count
=
content
.
count
(
text
)
real_count
=
content
.
count
(
text
)
if
count
is
not
None
:
if
count
is
not
None
:
self
.
assertEqual
(
real_count
,
count
,
self
.
assertEqual
(
real_count
,
count
,
msg_prefix
+
"Found
%
d instances of
'
%
s'
in response"
msg_prefix
+
"Found
%
d instances of
%
s
in response"
" (expected
%
d)"
%
(
real_count
,
text
,
count
))
" (expected
%
d)"
%
(
real_count
,
text
_repr
,
count
))
else
:
else
:
self
.
assertTrue
(
real_count
!=
0
,
self
.
assertTrue
(
real_count
!=
0
,
msg_prefix
+
"Couldn't find
'
%
s' in response"
%
text
)
msg_prefix
+
"Couldn't find
%
s in response"
%
text_repr
)
def
assertNotContains
(
self
,
response
,
text
,
status_code
=
200
,
def
assertNotContains
(
self
,
response
,
text
,
status_code
=
200
,
msg_prefix
=
''
,
html
=
False
):
msg_prefix
=
''
,
html
=
False
):
...
@@ -661,13 +664,16 @@ class TransactionTestCase(SimpleTestCase):
...
@@ -661,13 +664,16 @@ class TransactionTestCase(SimpleTestCase):
if
not
isinstance
(
text
,
bytes
)
or
html
:
if
not
isinstance
(
text
,
bytes
)
or
html
:
text
=
force_text
(
text
,
encoding
=
response
.
_charset
)
text
=
force_text
(
text
,
encoding
=
response
.
_charset
)
content
=
content
.
decode
(
response
.
_charset
)
content
=
content
.
decode
(
response
.
_charset
)
text_repr
=
"'
%
s'"
%
text
else
:
text_repr
=
repr
(
text
)
if
html
:
if
html
:
content
=
assert_and_parse_html
(
self
,
content
,
None
,
content
=
assert_and_parse_html
(
self
,
content
,
None
,
'Response
\'
s content is not valid HTML:'
)
'Response
\'
s content is not valid HTML:'
)
text
=
assert_and_parse_html
(
self
,
text
,
None
,
text
=
assert_and_parse_html
(
self
,
text
,
None
,
'Second argument is not valid HTML:'
)
'Second argument is not valid HTML:'
)
self
.
assertEqual
(
content
.
count
(
text
),
0
,
self
.
assertEqual
(
content
.
count
(
text
),
0
,
msg_prefix
+
"Response should not contain
'
%
s'"
%
text
)
msg_prefix
+
"Response should not contain
%
s"
%
text_repr
)
def
assertFormError
(
self
,
response
,
form
,
field
,
errors
,
msg_prefix
=
''
):
def
assertFormError
(
self
,
response
,
form
,
field
,
errors
,
msg_prefix
=
''
):
"""
"""
...
...
tests/test_client_regress/tests.py
Dosyayı görüntüle @
b04fd579
...
@@ -133,10 +133,15 @@ class AssertContainsTests(TestCase):
...
@@ -133,10 +133,15 @@ class AssertContainsTests(TestCase):
def
test_binary_contains
(
self
):
def
test_binary_contains
(
self
):
r
=
self
.
client
.
get
(
'/test_client_regress/check_binary/'
)
r
=
self
.
client
.
get
(
'/test_client_regress/check_binary/'
)
self
.
assertContains
(
r
,
b
'
PDF document
'
)
self
.
assertContains
(
r
,
b
'
%
PDF-1.4
\r\n
%
\x93\x8c\x8b\x9e
'
)
with
self
.
assertRaises
(
AssertionError
):
with
self
.
assertRaises
(
AssertionError
):
self
.
assertContains
(
r
,
b
'PDF document'
,
count
=
2
)
self
.
assertContains
(
r
,
b
'
%
PDF-1.4
\r\n
%
\x93\x8c\x8b\x9e
'
,
count
=
2
)
self
.
assertNotContains
(
r
,
b
'ODF document'
)
def
test_binary_not_contains
(
self
):
r
=
self
.
client
.
get
(
'/test_client_regress/check_binary/'
)
self
.
assertNotContains
(
r
,
b
'
%
ODF-1.4
\r\n
%
\x93\x8c\x8b\x9e
'
)
with
self
.
assertRaises
(
AssertionError
):
self
.
assertNotContains
(
r
,
b
'
%
PDF-1.4
\r\n
%
\x93\x8c\x8b\x9e
'
)
def
test_nontext_contains
(
self
):
def
test_nontext_contains
(
self
):
r
=
self
.
client
.
get
(
'/test_client_regress/no_template_view/'
)
r
=
self
.
client
.
get
(
'/test_client_regress/no_template_view/'
)
...
...
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