[1.5.x] Minor fixes in the known_related_objects tests.
* Fixed JSON indentation.
* Avoided relying on implicit ordering.
Backport of a7b7efe
.
This commit is contained in:
parent
056ace0f39
commit
7be9fa224c
|
@ -4,22 +4,22 @@
|
|||
"model": "known_related_objects.tournament",
|
||||
"fields": {
|
||||
"name": "Tourney 1"
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
{
|
||||
"pk": 2,
|
||||
"model": "known_related_objects.tournament",
|
||||
"fields": {
|
||||
"name": "Tourney 2"
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
{
|
||||
"pk": 1,
|
||||
"model": "known_related_objects.organiser",
|
||||
"fields": {
|
||||
"name": "Organiser 1"
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
{
|
||||
"pk": 1,
|
||||
"model": "known_related_objects.pool",
|
||||
|
@ -27,8 +27,8 @@
|
|||
"tournament": 1,
|
||||
"organiser": 1,
|
||||
"name": "T1 Pool 1"
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
{
|
||||
"pk": 2,
|
||||
"model": "known_related_objects.pool",
|
||||
|
@ -36,8 +36,8 @@
|
|||
"tournament": 1,
|
||||
"organiser": 1,
|
||||
"name": "T1 Pool 2"
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
{
|
||||
"pk": 3,
|
||||
"model": "known_related_objects.pool",
|
||||
|
@ -45,8 +45,8 @@
|
|||
"tournament": 2,
|
||||
"organiser": 1,
|
||||
"name": "T2 Pool 1"
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
{
|
||||
"pk": 4,
|
||||
"model": "known_related_objects.pool",
|
||||
|
@ -54,23 +54,23 @@
|
|||
"tournament": 2,
|
||||
"organiser": 1,
|
||||
"name": "T2 Pool 2"
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
{
|
||||
"pk": 1,
|
||||
"model": "known_related_objects.poolstyle",
|
||||
"fields": {
|
||||
"name": "T1 Pool 2 Style",
|
||||
"pool": 2
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
{
|
||||
"pk": 2,
|
||||
"model": "known_related_objects.poolstyle",
|
||||
"fields": {
|
||||
"name": "T2 Pool 1 Style",
|
||||
"pool": 3
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ class ExistingRelatedInstancesTests(TestCase):
|
|||
|
||||
def test_foreign_key_multiple_prefetch(self):
|
||||
with self.assertNumQueries(2):
|
||||
tournaments = list(Tournament.objects.prefetch_related('pool_set'))
|
||||
tournaments = list(Tournament.objects.prefetch_related('pool_set').order_by('pk'))
|
||||
pool1 = tournaments[0].pool_set.all()[0]
|
||||
self.assertIs(tournaments[0], pool1.tournament)
|
||||
pool2 = tournaments[1].pool_set.all()[0]
|
||||
|
@ -81,7 +81,7 @@ class ExistingRelatedInstancesTests(TestCase):
|
|||
|
||||
def test_one_to_one_multi_select_related(self):
|
||||
with self.assertNumQueries(1):
|
||||
poolstyles = list(PoolStyle.objects.select_related('pool'))
|
||||
poolstyles = list(PoolStyle.objects.select_related('pool').order_by('pk'))
|
||||
self.assertIs(poolstyles[0], poolstyles[0].pool.poolstyle)
|
||||
self.assertIs(poolstyles[1], poolstyles[1].pool.poolstyle)
|
||||
|
||||
|
@ -93,7 +93,7 @@ class ExistingRelatedInstancesTests(TestCase):
|
|||
|
||||
def test_one_to_one_multi_prefetch_related(self):
|
||||
with self.assertNumQueries(2):
|
||||
poolstyles = list(PoolStyle.objects.prefetch_related('pool'))
|
||||
poolstyles = list(PoolStyle.objects.prefetch_related('pool').order_by('pk'))
|
||||
self.assertIs(poolstyles[0], poolstyles[0].pool.poolstyle)
|
||||
self.assertIs(poolstyles[1], poolstyles[1].pool.poolstyle)
|
||||
|
||||
|
@ -117,12 +117,12 @@ class ExistingRelatedInstancesTests(TestCase):
|
|||
|
||||
def test_reverse_one_to_one_multi_select_related(self):
|
||||
with self.assertNumQueries(1):
|
||||
pools = list(Pool.objects.select_related('poolstyle'))
|
||||
pools = list(Pool.objects.select_related('poolstyle').order_by('pk'))
|
||||
self.assertIs(pools[1], pools[1].poolstyle.pool)
|
||||
self.assertIs(pools[2], pools[2].poolstyle.pool)
|
||||
|
||||
def test_reverse_one_to_one_multi_prefetch_related(self):
|
||||
with self.assertNumQueries(2):
|
||||
pools = list(Pool.objects.prefetch_related('poolstyle'))
|
||||
pools = list(Pool.objects.prefetch_related('poolstyle').order_by('pk'))
|
||||
self.assertIs(pools[1], pools[1].poolstyle.pool)
|
||||
self.assertIs(pools[2], pools[2].poolstyle.pool)
|
||||
|
|
Loading…
Reference in New Issue