Browse files

Fixed typo, added test

  • Loading branch information...
1 parent 2e0dbd7 commit 17e618b38b5b902d9e54a32cfe85d325b178a267 @chrisglass chrisglass committed Jun 7, 2012
Showing with 16 additions and 3 deletions.
  1. +15 −2 cms/tests/menu.py
  2. +1 −1 menus/models.py
View
17 cms/tests/menu.py
@@ -123,7 +123,7 @@ def test_show_menu_num_queries(self):
"""
tpl = Template("{% load menu_tags %}{% show_menu %}")
tpl.render(context)
-
+
def test_show_menu_cache_key_leak(self):
context = self.get_context()
tpl = Template("{% load menu_tags %}{% show_menu %}")
@@ -132,7 +132,20 @@ def test_show_menu_cache_key_leak(self):
self.assertEqual(CacheKey.objects.count(), 1)
tpl.render(context)
self.assertEqual(CacheKey.objects.count(), 1)
-
+
+ def test_menu_keys_duplicate_truncates(self):
+ """
+ When two objects with the same characteristics are present in the
+ database, get_or_create truncates the database table to "invalidate"
+ the cache, before retrying. This can happen after migrations, and since
+ it's only cache, we don't want any propagation of errors.
+ """
+ CacheKey.objects.create(language="fr", site=1, key="a")
+ CacheKey.objects.create(language="fr", site=1, key="a")
+ CacheKey.objects.get_or_create(language="fr", site=1, key="a")
+
+ self.assertEqual(CacheKey.objects.count(), 1)
+
def test_only_active_tree(self):
context = self.get_context()
# test standard show_menu
View
2 menus/models.py
@@ -23,7 +23,7 @@ def get_or_create(self, **kwargs):
except CacheKey.MultipleObjectsReturned:
# Truncate the table, we don't want a funny cache object to cause
# mayhem!
- CacheKey.object.all().delete()
+ CacheKey.objects.all().delete()
return super(CacheKeyManager, self).get_or_create(**kwargs)

0 comments on commit 17e618b

Please sign in to comment.