Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #7825 - modeltests/delete tests failing after NFA merge, and im…

…proved documentation of these tests.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8030 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 384a721e1cd02b9c47f0d797ec8865e518aee84f 1 parent fb51608
Luke Plant authored July 21, 2008

Showing 1 changed file with 21 additions and 10 deletions. Show diff stats Hide diff stats

  1. 31  tests/modeltests/delete/models.py
31  tests/modeltests/delete/models.py
@@ -42,7 +42,9 @@ class F(DefaultRepr, models.Model):
42 42
 
43 43
 
44 44
 __test__ = {'API_TESTS': """
45  
-# First, some tests for the datastructure we use
  45
+### Tests for models A,B,C,D ###
  46
+
  47
+## First, test the CollectedObjects data structure directly
46 48
 
47 49
 >>> from django.db.models.query import CollectedObjects
48 50
 
@@ -72,6 +74,7 @@ class F(DefaultRepr, models.Model):
72 74
 CyclicDependency: There is a cyclic dependency of items to be processed.
73 75
 
74 76
 
  77
+## Second, test the usage of CollectedObjects by Model.delete()
75 78
 
76 79
 # Due to the way that transactions work in the test harness,
77 80
 # doing m.delete() here can work but fail in a real situation,
@@ -84,14 +87,21 @@ class F(DefaultRepr, models.Model):
84 87
 # then try again with a known 'tricky' order.  Slightly naughty
85 88
 # access to internals here :-)
86 89
 
  90
+# If implementation changes, then the tests may need to be simplified:
  91
+#  - remove the lines that set the .keyOrder and clear the related
  92
+#    object caches
  93
+#  - remove the second set of tests (with a2, b2 etc)
  94
+
87 95
 >>> from django.db.models.loading import cache
88 96
 
  97
+>>> def clear_rel_obj_caches(models):
  98
+...     for m in models:
  99
+...         if hasattr(m._meta, '_related_objects_cache'): 
  100
+...             del m._meta._related_objects_cache
  101
+
89 102
 # Nice order
90 103
 >>> cache.app_models['delete'].keyOrder = ['a', 'b', 'c', 'd']
91  
->>> del A._meta._related_objects_cache
92  
->>> del B._meta._related_objects_cache
93  
->>> del C._meta._related_objects_cache
94  
->>> del D._meta._related_objects_cache
  104
+>>> clear_rel_obj_caches([A, B, C, D])
95 105
 
96 106
 >>> a1 = A()
97 107
 >>> a1.save()
@@ -110,10 +120,7 @@ class F(DefaultRepr, models.Model):
110 120
 
111 121
 # Same again with a known bad order
112 122
 >>> cache.app_models['delete'].keyOrder = ['d', 'c', 'b', 'a']
113  
->>> del A._meta._related_objects_cache
114  
->>> del B._meta._related_objects_cache
115  
->>> del C._meta._related_objects_cache
116  
->>> del D._meta._related_objects_cache
  123
+>>> clear_rel_obj_caches([A, B, C, D])
117 124
 
118 125
 >>> a2 = A()
119 126
 >>> a2.save()
@@ -130,7 +137,9 @@ class F(DefaultRepr, models.Model):
130 137
 [<class 'modeltests.delete.models.D'>, <class 'modeltests.delete.models.C'>, <class 'modeltests.delete.models.B'>, <class 'modeltests.delete.models.A'>]
131 138
 >>> a2.delete()
132 139
 
133  
-# Tests for nullable related fields
  140
+### Tests for models E,F - nullable related fields ###
  141
+
  142
+## First, test the CollectedObjects data structure directly
134 143
 
135 144
 >>> g = CollectedObjects()
136 145
 >>> g.add("key1", 1, "item1", None)
@@ -142,6 +151,8 @@ class F(DefaultRepr, models.Model):
142 151
 >>> g.ordered_keys()
143 152
 ['key1', 'key2']
144 153
 
  154
+## Second, test the usage of CollectedObjects by Model.delete()
  155
+
145 156
 >>> e1 = E()
146 157
 >>> e1.save()
147 158
 >>> f1 = F(e=e1)

0 notes on commit 384a721

Please sign in to comment.
Something went wrong with that request. Please try again.