Ticket #12057: django1.1.1_cache_read_defaultcallable.patch
File django1.1.1_cache_read_defaultcallable.patch, 1.6 KB (added by , 15 years ago) |
---|
-
tests/regressiontests/cache/tests.py
210 210 } 211 211 self.cache.set("stuff", stuff) 212 212 self.assertEqual(self.cache.get("stuff"), stuff) 213 214 def test_model_instance(self): 215 from models import Poll, expensive_calculation 216 expensive_calculation.num_runs = 0 217 my_poll = Poll(question="Well?") 218 pub_date = my_poll.pub_date 219 self.cache.set('question', my_poll, 100) 220 cached_poll = self.cache.get('question') 221 self.assertEqual(cached_poll.pub_date, pub_date) 222 # We only want the default expensive calculation run once 223 self.assertEqual(expensive_calculation.num_runs, 1) 213 224 214 225 def test_expiration(self): 215 226 # Cache values can be set to expire -
tests/regressiontests/cache/models.py
1 from django.db import models 2 from datetime import datetime 3 import traceback 4 5 def expensive_calculation(): 6 expensive_calculation.num_runs += 1 7 8 if expensive_calculation.num_runs > 1: 9 traceback.print_stack() 10 11 return datetime.now() 12 13 class Poll(models.Model): 14 question = models.CharField(max_length=200) 15 pub_date = models.DateTimeField('date published', default=expensive_calculation)