Ticket #12057: django1.0_cache_read_defaultcallable.patch
File django1.0_cache_read_defaultcallable.patch, 1.5 KB (added by , 15 years ago) |
---|
-
tests/regressiontests/cache/tests.py
180 180 } 181 181 self.cache.set("stuff", stuff) 182 182 self.assertEqual(self.cache.get("stuff"), stuff) 183 184 def test_model_instance(self): 185 from models import Poll, expensive_calculation 186 expensive_calculation.num_runs = 0 187 my_poll = Poll(question="Well?") 188 pub_date = my_poll.pub_date 189 self.cache.set('question', my_poll, 100) 190 cached_poll = self.cache.get('question') 191 self.assertEqual(cached_poll.pub_date, pub_date) 192 # We only want the default expensive calculation run once 193 self.assertEqual(expensive_calculation.num_runs, 1) 183 194 184 195 def test_expiration(self): 185 196 # Cache values can be set to expire -
tests/regressiontests/cache/models.py
1 from django.db import models 2 from datetime import datetime 3 4 def expensive_calculation(): 5 expensive_calculation.num_runs += 1 6 return datetime.now() 7 8 class Poll(models.Model): 9 question = models.CharField(max_length=200) 10 pub_date = models.DateTimeField('date published', default=expensive_calculation)