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
311b3ad9
Kaydet (Commit)
311b3ad9
authored
Eyl 29, 2014
tarafından
Thomas Chaumeny
Kaydeden (comit)
Simon Charette
Eyl 29, 2014
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #23567 -- Made assertQuerysetEqual check Counter equality when ordered=False
üst
df578bf1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
2 deletions
+45
-2
testcases.py
django/test/testcases.py
+2
-1
models.py
tests/test_utils/models.py
+15
-0
tests.py
tests/test_utils/tests.py
+28
-1
No files found.
django/test/testcases.py
Dosyayı görüntüle @
311b3ad9
from
__future__
import
unicode_literals
from
collections
import
Counter
from
copy
import
copy
import
difflib
import
errno
...
...
@@ -871,7 +872,7 @@ class TransactionTestCase(SimpleTestCase):
def
assertQuerysetEqual
(
self
,
qs
,
values
,
transform
=
repr
,
ordered
=
True
,
msg
=
None
):
items
=
six
.
moves
.
map
(
transform
,
qs
)
if
not
ordered
:
return
self
.
assertEqual
(
set
(
items
),
set
(
values
),
msg
=
msg
)
return
self
.
assertEqual
(
Counter
(
items
),
Counter
(
values
),
msg
=
msg
)
values
=
list
(
values
)
# For example qs.iterator() could be passed as qs, but it does not
# have 'ordered' attribute.
...
...
tests/test_utils/models.py
Dosyayı görüntüle @
311b3ad9
from
django.db
import
models
from
django.utils.encoding
import
python_2_unicode_compatible
@python_2_unicode_compatible
class
Car
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
100
)
def
__str__
(
self
):
return
self
.
name
@python_2_unicode_compatible
class
Person
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
100
)
cars
=
models
.
ManyToManyField
(
Car
,
through
=
'PossessedCar'
)
def
__str__
(
self
):
return
self
.
name
@python_2_unicode_compatible
class
PossessedCar
(
models
.
Model
):
car
=
models
.
ForeignKey
(
Car
)
belongs_to
=
models
.
ForeignKey
(
Person
)
def
__str__
(
self
):
return
self
.
color
tests/test_utils/tests.py
Dosyayı görüntüle @
311b3ad9
...
...
@@ -14,7 +14,7 @@ from django.test.html import HTMLParseError, parse_html
from
django.test.utils
import
CaptureQueriesContext
,
override_settings
from
django.utils
import
six
from
.models
import
Person
from
.models
import
Car
,
Person
,
PossessedCar
from
.views
import
empty_response
...
...
@@ -178,6 +178,33 @@ class AssertQuerysetEqualTests(TestCase):
[
repr
(
self
.
p1
)]
)
def
test_repeated_values
(
self
):
"""
Test that assertQuerysetEqual checks the number of appearance of each item
when used with option ordered=False.
"""
batmobile
=
Car
.
objects
.
create
(
name
=
'Batmobile'
)
k2000
=
Car
.
objects
.
create
(
name
=
'K 2000'
)
PossessedCar
.
objects
.
bulk_create
([
PossessedCar
(
car
=
batmobile
,
belongs_to
=
self
.
p1
),
PossessedCar
(
car
=
batmobile
,
belongs_to
=
self
.
p1
),
PossessedCar
(
car
=
k2000
,
belongs_to
=
self
.
p1
),
PossessedCar
(
car
=
k2000
,
belongs_to
=
self
.
p1
),
PossessedCar
(
car
=
k2000
,
belongs_to
=
self
.
p1
),
PossessedCar
(
car
=
k2000
,
belongs_to
=
self
.
p1
),
])
with
self
.
assertRaises
(
AssertionError
):
self
.
assertQuerysetEqual
(
self
.
p1
.
cars
.
all
(),
[
repr
(
batmobile
),
repr
(
k2000
)],
ordered
=
False
)
self
.
assertQuerysetEqual
(
self
.
p1
.
cars
.
all
(),
[
repr
(
batmobile
)]
*
2
+
[
repr
(
k2000
)]
*
4
,
ordered
=
False
)
@override_settings
(
ROOT_URLCONF
=
'test_utils.urls'
)
class
CaptureQueriesContextManagerTests
(
TestCase
):
...
...
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