X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/4298f7948e8963176debf5877fce30c49ae4e3ad..75de44ecc913abf2424e0e94369517d253c70467:/src/catalogue/tests/test_tags.py diff --git a/src/catalogue/tests/test_tags.py b/src/catalogue/tests/test_tags.py index d5aa72c49..92845e228 100644 --- a/src/catalogue/tests/test_tags.py +++ b/src/catalogue/tests/test_tags.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # @@ -29,7 +28,7 @@ class BooksByTagTests(WLTestCase): parts=[self.child_info.url], **info_args("Parent")) - self.book_file = ContentFile('') + self.book_file = ContentFile(b'') def test_nonexistent_tag(self): """ Looking for a non-existent tag should yield 404 """ @@ -78,15 +77,15 @@ class TagRelatedTagsTests(WLTestCase): author = PersonStub(("Common",), "Man") gchild_info = BookInfoStub(author=author, genre="GchildGenre", epoch='Epoch', kind="Kind", - **info_args(u"GChild")) + **info_args("GChild")) child1_info = BookInfoStub(author=author, genre="ChildGenre", epoch='Epoch', kind="ChildKind", parts=[gchild_info.url], - **info_args(u"Child1")) + **info_args("Child1")) child2_info = BookInfoStub(author=author, genre="ChildGenre", epoch='Epoch', kind="ChildKind", - **info_args(u"Child2")) + **info_args("Child2")) parent_info = BookInfoStub(author=author, genre="Genre", epoch='Epoch', kind="Kind", parts=[child1_info.url, child2_info.url], - **info_args(u"Parent")) + **info_args("Parent")) for info in gchild_info, child1_info, child2_info, parent_info: book_text = """ @@ -95,8 +94,11 @@ class TagRelatedTagsTests(WLTestCase): Ala ma kota - """ % info.title.encode('utf-8') - book = models.Book.from_text_and_meta(ContentFile(book_text), info) + """ % info.title + book = models.Book.from_text_and_meta( + ContentFile(book_text.encode('utf-8')), + info + ) book.save() tag_empty = models.Tag(name='Empty tag', slug='empty', category='author') @@ -157,7 +159,7 @@ class TagRelatedTagsTests(WLTestCase): self.assertTrue( ('ChildKind', 2) in [(tag.name, tag.count) for tag in cats['kind']], 'wrong related kind tags on tag page, got: ' + - unicode([(tag.name, tag.count) for tag in cats['kind']])) + str([(tag.name, tag.count) for tag in cats['kind']])) # all occurencies of theme should be counted self.assertTrue(('Theme', 4) in [(tag.name, tag.count) for tag in cats['theme']], @@ -171,7 +173,7 @@ class TagRelatedTagsTests(WLTestCase): cats = self.client.get('/katalog/gatunek/childgenre/').context['categories'] self.assertTrue(('Epoch', 2) in [(tag.name, tag.count) for tag in cats['epoch']], 'wrong related kind tags on tag page, got: ' + - unicode([(tag.name, tag.count) for tag in cats['epoch']])) + str([(tag.name, tag.count) for tag in cats['epoch']])) class CleanTagRelationTests(WLTestCase): @@ -181,13 +183,15 @@ class CleanTagRelationTests(WLTestCase): WLTestCase.setUp(self) author = PersonStub(("Common",), "Man") - book_info = BookInfoStub(author=author, genre="G", epoch='E', kind="K", **info_args(u"Book")) + book_info = BookInfoStub(author=author, genre="G", epoch='E', kind="K", **info_args("Book")) book_text = """ ThemeAla ma kota """ - self.book = models.Book.from_text_and_meta(ContentFile(book_text), book_info) + self.book = models.Book.from_text_and_meta( + ContentFile(book_text.encode('utf-8')), + book_info) @skip('Not implemented and not priority') def test_delete_objects(self): @@ -216,7 +220,7 @@ class TestIdenticalTag(WLTestCase): WLTestCase.setUp(self) author = PersonStub((), "Tag") - self.book_info = BookInfoStub(author=author, genre="tag", epoch='tag', kind="tag", **info_args(u"tag")) + self.book_info = BookInfoStub(author=author, genre="tag", epoch='tag', kind="tag", **info_args("tag")) self.book_text = """ @@ -228,7 +232,9 @@ class TestIdenticalTag(WLTestCase): def test_book_tags(self): """ there should be all related tags in relevant categories """ - book = models.Book.from_text_and_meta(ContentFile(self.book_text), self.book_info) + book = models.Book.from_text_and_meta( + ContentFile(self.book_text.encode('utf-8')), + self.book_info) related_themes = book.related_themes() for category in 'author', 'kind', 'genre', 'epoch': @@ -237,9 +243,11 @@ class TestIdenticalTag(WLTestCase): self.assertTrue('tag' in [tag.slug for tag in related_themes]) def test_qualified_url(self): - models.Book.from_text_and_meta(ContentFile(self.book_text), self.book_info) + models.Book.from_text_and_meta( + ContentFile(self.book_text.encode('utf-8')), + self.book_info) categories = {'author': 'autor', 'theme': 'motyw', 'epoch': 'epoka', 'kind': 'rodzaj', 'genre': 'gatunek'} - for cat, localcat in categories.iteritems(): + for cat, localcat in categories.items(): context = self.client.get('/katalog/%s/tag/' % localcat).context self.assertEqual(1, len(context['object_list'])) self.assertNotEqual({}, context['categories']) @@ -255,10 +263,10 @@ class BookTagsTests(WLTestCase): author2 = PersonStub(("Jim",), "Lazy") child_info = BookInfoStub(authors=(author1, author2), genre="ChildGenre", epoch='Epoch', kind="ChildKind", - **info_args(u"Child")) + **info_args("Child")) parent_info = BookInfoStub(author=author1, genre="Genre", epoch='Epoch', kind="Kind", parts=[child_info.url], - **info_args(u"Parent")) + **info_args("Parent")) for info in child_info, parent_info: book_text = """ @@ -267,8 +275,10 @@ class BookTagsTests(WLTestCase): Ala ma kota - """ % info.title.encode('utf-8') - models.Book.from_text_and_meta(ContentFile(book_text), info) + """ % info.title + models.Book.from_text_and_meta( + ContentFile(book_text.encode('utf-8')), + info) def test_book_tags(self): """ book should have own tags and whole tree's themes """