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
4d658400
Kaydet (Commit)
4d658400
authored
Ock 27, 2017
tarafından
Anton Samarchyan
Kaydeden (comit)
Tim Graham
Şub 03, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Refs #27745 -- Improved test coverage of contrib.contenttypes.
üst
aa145289
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
2 deletions
+39
-2
test_fields.py
tests/contenttypes_tests/test_fields.py
+23
-1
tests.py
tests/generic_relations/tests.py
+16
-1
No files found.
tests/contenttypes_tests/test_fields.py
Dosyayı görüntüle @
4d658400
import
json
from
django.contrib.contenttypes.fields
import
GenericForeignKey
from
django.db
import
models
from
django.test
import
SimpleTestCase
from
django.test
import
SimpleTestCase
,
TestCase
from
django.test.utils
import
isolate_apps
from
.models
import
Answer
,
Question
@isolate_apps
(
'contenttypes_tests'
)
class
GenericForeignKeyTests
(
SimpleTestCase
):
...
...
@@ -11,3 +15,21 @@ class GenericForeignKeyTests(SimpleTestCase):
class
Model
(
models
.
Model
):
field
=
GenericForeignKey
()
self
.
assertEqual
(
str
(
Model
.
field
),
'contenttypes_tests.Model.field'
)
def
test_get_content_type_no_arguments
(
self
):
with
self
.
assertRaisesMessage
(
Exception
,
'Impossible arguments to GFK.get_content_type!'
):
Answer
.
question
.
get_content_type
()
def
test_incorrect_get_prefetch_queryset_arguments
(
self
):
with
self
.
assertRaisesMessage
(
ValueError
,
"Custom queryset can't be used for this lookup."
):
Answer
.
question
.
get_prefetch_queryset
(
Answer
.
objects
.
all
(),
Answer
.
objects
.
all
())
class
GenericRelationTests
(
TestCase
):
def
test_value_to_string
(
self
):
question
=
Question
.
objects
.
create
(
text
=
'test'
)
answer1
=
Answer
.
objects
.
create
(
question
=
question
)
answer2
=
Answer
.
objects
.
create
(
question
=
question
)
result
=
json
.
loads
(
Question
.
answer_set
.
field
.
value_to_string
(
question
))
self
.
assertCountEqual
(
result
,
[
answer1
.
pk
,
answer2
.
pk
])
tests/generic_relations/tests.py
Dosyayı görüntüle @
4d658400
...
...
@@ -2,9 +2,10 @@ from django import forms
from
django.contrib.contenttypes.forms
import
generic_inlineformset_factory
from
django.contrib.contenttypes.models
import
ContentType
from
django.core.exceptions
import
FieldError
from
django.db
import
IntegrityError
from
django.db
import
IntegrityError
,
models
from
django.db.models
import
Q
from
django.test
import
SimpleTestCase
,
TestCase
from
django.test.utils
import
isolate_apps
from
.models
import
(
AllowsNullGFK
,
Animal
,
Carrot
,
Comparison
,
ConcreteRelatedModel
,
...
...
@@ -272,6 +273,11 @@ class GenericRelationsTests(TestCase):
with
self
.
assertRaisesMessage
(
ValueError
,
msg
):
self
.
bacon
.
tags
.
add
(
t1
)
def
test_add_rejects_wrong_instances
(
self
):
msg
=
"'TaggedItem' instance expected, got <Animal: Lion>"
with
self
.
assertRaisesMessage
(
TypeError
,
msg
):
self
.
bacon
.
tags
.
add
(
self
.
lion
)
def
test_set
(
self
):
bacon
=
Vegetable
.
objects
.
create
(
name
=
"Bacon"
,
is_yucky
=
False
)
fatty
=
bacon
.
tags
.
create
(
tag
=
"fatty"
)
...
...
@@ -596,6 +602,15 @@ class GenericInlineFormsetTest(TestCase):
form
=
Formset
()
.
forms
[
0
]
self
.
assertIsInstance
(
form
[
'tag'
]
.
field
.
widget
,
CustomWidget
)
@isolate_apps
(
'generic_relations'
)
def
test_incorrect_content_type
(
self
):
class
BadModel
(
models
.
Model
):
content_type
=
models
.
PositiveIntegerField
()
msg
=
"fk_name 'generic_relations.BadModel.content_type' is not a ForeignKey to ContentType"
with
self
.
assertRaisesMessage
(
Exception
,
msg
):
generic_inlineformset_factory
(
BadModel
,
TaggedItemForm
)
def
test_save_new_uses_form_save
(
self
):
"""
Regression for #16260: save_new should call form.save()
...
...
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