Commits

Luke Plant committed a2d2265

Fixed #7825 - modeltests/delete tests failing after NFA merge, and improved documentation of these tests.

  • Participants
  • Parent commits 0b0a3db

Comments (0)

Files changed (1)

tests/modeltests/delete/models.py

 
 
 __test__ = {'API_TESTS': """
-# First, some tests for the datastructure we use
+### Tests for models A,B,C,D ###
+
+## First, test the CollectedObjects data structure directly
 
 >>> from django.db.models.query import CollectedObjects
 
 CyclicDependency: There is a cyclic dependency of items to be processed.
 
 
+## Second, test the usage of CollectedObjects by Model.delete()
 
 # Due to the way that transactions work in the test harness,
 # doing m.delete() here can work but fail in a real situation,
 # then try again with a known 'tricky' order.  Slightly naughty
 # access to internals here :-)
 
+# If implementation changes, then the tests may need to be simplified:
+#  - remove the lines that set the .keyOrder and clear the related
+#    object caches
+#  - remove the second set of tests (with a2, b2 etc)
+
 >>> from django.db.models.loading import cache
 
+>>> def clear_rel_obj_caches(models):
+...     for m in models:
+...         if hasattr(m._meta, '_related_objects_cache'): 
+...             del m._meta._related_objects_cache
+
 # Nice order
 >>> cache.app_models['delete'].keyOrder = ['a', 'b', 'c', 'd']
->>> del A._meta._related_objects_cache
->>> del B._meta._related_objects_cache
->>> del C._meta._related_objects_cache
->>> del D._meta._related_objects_cache
+>>> clear_rel_obj_caches([A, B, C, D])
 
 >>> a1 = A()
 >>> a1.save()
 
 # Same again with a known bad order
 >>> cache.app_models['delete'].keyOrder = ['d', 'c', 'b', 'a']
->>> del A._meta._related_objects_cache
->>> del B._meta._related_objects_cache
->>> del C._meta._related_objects_cache
->>> del D._meta._related_objects_cache
+>>> clear_rel_obj_caches([A, B, C, D])
 
 >>> a2 = A()
 >>> a2.save()
 [<class 'modeltests.delete.models.D'>, <class 'modeltests.delete.models.C'>, <class 'modeltests.delete.models.B'>, <class 'modeltests.delete.models.A'>]
 >>> a2.delete()
 
-# Tests for nullable related fields
+### Tests for models E,F - nullable related fields ###
+
+## First, test the CollectedObjects data structure directly
 
 >>> g = CollectedObjects()
 >>> g.add("key1", 1, "item1", None)
 >>> g.ordered_keys()
 ['key1', 'key2']
 
+## Second, test the usage of CollectedObjects by Model.delete()
+
 >>> e1 = E()
 >>> e1.save()
 >>> f1 = F(e=e1)