Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Made an app-cache test not dependent on all models in defer_regress

  • Loading branch information...
commit bb80d2976bdf785a0cedd52945c8f3f55a20ace5 1 parent e6ff238
@akaariai akaariai authored
Showing with 34 additions and 53 deletions.
  1. +34 −53 tests/defer_regress/tests.py
View
87 tests/defer_regress/tests.py
@@ -98,29 +98,36 @@ def test_basic(self):
i2 = s["item"]
self.assertFalse(i2._deferred)
+ # Regression for #16409 - make sure defer() and only() work with annotate()
+ self.assertIsInstance(
+ list(SimpleItem.objects.annotate(Count('feature')).defer('name')),
+ list)
+ self.assertIsInstance(
+ list(SimpleItem.objects.annotate(Count('feature')).only('name')),
+ list)
+
+ def test_ticket_11936(self):
# Regression for #11936 - loading.get_models should not return deferred
# models by default.
- klasses = sorted(
- cache.get_models(cache.get_app("defer_regress")),
- key=lambda klass: klass.__name__
- )
- self.assertEqual(
- klasses, [
- Child,
- Feature,
- Item,
- ItemAndSimpleItem,
- Leaf,
- OneToOneItem,
- Proxy,
- RelatedItem,
- ResolveThis,
- SimpleItem,
- SpecialFeature,
- ]
+ # Run a couple of defer queries so that app-cache must contain some
+ # deferred classes. It might contain a lot more classes depending on
+ # the order the tests are ran.
+ list(Item.objects.defer("name"))
+ list(Child.objects.defer("value"))
+ klasses = set(
+ map(
+ attrgetter("__name__"),
+ cache.get_models(cache.get_app("defer_regress"))
+ )
)
-
- klasses = sorted(
+ self.assertIn("Child", klasses)
+ self.assertIn("Item", klasses)
+ self.assertNotIn("Child_Deferred_value", klasses)
+ self.assertNotIn("Item_Deferred_name", klasses)
+ self.assertFalse(any(
+ k._deferred for k in cache.get_models(cache.get_app("defer_regress"))))
+
+ klasses_with_deferred = set(
map(
attrgetter("__name__"),
cache.get_models(
@@ -128,41 +135,15 @@ def test_basic(self):
),
)
)
- # FIXME: This is dependent on the order in which tests are run --
- # this test case has to be the first, otherwise a LOT more classes
- # appear.
- self.assertEqual(
- klasses, [
- "Child",
- "Child_Deferred_value",
- "Feature",
- "Item",
- "ItemAndSimpleItem",
- "Item_Deferred_name",
- "Item_Deferred_name_other_value_text",
- "Item_Deferred_name_other_value_value",
- "Item_Deferred_other_value_text_value",
- "Item_Deferred_text_value",
- "Leaf",
- "Leaf_Deferred_child_id_second_child_id_value",
- "Leaf_Deferred_name_value",
- "Leaf_Deferred_second_child_id_value",
- "Leaf_Deferred_value",
- "OneToOneItem",
- "Proxy",
- "RelatedItem",
- "RelatedItem_Deferred_",
- "RelatedItem_Deferred_item_id",
- "ResolveThis",
- "SimpleItem",
- "SpecialFeature",
- ]
+ self.assertIn("Child", klasses_with_deferred)
+ self.assertIn("Item", klasses_with_deferred)
+ self.assertIn("Child_Deferred_value", klasses_with_deferred)
+ self.assertIn("Item_Deferred_name", klasses_with_deferred)
+ self.assertTrue(any(
+ k._deferred for k in cache.get_models(
+ cache.get_app("defer_regress"), include_deferred=True))
)
- # Regression for #16409 - make sure defer() and only() work with annotate()
- self.assertIsInstance(list(SimpleItem.objects.annotate(Count('feature')).defer('name')), list)
- self.assertIsInstance(list(SimpleItem.objects.annotate(Count('feature')).only('name')), list)
-
def test_only_and_defer_usage_on_proxy_models(self):
# Regression for #15790 - only() broken for proxy models
proxy = Proxy.objects.create(name="proxy", value=42)
Please sign in to comment.
Something went wrong with that request. Please try again.