# -*- coding: utf-8 -*-
+from django.core.files.base import ContentFile
+from django.test import Client
from catalogue import models
from catalogue.test_utils import *
-from django.core.files.base import ContentFile
-
-from nose.tools import raises
class BooksByTagTests(WLTestCase):
- """ tests the /katalog/tag page for found books """
+ """ tests the /katalog/category/tag page for found books """
def setUp(self):
WLTestCase.setUp(self)
def test_nonexistent_tag(self):
""" Looking for a non-existent tag should yield 404 """
# NOTE: this yields a false positive, 'cause of URL change
- self.assertEqual(404, self.client.get('/katalog/czeslaw_milosz/').status_code)
+ self.assertEqual(404, self.client.get('/katalog/autor/czeslaw_milosz/').status_code)
def test_book_tag(self):
""" Looking for a book tag isn't permitted """
models.Book.from_text_and_meta(self.book_file, self.gchild_info)
models.Tag.objects.create(name='Empty tag', slug='empty', category='author')
- context = self.client.get('/katalog/empty/').context
+ context = self.client.get('/katalog/autor/empty/').context
self.assertEqual(0, len(context['object_list']))
def test_tag_eliminate(self):
models.Book.from_text_and_meta(self.book_file, info)
# all three qualify
- context = self.client.get('/katalog/genre/').context
+ context = self.client.get('/katalog/gatunek/genre/').context
self.assertEqual([book.title for book in context['object_list']],
['Parent'])
# parent and gchild qualify, child doesn't
- context = self.client.get('/katalog/kind/').context
+ context = self.client.get('/katalog/rodzaj/kind/').context
self.assertEqual([book.title for book in context['object_list']],
['Parent'])
# Filtering by child's tag should yield the child
- context = self.client.get('/katalog/other-kind/').context
+ context = self.client.get('/katalog/rodzaj/other-kind/').context
self.assertEqual([book.title for book in context['object_list']],
['Child'])
-
class TagRelatedTagsTests(WLTestCase):
- """ tests the /katalog/tag/ page for related tags """
+ """ tests the /katalog/category/tag/ page for related tags """
def setUp(self):
WLTestCase.setUp(self)
+ self.client = Client()
author = PersonStub(("Common",), "Man")
gchild_info = BookInfoStub(author=author, genre="GchildGenre", epoch='Epoch', kind="Kind",
def test_empty(self):
""" empty tag should have no related tags """
- cats = self.client.get('/katalog/empty/').context['categories']
+ cats = self.client.get('/katalog/autor/empty/').context['categories']
self.assertEqual(cats, {}, 'tags related to empty tag')
def test_has_related(self):
""" related own and descendants' tags should be generated """
- cats = self.client.get('/katalog/kind/').context['categories']
+ cats = self.client.get('/katalog/rodzaj/kind/').context['categories']
self.assertTrue('Common Man' in [tag.name for tag in cats['author']],
'missing `author` related tag')
self.assertTrue('Epoch' in [tag.name for tag in cats['epoch']],
def test_related_differ(self):
""" related tags shouldn't include filtering tags """
- cats = self.client.get('/katalog/kind/').context['categories']
+ response = self.client.get('/katalog/rodzaj/kind/')
+ cats = response.context['categories']
self.assertFalse('Kind' in [tag.name for tag in cats['kind']],
'filtering tag wrongly included in related')
- cats = self.client.get('/katalog/theme/').context['categories']
+ cats = self.client.get('/katalog/motyw/theme/').context['categories']
self.assertFalse('Theme' in [tag.name for tag in cats['theme']],
'filtering theme wrongly included in related')
-
def test_parent_tag_once(self):
""" if parent and descendants have a common tag, count it only once """
- cats = self.client.get('/katalog/kind/').context['categories']
+ cats = self.client.get('/katalog/rodzaj/kind/').context['categories']
self.assertEqual([(tag.name, tag.count) for tag in cats['epoch']],
[('Epoch', 1)],
'wrong related tag epoch tag on tag page')
def test_siblings_tags_count(self):
""" if children have tags and parent hasn't, count the children """
- cats = self.client.get('/katalog/epoch/').context['categories']
+ cats = self.client.get('/katalog/epoka/epoch/').context['categories']
self.assertTrue(('ChildKind', 2) in [(tag.name, tag.count) for tag in cats['kind']],
'wrong related kind tags on tag page')
<end id="m01" />
</akap></opowiadanie></utwor>
"""
- book = models.Book.from_text_and_meta(ContentFile(book_text), book_info)
+ self.book = models.Book.from_text_and_meta(ContentFile(book_text), book_info)
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']
+ cats = self.client.get('/katalog/rodzaj/k/').context['categories']
self.assertEqual(cats, {})
self.assertEqual(models.Fragment.objects.all().count(), 0,
"orphaned fragments left")
""" 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, {})
+ self.assertEqual(len(self.book.related_info()['tags']), 0)
+ self.assertEqual(len(self.book.related_themes()), 0)
self.assertEqual(models.Tag.intermediary_table_model.objects.all().count(), 0,
"orphaned TagRelation objects left")
def test_book_tags(self):
""" there should be all related tags in relevant categories """
- models.Book.from_text_and_meta(ContentFile(self.book_text), self.book_info)
+ book = models.Book.from_text_and_meta(ContentFile(self.book_text), self.book_info)
- context = self.client.get('/katalog/lektura/tag/').context
+ related_info = book.related_info()
+ related_themes = book.related_themes()
for category in 'author', 'kind', 'genre', 'epoch':
- self.assertTrue('tag' in [tag.slug for tag in context['categories'][category]],
+ self.assertTrue('tag' in [tag[1] for tag in related_info['tags'][category]],
'missing related tag for %s' % category)
- self.assertTrue('tag' in [tag.slug for tag in context['book_themes']])
+ 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)
<end id="m01" />
</akap></opowiadanie></utwor>
""" % info.title.encode('utf-8')
- book = models.Book.from_text_and_meta(ContentFile(book_text), info)
+ 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 """
- context = self.client.get('/katalog/lektura/parent/').context
+ book = models.Book.objects.get(slug='parent')
+ related_info = book.related_info()
+ related_themes = book.related_themes()
- self.assertEqual([tag.name for tag in context['categories']['author']],
- ['Common Man'])
- self.assertEqual([tag.name for tag in context['categories']['kind']],
- ['Kind'])
- self.assertEqual([(tag.name, tag.count) for tag in context['book_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 """
-
- context = self.client.get('/katalog/').context
-
- self.assertEqual([(tag.name, tag.count) for tag in context['categories']['author']],
+ 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.count) for tag in context['fragment_tags']],
+ self.assertEqual([(tag.name, tag.book_count) for tag in menu['theme']],
[('ChildTheme', 1), ('ParentTheme', 1), ('Theme', 2)])