Code

Ticket #17439: attribute_cache_test.diff

File attribute_cache_test.diff, 755 bytes (added by gwahl@…, 2 years ago)
Line 
1Index: tests/modeltests/one_to_one/tests.py
2===================================================================
3--- tests/modeltests/one_to_one/tests.py        (revision 17238)
4+++ tests/modeltests/one_to_one/tests.py        (working copy)
5@@ -121,3 +121,11 @@
6         mm = MultiModel(link1=self.p2, link2=o1, name="x1")
7         self.assertRaises(IntegrityError, mm.save)
8         transaction.savepoint_rollback(sid)
9+
10+    def test_attribute_caching(self):
11+        # must do a query
12+        self.assertRaises(Restaurant.DoesNotExist, getattr, self.p2, 'restaurant')
13+
14+        # accessing the same attribute again should not do a query
15+        with self.assertNumQueries(0):
16+            self.assertRaises(Restaurant.DoesNotExist, getattr, self.p2, 'restaurant')