deleted hover borders
[wolnelektury.git] / apps / catalogue / tests.py
index 198aee8..829f8dc 100644 (file)
@@ -129,11 +129,7 @@ class BookImportLogicTests(TestCase):
         self.expected_tags.sort()
 
     def tearDown(self):
         self.expected_tags.sort()
 
     def tearDown(self):
-        for book in models.Book.objects.all():
-            if book.xml_file:
-                book.xml_file.delete()
-            if book.html_file:
-                book.html_file.delete()
+        models.Book.objects.all().delete()
 
     def test_empty_book(self):
         BOOK_TEXT = "<utwor />"
 
     def test_empty_book(self):
         BOOK_TEXT = "<utwor />"
@@ -261,11 +257,7 @@ class BooksByTagTests(TestCase):
     
     
     def tearDown(self):
     
     
     def tearDown(self):
-        for book in models.Book.objects.all():
-            if book.xml_file:
-                book.xml_file.delete()
-            if book.html_file:
-                book.html_file.delete()
+        models.Book.objects.all().delete()
 
     
     def test_nonexistent_tag(self):
 
     
     def test_nonexistent_tag(self):
@@ -321,7 +313,7 @@ class TagRelatedTagsTests(TestCase):
             book_text = """<utwor><opowiadanie><akap>
                 <begin id="m01" />
                     <motyw id="m01">Theme, %sTheme</motyw>
             book_text = """<utwor><opowiadanie><akap>
                 <begin id="m01" />
                     <motyw id="m01">Theme, %sTheme</motyw>
-                    Ala ma kąta
+                    Ala ma kota
                 <end id="m01" />
                 </akap></opowiadanie></utwor>
                 """ % info.title.encode('utf-8')
                 <end id="m01" />
                 </akap></opowiadanie></utwor>
                 """ % info.title.encode('utf-8')
@@ -335,11 +327,7 @@ class TagRelatedTagsTests(TestCase):
     
     
     def tearDown(self):
     
     
     def tearDown(self):
-        for book in models.Book.objects.all():
-            if book.xml_file:
-                book.xml_file.delete()
-            if book.html_file:
-                book.html_file.delete()
+        models.Book.objects.all().delete()
     
     
     def test_empty(self):
     
     
     def test_empty(self):
@@ -406,7 +394,83 @@ class TagRelatedTagsTests(TestCase):
         cats = self.client.get('/katalog/epoch/').context['categories']
         self.assertTrue(('Theme', 4) in [(tag.name, tag.count) for tag in cats['theme']],
                     'wrong related theme count')
         cats = self.client.get('/katalog/epoch/').context['categories']
         self.assertTrue(('Theme', 4) in [(tag.name, tag.count) for tag in cats['theme']],
                     'wrong related theme count')
+    
+
+
+class CleanTagRelationTests(TestCase):
+    """ tests for tag relations cleaning after deleting things """
+    
+    def setUp(self):
+        author = PersonStub(("Common",), "Man")
+
+        book_info = BookInfoStub(author=author, genre="G", epoch='E', kind="K", 
+                                   **info_args(u"Book"))
+        book_text = """<utwor><opowiadanie><akap>
+            <begin id="m01" /><motyw id="m01">Theme</motyw>Ala ma kota
+            <end id="m01" />
+            </akap></opowiadanie></utwor>
+            """
+        book = models.Book.from_text_and_meta(ContentFile(book_text), book_info)
+        book.save()
         
         
+        self.client = Client()
+    
+    
+    def tearDown(self):
+        models.Book.objects.all().delete()
+    
+    
+    def test_delete_objects(self):
+        """ there should be no related tags left after deleting some objects """
         
         
+        models.Book.objects.all().delete()
+        cats = self.client.get('/katalog/k/').context['categories']
+        self.assertEqual({}, cats)
+
+
+    def test_deleted_tag(self):
+        """ there should be no tag relations left after deleting tags """
+        
+        models.Tag.objects.all().delete()
+        cats = self.client.get('/katalog/lektura/book/').context['categories']
+        self.assertEqual(cats, {})
+
+
+class TestIdenticalTag(TestCase):
     
     
+    def setUp(self):
+        author = PersonStub(("A",), "B")
+
+        book_info = BookInfoStub(author=author, genre="A B", epoch='A B', kind="A B", 
+                                   **info_args(u"A B"))
+        book_text = """<utwor><opowiadanie><akap>
+            <begin id="m01" /><motyw id="m01">A B</motyw>Ala ma kota
+            <end id="m01" />
+            </akap></opowiadanie></utwor>
+            """
+        book = models.Book.from_text_and_meta(ContentFile(book_text), book_info)
+        book.save()
+        
+        self.client = Client()
+    
+    
+    def tearDown(self):
+        models.Book.objects.all().delete()
+    
+    
+    def test_book_tags(self):
+        """ there should be all related tags in relevant categories """
+        
+        cats = self.client.get('/katalog/lektura/a-b/').context['categories']
+        for category in 'author', 'kind', 'genre', 'epoch', 'theme':
+            self.assertTrue('A B' in [tag.name for tag in cats[category]],
+                            'missing related tag for %s' % category)
+
+    def test_qualified_url(self):
+        categories = {'author': 'autor', 'theme': 'motyw', 'epoch': 'epoka', 'kind':'rodzaj', 'genre':'gatunek'}
+        for cat, localcat in categories.iteritems():
+            context = self.client.get('/katalog/%s/a-b/' % localcat).context
+            self.assertEqual(1, len(context['object_list']))
+            self.assertNotEqual({}, context['categories'])
+            self.assertFalse(cat in context['categories'])