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
e3500496
Kaydet (Commit)
e3500496
authored
Nis 20, 2018
tarafından
Tim Graham
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Moved tests for model Field.get_choices().
üst
11b8c30b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
12 deletions
+14
-12
test_charfield.py
tests/model_fields/test_charfield.py
+0
-12
tests.py
tests/model_fields/tests.py
+14
-0
No files found.
tests/model_fields/test_charfield.py
Dosyayı görüntüle @
e3500496
...
...
@@ -3,7 +3,6 @@ from unittest import skipIf
from
django.core.exceptions
import
ValidationError
from
django.db
import
connection
,
models
from
django.test
import
SimpleTestCase
,
TestCase
from
django.utils.functional
import
lazy
from
.models
import
Post
...
...
@@ -50,17 +49,6 @@ class ValidationTests(SimpleTestCase):
with
self
.
assertRaises
(
ValidationError
):
f
.
clean
(
'not a'
,
None
)
def
test_charfield_get_choices_with_blank_defined
(
self
):
f
=
models
.
CharField
(
choices
=
[(
''
,
'<><>'
),
(
'a'
,
'A'
)])
self
.
assertEqual
(
f
.
get_choices
(
True
),
[(
''
,
'<><>'
),
(
'a'
,
'A'
)])
def
test_charfield_get_choices_doesnt_evaluate_lazy_strings
(
self
):
# Regression test for #23098
# Will raise ZeroDivisionError if lazy is evaluated
lazy_func
=
lazy
(
lambda
x
:
0
/
0
,
int
)
f
=
models
.
CharField
(
choices
=
[(
lazy_func
(
'group'
),
((
'a'
,
'A'
),
(
'b'
,
'B'
)))])
self
.
assertEqual
(
f
.
get_choices
(
True
)[
0
],
(
''
,
'---------'
))
def
test_charfield_raises_error_on_empty_input
(
self
):
f
=
models
.
CharField
(
null
=
False
)
with
self
.
assertRaises
(
ValidationError
):
...
...
tests/model_fields/tests.py
Dosyayı görüntüle @
e3500496
...
...
@@ -3,6 +3,7 @@ import pickle
from
django
import
forms
from
django.db
import
models
from
django.test
import
SimpleTestCase
,
TestCase
from
django.utils.functional
import
lazy
from
.models
import
(
Foo
,
RenamedField
,
VerboseNameField
,
Whiz
,
WhizIter
,
WhizIterEmpty
,
...
...
@@ -130,3 +131,16 @@ class ChoicesTests(SimpleTestCase):
self
.
assertEqual
(
WhizIterEmpty
(
c
=
"b"
)
.
c
,
"b"
)
# Invalid value
self
.
assertIsNone
(
WhizIterEmpty
(
c
=
None
)
.
c
)
# Blank value
self
.
assertEqual
(
WhizIterEmpty
(
c
=
''
)
.
c
,
''
)
# Empty value
class
GetChoicesTests
(
SimpleTestCase
):
def
test_blank_in_choices
(
self
):
choices
=
[(
''
,
'<><>'
),
(
'a'
,
'A'
)]
f
=
models
.
CharField
(
choices
=
choices
)
self
.
assertEqual
(
f
.
get_choices
(
include_blank
=
True
),
choices
)
def
test_lazy_strings_not_evaluated
(
self
):
lazy_func
=
lazy
(
lambda
x
:
0
/
0
,
int
)
# raises ZeroDivisionError if evaluated.
f
=
models
.
CharField
(
choices
=
[(
lazy_func
(
'group'
),
((
'a'
,
'A'
),
(
'b'
,
'B'
)))])
self
.
assertEqual
(
f
.
get_choices
(
include_blank
=
True
)[
0
],
(
''
,
'---------'
))
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