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
473c2722
Kaydet (Commit)
473c2722
authored
May 31, 2012
tarafından
Claude Paroz
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Rewrote test_error_messages with helper test utility.
üst
2626ea4a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
104 deletions
+51
-104
test_error_messages.py
tests/modeltests/validation/test_error_messages.py
+51
-104
No files found.
tests/modeltests/validation/test_error_messages.py
Dosyayı görüntüle @
473c2722
...
@@ -5,142 +5,89 @@ from django.utils.unittest import TestCase
...
@@ -5,142 +5,89 @@ from django.utils.unittest import TestCase
class
ValidationMessagesTest
(
TestCase
):
class
ValidationMessagesTest
(
TestCase
):
def
_test_validation_messages
(
self
,
field
,
value
,
expected
):
with
self
.
assertRaises
(
ValidationError
)
as
cm
:
field
.
clean
(
value
,
None
)
self
.
assertEqual
(
cm
.
exception
.
messages
,
expected
)
def
test_autofield_field_raises_error_message
(
self
):
def
test_autofield_field_raises_error_message
(
self
):
f
=
models
.
AutoField
(
primary_key
=
True
)
f
=
models
.
AutoField
(
primary_key
=
True
)
self
.
assertRaises
(
ValidationError
,
f
.
clean
,
'foo'
,
None
)
self
.
_test_validation_messages
(
f
,
'foo'
,
try
:
[
u"'foo' value must be an integer."
])
f
.
clean
(
'foo'
,
None
)
except
ValidationError
as
e
:
self
.
assertEqual
(
e
.
messages
,
[
u"'foo' value must be an integer."
])
# primary_key must be True. Refs #12467.
# primary_key must be True. Refs #12467.
self
.
assertRaises
(
AssertionError
,
models
.
AutoField
,
'primary_key'
,
False
)
with
self
.
assertRaisesRegexp
(
AssertionError
,
try
:
"AutoFields must have primary_key=True."
)
:
models
.
AutoField
(
primary_key
=
False
)
models
.
AutoField
(
primary_key
=
False
)
except
AssertionError
as
e
:
self
.
assertEqual
(
str
(
e
),
"AutoFields must have primary_key=True."
)
def
test_integer_field_raises_error_message
(
self
):
def
test_integer_field_raises_error_message
(
self
):
f
=
models
.
IntegerField
()
f
=
models
.
IntegerField
()
self
.
assertRaises
(
ValidationError
,
f
.
clean
,
'foo'
,
None
)
self
.
_test_validation_messages
(
f
,
'foo'
,
try
:
[
u"'foo' value must be an integer."
])
f
.
clean
(
'foo'
,
None
)
except
ValidationError
as
e
:
self
.
assertEqual
(
e
.
messages
,
[
u"'foo' value must be an integer."
])
def
test_boolean_field_raises_error_message
(
self
):
def
test_boolean_field_raises_error_message
(
self
):
f
=
models
.
BooleanField
()
f
=
models
.
BooleanField
()
self
.
assertRaises
(
ValidationError
,
f
.
clean
,
'foo'
,
None
)
self
.
_test_validation_messages
(
f
,
'foo'
,
try
:
[
u"'foo' value must be either True or False."
])
f
.
clean
(
'foo'
,
None
)
except
ValidationError
as
e
:
self
.
assertEqual
(
e
.
messages
,
[
u"'foo' value must be either True or False."
])
def
test_float_field_raises_error_message
(
self
):
def
test_float_field_raises_error_message
(
self
):
f
=
models
.
FloatField
()
f
=
models
.
FloatField
()
self
.
assertRaises
(
ValidationError
,
f
.
clean
,
'foo'
,
None
)
self
.
_test_validation_messages
(
f
,
'foo'
,
try
:
[
u"'foo' value must be a float."
])
f
.
clean
(
'foo'
,
None
)
except
ValidationError
as
e
:
self
.
assertEqual
(
e
.
messages
,
[
u"'foo' value must be a float."
])
def
test_decimal_field_raises_error_message
(
self
):
def
test_decimal_field_raises_error_message
(
self
):
f
=
models
.
DecimalField
()
f
=
models
.
DecimalField
()
self
.
assertRaises
(
ValidationError
,
f
.
clean
,
'foo'
,
None
)
self
.
_test_validation_messages
(
f
,
'foo'
,
try
:
[
u"'foo' value must be a decimal number."
])
f
.
clean
(
'foo'
,
None
)
except
ValidationError
as
e
:
self
.
assertEqual
(
e
.
messages
,
[
u"'foo' value must be a decimal number."
])
def
test_null_boolean_field_raises_error_message
(
self
):
def
test_null_boolean_field_raises_error_message
(
self
):
f
=
models
.
NullBooleanField
()
f
=
models
.
NullBooleanField
()
self
.
assertRaises
(
ValidationError
,
f
.
clean
,
'foo'
,
None
)
self
.
_test_validation_messages
(
f
,
'foo'
,
try
:
[
u"'foo' value must be either None, True or False."
])
f
.
clean
(
'foo'
,
None
)
except
ValidationError
as
e
:
self
.
assertEqual
(
e
.
messages
,
[
u"'foo' value must be either None, True or False."
])
def
test_date_field_raises_error_message
(
self
):
def
test_date_field_raises_error_message
(
self
):
f
=
models
.
DateField
()
f
=
models
.
DateField
()
self
.
assertRaises
(
ValidationError
,
f
.
clean
,
'foo'
,
None
)
self
.
_test_validation_messages
(
f
,
'foo'
,
try
:
[
u"'foo' value has an invalid date format. "
f
.
clean
(
'foo'
,
None
)
u"It must be in YYYY-MM-DD format."
])
except
ValidationError
as
e
:
self
.
assertEqual
(
e
.
messages
,
[
self
.
_test_validation_messages
(
f
,
'aaaa-10-10'
,
u"'foo' value has an invalid date format. "
[
u"'aaaa-10-10' value has an invalid date format. "
u"It must be in YYYY-MM-DD format."
])
u"It must be in YYYY-MM-DD format."
])
self
.
assertRaises
(
ValidationError
,
f
.
clean
,
'aaaa-10-10'
,
None
)
self
.
_test_validation_messages
(
f
,
'2011-13-10'
,
try
:
[
u"'2011-13-10' value has the correct format (YYYY-MM-DD) "
f
.
clean
(
'aaaa-10-10'
,
None
)
u"but it is an invalid date."
])
except
ValidationError
as
e
:
self
.
assertEqual
(
e
.
messages
,
[
self
.
_test_validation_messages
(
f
,
'2011-10-32'
,
u"'aaaa-10-10' value has an invalid date format. "
[
u"'2011-10-32' value has the correct format (YYYY-MM-DD) "
u"It must be in YYYY-MM-DD format."
])
u"but it is an invalid date."
])
self
.
assertRaises
(
ValidationError
,
f
.
clean
,
'2011-13-10'
,
None
)
try
:
f
.
clean
(
'2011-13-10'
,
None
)
except
ValidationError
as
e
:
self
.
assertEqual
(
e
.
messages
,
[
u"'2011-13-10' value has the correct format (YYYY-MM-DD) "
u"but it is an invalid date."
])
self
.
assertRaises
(
ValidationError
,
f
.
clean
,
'2011-10-32'
,
None
)
try
:
f
.
clean
(
'2011-10-32'
,
None
)
except
ValidationError
as
e
:
self
.
assertEqual
(
e
.
messages
,
[
u"'2011-10-32' value has the correct format (YYYY-MM-DD) "
u"but it is an invalid date."
])
def
test_datetime_field_raises_error_message
(
self
):
def
test_datetime_field_raises_error_message
(
self
):
f
=
models
.
DateTimeField
()
f
=
models
.
DateTimeField
()
# Wrong format
# Wrong format
self
.
assertRaises
(
ValidationError
,
f
.
clean
,
'foo'
,
None
)
self
.
_test_validation_messages
(
f
,
'foo'
,
try
:
[
u"'foo' value has an invalid format. It must be "
f
.
clean
(
'foo'
,
None
)
u"in YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ] format."
])
except
ValidationError
as
e
:
self
.
assertEqual
(
e
.
messages
,
[
u"'foo' value has an invalid format. It must be "
u"in YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ] format."
])
# Correct format but invalid date
# Correct format but invalid date
self
.
assertRaises
(
ValidationError
,
f
.
clean
,
'2011-10-32'
,
None
)
self
.
_test_validation_messages
(
f
,
'2011-10-32'
,
try
:
[
u"'2011-10-32' value has the correct format "
f
.
clean
(
'2011-10-32'
,
None
)
u"(YYYY-MM-DD) but it is an invalid date."
])
except
ValidationError
as
e
:
self
.
assertEqual
(
e
.
messages
,
[
u"'2011-10-32' value has the correct format "
u"(YYYY-MM-DD) but it is an invalid date."
])
# Correct format but invalid date/time
# Correct format but invalid date/time
self
.
assertRaises
(
ValidationError
,
f
.
clean
,
'2011-10-32 10:10'
,
None
)
self
.
_test_validation_messages
(
f
,
'2011-10-32 10:10'
,
try
:
[
u"'2011-10-32 10:10' value has the correct format "
f
.
clean
(
'2011-10-32 10:10'
,
None
)
u"(YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ]) "
except
ValidationError
as
e
:
u"but it is an invalid date/time."
])
self
.
assertEqual
(
e
.
messages
,
[
u"'2011-10-32 10:10' value has the correct format "
u"(YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ]) "
u"but it is an invalid date/time."
])
def
test_time_field_raises_error_message
(
self
):
def
test_time_field_raises_error_message
(
self
):
f
=
models
.
TimeField
()
f
=
models
.
TimeField
()
# Wrong format
# Wrong format
self
.
assertRaises
(
ValidationError
,
f
.
clean
,
'foo'
,
None
)
self
.
_test_validation_messages
(
f
,
'foo'
,
try
:
[
u"'foo' value has an invalid format. It must be in "
f
.
clean
(
'foo'
,
None
)
u"HH:MM[:ss[.uuuuuu]] format."
])
except
ValidationError
as
e
:
self
.
assertEqual
(
e
.
messages
,
[
u"'foo' value has an invalid format. It must be in "
u"HH:MM[:ss[.uuuuuu]] format."
])
# Correct format but invalid time
# Correct format but invalid time
self
.
assertRaises
(
ValidationError
,
f
.
clean
,
'25:50'
,
None
)
self
.
_test_validation_messages
(
f
,
'25:50'
,
try
:
[
u"'25:50' value has the correct format "
f
.
clean
(
'25:50'
,
None
)
u"(HH:MM[:ss[.uuuuuu]]) but it is an invalid time."
])
except
ValidationError
as
e
:
self
.
assertEqual
(
e
.
messages
,
[
u"'25:50' value has the correct format "
u"(HH:MM[:ss[.uuuuuu]]) but it is an invalid time."
])
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