+
+
+class BookTagsTests(WLTestCase):
+ """ tests the /katalog/lektura/book/ page for related tags """
+
+ def setUp(self):
+ WLTestCase.setUp(self)
+ author1 = PersonStub(("Common",), "Man")
+ author2 = PersonStub(("Jim",), "Lazy")
+
+ child_info = BookInfoStub(authors=(author1, author2), genre="ChildGenre", epoch='Epoch', kind="ChildKind",
+ **info_args(u"Child"))
+ parent_info = BookInfoStub(author=author1, genre="Genre", epoch='Epoch', kind="Kind",
+ parts=[child_info.url],
+ **info_args(u"Parent"))
+
+ for info in child_info, parent_info:
+ book_text = """<utwor><opowiadanie><akap>
+ <begin id="m01" />
+ <motyw id="m01">Theme, %sTheme</motyw>
+ Ala ma kota
+ <end id="m01" />
+ </akap></opowiadanie></utwor>
+ """ % info.title.encode('utf-8')
+ models.Book.from_text_and_meta(ContentFile(book_text), info)
+
+ def test_book_tags(self):
+ """ book should have own tags and whole tree's themes """
+
+ book = models.Book.objects.get(slug='parent')
+ related_info = book.related_info()
+ related_themes = book.related_themes()
+
+ self.assertEqual(related_info['tags']['author'],
+ [('Common Man', 'common-man')])
+ self.assertEqual(related_info['tags']['kind'],
+ [('Kind', 'kind')])
+ self.assertEqual([(tag.name, tag.count) for tag in related_themes],
+ [('ChildTheme', 1), ('ParentTheme', 1), ('Theme', 2)])
+
+ def test_main_page_tags(self):
+ """ test main page tags and counts """
+ from catalogue.templatetags.catalogue_tags import catalogue_menu
+ menu = catalogue_menu()
+ self.assertEqual([(tag.name, tag.book_count) for tag in menu['author']],
+ [('Jim Lazy', 1), ('Common Man', 1)])
+ self.assertEqual([(tag.name, tag.book_count) for tag in menu['theme']],
+ [('ChildTheme', 1), ('ParentTheme', 1), ('Theme', 2)])
+