MCPcopy
hub / github.com/django/django / test_cache_read_for_model_instance

Method test_cache_read_for_model_instance

tests/cache/tests.py:460–471  ·  tests/cache/tests.py::BaseCacheTests.test_cache_read_for_model_instance
(self)

Source from the content-addressed store, hash-verified

458 self.assertEqual(cache.get(key), value)
459
460 def test_cache_read_for_model_instance(self):
461 class="cm"># Don't want fields with callable as default to be called on cache read
462 expensive_calculation.num_runs = 0
463 Poll.objects.all().delete()
464 my_poll = Poll.objects.create(question=class="st">"Well?")
465 self.assertEqual(Poll.objects.count(), 1)
466 pub_date = my_poll.pub_date
467 cache.set(class="st">"question", my_poll)
468 cached_poll = cache.get(class="st">"question")
469 self.assertEqual(cached_poll.pub_date, pub_date)
470 class="cm"># We only want the default expensive calculation run once
471 self.assertEqual(expensive_calculation.num_runs, 1)
472
473 def test_cache_write_for_model_instance_with_deferred(self):
474 class="cm"># Don't want fields with callable as default to be called on cache

Callers

nothing calls this directly

Calls 6

deleteMethod · 0.45
allMethod · 0.45
createMethod · 0.45
countMethod · 0.45
setMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected