# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
from django.core.files.base import ContentFile
from django.test import Client
from catalogue import models
from django.core.files.base import ContentFile
from django.test import Client
from catalogue import models
""" empty tag should have no related tags """
cats = self.client.get('/katalog/autor/empty/').context['categories']
""" empty tag should have no related tags """
cats = self.client.get('/katalog/autor/empty/').context['categories']
- self.assertEqual({k: v for (k, v) in cats.items() if v}, {},
- 'tags related to empty tag')
+ self.assertEqual({k: v for (k, v) in cats.items() if v}, {}, 'tags related to empty tag')
self.assertTrue('Epoch' in [tag.name for tag in cats['epoch']],
'missing `epoch` related tag')
self.assertFalse(cats.get("kind", False),
self.assertTrue('Epoch' in [tag.name for tag in cats['epoch']],
'missing `epoch` related tag')
self.assertFalse(cats.get("kind", False),
self.assertTrue("Genre" in [tag.name for tag in cats['genre']],
'missing `genre` related tag')
self.assertFalse("ChildGenre" in [tag.name for tag in cats['genre']],
self.assertTrue("Genre" in [tag.name for tag in cats['genre']],
'missing `genre` related tag')
self.assertFalse("ChildGenre" in [tag.name for tag in cats['genre']],
self.assertTrue("GchildGenre" in [tag.name for tag in cats['genre']],
"missing grandchild's related tag")
self.assertTrue('Theme' in [tag.name for tag in cats['theme']],
"missing related theme")
self.assertFalse('Child1Theme' in [tag.name for tag in cats['theme']],
self.assertTrue("GchildGenre" in [tag.name for tag in cats['genre']],
"missing grandchild's related tag")
self.assertTrue('Theme' in [tag.name for tag in cats['theme']],
"missing related theme")
self.assertFalse('Child1Theme' in [tag.name for tag in cats['theme']],
self.assertTrue('GChildTheme' in [tag.name for tag in cats['theme']],
"missing grandchild's related theme")
self.assertTrue('GChildTheme' in [tag.name for tag in cats['theme']],
"missing grandchild's related theme")
def test_siblings_tags_count(self):
""" if children have tags and parent hasn't, count the children """
cats = self.client.get('/katalog/epoka/epoch/').context['categories']
def test_siblings_tags_count(self):
""" if children have tags and parent hasn't, count the children """
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, got: ' +
- unicode([(tag.name, tag.count) for tag in cats['kind']]))
+ 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']]))
# all occurencies of theme should be counted
self.assertTrue(('Theme', 4) in [(tag.name, tag.count) for tag in cats['theme']],
# all occurencies of theme should be counted
self.assertTrue(('Theme', 4) in [(tag.name, tag.count) for tag in cats['theme']],
"""
cats = self.client.get('/katalog/gatunek/childgenre/').context['categories']
self.assertTrue(('Epoch', 2) in [(tag.name, tag.count) for tag in cats['epoch']],
"""
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']]))
+ 'wrong related kind tags on tag page, got: ' +
+ unicode([(tag.name, tag.count) for tag in cats['epoch']]))
- 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(u"Book"))
def test_delete_objects(self):
""" there should be no related tags left after deleting some objects """
def test_delete_objects(self):
""" there should be no related tags left after deleting some objects """
- 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(u"tag"))
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)
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)
def test_qualified_url(self):
models.Book.from_text_and_meta(ContentFile(self.book_text), self.book_info)
def test_qualified_url(self):
models.Book.from_text_and_meta(ContentFile(self.book_text), self.book_info)
- categories = {'author': 'autor', 'theme': 'motyw', 'epoch': 'epoka', 'kind':'rodzaj', 'genre':'gatunek'}
+ categories = {'author': 'autor', 'theme': 'motyw', 'epoch': 'epoka', 'kind': 'rodzaj', 'genre': 'gatunek'}
for cat, localcat in categories.iteritems():
context = self.client.get('/katalog/%s/tag/' % localcat).context
self.assertEqual(1, len(context['object_list']))
for cat, localcat in categories.iteritems():
context = self.client.get('/katalog/%s/tag/' % localcat).context
self.assertEqual(1, len(context['object_list']))
author2 = PersonStub(("Jim",), "Lazy")
child_info = BookInfoStub(authors=(author1, author2), genre="ChildGenre", epoch='Epoch', kind="ChildKind",
author2 = PersonStub(("Jim",), "Lazy")
child_info = BookInfoStub(authors=(author1, author2), genre="ChildGenre", epoch='Epoch', kind="ChildKind",
parent_info = BookInfoStub(author=author1, genre="Genre", epoch='Epoch', kind="Kind",
parts=[child_info.url],
**info_args(u"Parent"))
parent_info = BookInfoStub(author=author1, genre="Genre", epoch='Epoch', kind="Kind",
parts=[child_info.url],
**info_args(u"Parent"))