Browse Source

commit missing file and additional files moving to MisagoTestCache

Rafał Pitoń 9 years ago
parent
commit
d18b4baf28
2 changed files with 33 additions and 5 deletions
  1. 20 0
      misago/core/testutils.py
  2. 13 5
      misago/threads/tests/test_threadslists.py

+ 20 - 0
misago/core/testutils.py

@@ -0,0 +1,20 @@
+from django.test import TestCase
+from misago.core import threadstore
+from misago.core.cache import cache
+
+
+class MisagoTestCase(TestCase):
+    """
+    TestCase class that empties global state before and after each test
+    """
+    def clear_state(self):
+        cache.clear()
+        threadstore.clear()
+
+    def setUp(self):
+        super(MisagoTestCase, self).setUp()
+        self.clear_state()
+
+    def tearDown(self):
+        self.clear_state()
+        super(MisagoTestCase, self).tearDown()

+ 13 - 5
misago/threads/tests/test_threadslists.py

@@ -29,9 +29,6 @@ class ThreadsListTestCase(AuthenticatedUserTestCase):
 
 
         self.api_link = '/api/threads/'
         self.api_link = '/api/threads/'
 
 
-        cache.clear()
-        threadstore.clear()
-
         self.root = Category.objects.root_category()
         self.root = Category.objects.root_category()
         self.first_category = Category.objects.get(slug='first-category')
         self.first_category = Category.objects.get(slug='first-category')
 
 
@@ -94,11 +91,22 @@ class ThreadsListTestCase(AuthenticatedUserTestCase):
 
 
         self.category_f = Category.objects.get(slug='category-f')
         self.category_f = Category.objects.get(slug='category-f')
 
 
+        self.clear_state()
+
+        Category.objects.partial_rebuild(self.root.tree_id)
+
+        self.root = Category.objects.root_category()
+        self.category_a = Category.objects.get(slug='category-a')
+        self.category_b = Category.objects.get(slug='category-b')
+        self.category_c = Category.objects.get(slug='category-c')
+        self.category_d = Category.objects.get(slug='category-d')
+        self.category_e = Category.objects.get(slug='category-e')
+        self.category_f = Category.objects.get(slug='category-f')
+
         self.access_all_categories()
         self.access_all_categories()
 
 
     def access_all_categories(self, extra=None):
     def access_all_categories(self, extra=None):
-        cache.clear()
-        threadstore.clear()
+        self.clear_state()
 
 
         categories_acl = {'categories': {}, 'visible_categories': []}
         categories_acl = {'categories': {}, 'visible_categories': []}
         for category in Category.objects.all_categories():
         for category in Category.objects.all_categories():