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
4bcec023
Kaydet (Commit)
4bcec023
authored
Ock 12, 2018
tarafından
Tim Graham
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Added tests for django.forms.formsets.all_valid().
üst
1f0813ca
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
1 deletion
+41
-1
test_formsets.py
tests/forms_tests/tests/test_formsets.py
+41
-1
No files found.
tests/forms_tests/tests/test_formsets.py
Dosyayı görüntüle @
4bcec023
...
...
@@ -6,7 +6,7 @@ from django.forms import (
BaseForm
,
CharField
,
DateField
,
FileField
,
Form
,
IntegerField
,
SplitDateTimeField
,
ValidationError
,
formsets
,
)
from
django.forms.formsets
import
BaseFormSet
,
formset_factory
from
django.forms.formsets
import
BaseFormSet
,
all_valid
,
formset_factory
from
django.forms.utils
import
ErrorList
from
django.test
import
SimpleTestCase
...
...
@@ -1320,3 +1320,43 @@ class TestEmptyFormSet(SimpleTestCase):
class
FileForm
(
Form
):
file
=
FileField
()
self
.
assertTrue
(
formset_factory
(
FileForm
,
extra
=
0
)()
.
is_multipart
())
class
AllValidTests
(
SimpleTestCase
):
def
test_valid
(
self
):
data
=
{
'choices-TOTAL_FORMS'
:
'2'
,
'choices-INITIAL_FORMS'
:
'0'
,
'choices-MIN_NUM_FORMS'
:
'0'
,
'choices-0-choice'
:
'Zero'
,
'choices-0-votes'
:
'0'
,
'choices-1-choice'
:
'One'
,
'choices-1-votes'
:
'1'
,
}
ChoiceFormSet
=
formset_factory
(
Choice
)
formset1
=
ChoiceFormSet
(
data
,
auto_id
=
False
,
prefix
=
'choices'
)
formset2
=
ChoiceFormSet
(
data
,
auto_id
=
False
,
prefix
=
'choices'
)
self
.
assertIs
(
all_valid
((
formset1
,
formset2
)),
True
)
expected_errors
=
[{},
{}]
self
.
assertEqual
(
formset1
.
_errors
,
expected_errors
)
self
.
assertEqual
(
formset2
.
_errors
,
expected_errors
)
def
test_invalid
(
self
):
"""all_valid() validates all forms, even when some are invalid."""
data
=
{
'choices-TOTAL_FORMS'
:
'2'
,
'choices-INITIAL_FORMS'
:
'0'
,
'choices-MIN_NUM_FORMS'
:
'0'
,
'choices-0-choice'
:
'Zero'
,
'choices-0-votes'
:
''
,
'choices-1-choice'
:
'One'
,
'choices-1-votes'
:
''
,
}
ChoiceFormSet
=
formset_factory
(
Choice
)
formset1
=
ChoiceFormSet
(
data
,
auto_id
=
False
,
prefix
=
'choices'
)
formset2
=
ChoiceFormSet
(
data
,
auto_id
=
False
,
prefix
=
'choices'
)
self
.
assertIs
(
all_valid
((
formset1
,
formset2
)),
False
)
expected_errors
=
[{
'votes'
:
[
'This field is required.'
]},
{
'votes'
:
[
'This field is required.'
]}]
self
.
assertEqual
(
formset1
.
_errors
,
expected_errors
)
self
.
assertEqual
(
formset2
.
_errors
,
expected_errors
)
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