@override_settings(
API_WAIT=-1,
+ NO_SEARCH_INDEX = True,
CACHES = {'api': {'BACKEND': 'django.core.cache.backends.dummy.DummyCache'},
'default': {'BACKEND': 'django.core.cache.backends.dummy.DummyCache'},
'permanent': {'BACKEND': 'django.core.cache.backends.dummy.DummyCache'}}
book = fieldfile.instance
- meta_tags = list(book.tags.filter(
- category__in=('author', 'epoch', 'genre', 'kind')))
- book_tag = book.book_tag()
-
html_output = self.transform(
book.wldocument(parse_dublincore=False),
fieldfile)
- lang = book.language
- lang = LANGUAGES_3TO2.get(lang, lang)
- if lang not in [ln[0] for ln in settings.LANGUAGES]:
- lang = None
# Delete old fragments, create from scratch if necessary.
book.fragments.all().delete()
if html_output:
+ meta_tags = list(book.tags.filter(
+ category__in=('author', 'epoch', 'genre', 'kind')))
+ book_tag = book.book_tag()
+
+ lang = book.language
+ lang = LANGUAGES_3TO2.get(lang, lang)
+ if lang not in [ln[0] for ln in settings.LANGUAGES]:
+ lang = None
+
fieldfile.save(None, ContentFile(html_output.get_string()),
save=False)
type(book).objects.filter(pk=book.pk).update(**{
book.fix_tree_tags()
book.html_built.send(sender=book)
return True
+ book.fix_tree_tags()
return False
@BuildEbook.register('cover_thumb')
book.cover_thumb.build_delay()
# Build HTML and ebooks.
+ book.html_file.build_delay()
if not children:
- book.html_file.build_delay()
for format_ in constants.EBOOK_FORMATS_WITHOUT_CHILDREN:
if format_ not in dont_build:
getattr(book, '%s_file' % format_).build_delay()
# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
+from unittest import skipIf
from lxml import etree
+from django.conf import settings
from django.core.files.base import ContentFile
import catalogue
from catalogue.test_utils import (BookInfoStub, PersonStub, info_args,
AtomNS = XMLNamespace("http://www.w3.org/2005/Atom")
+@skipIf(getattr(settings, 'NO_SEARCH_INDEX', False),
+ u'Requires search server and NO_SEARCH_INDEX=False.')
class OpdsSearchTests(WLTestCase):
"""Tests search feed in OPDS.."""
def setUp(self):
index.index.delete_all()
index.index.commit()
- with self.settings(NO_SEARCH_INDEX=False):
- self.do_doktora = Book.from_xml_file(
- get_fixture('do-doktora.xml'))
- self.do_anusie = Book.from_xml_file(
- get_fixture('fraszka-do-anusie.xml', catalogue))
+ self.do_doktora = Book.from_xml_file(
+ get_fixture('do-doktora.xml'))
+ self.do_anusie = Book.from_xml_file(
+ get_fixture('fraszka-do-anusie.xml', catalogue))
def assert_finds(self, query, books):
"""Takes a query and tests against books expected to be found."""
def test_import(self):
picture = Picture.from_xml_file(path.join(path.dirname(__file__), "files/kandinsky-composition-viii.xml"))
- motifs = set([tag.name for tag in picture.tags if tag.category == 'theme'])
- assert motifs == set([u'nieporządek']), 'theme tags are wrong. %s' % motifs
+ themes = set()
+ for area in picture.areas.all():
+ themes.update([(tag.category, tag.name)
+ for tag in area.tags if tag.category in (u'theme', u'thing')])
+ assert themes == set([(u'theme', u'nieporządek'), (u'thing', u'kosmos')]), \
+ 'Bad themes on Picture areas: %s' % themes
+
+ pic_themes = set([tag.name for tag in picture.tags if tag.category in ('theme', 'object')])
+ assert not pic_themes, 'Unwanted themes set on Pictures: %s' % pic_themes
picture.delete()
def test_import_2(self):
- picture = Picture.from_xml_file(path.join(path.dirname(__file__), "files/pejzaz-i-miasto-krzyzanowski-chmury.xml"),
- path.join(path.dirname(__file__), "files/pejzaz-i-miasto-krzyzanowski-chmury.jpg"),
+ picture = Picture.from_xml_file(path.join(path.dirname(__file__), "files/kandinsky-composition-viii.xml"),
+ path.join(path.dirname(__file__), "files/kandinsky-composition-viii.png"),
overwrite=True)
cats = set([t.category for t in picture.tags])
- assert 'genre' in cats
+ assert 'epoch' in cats
assert 'kind' in cats
# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
+from unittest import skipIf
from django.conf import settings
from django.test.utils import override_settings
from catalogue.test_utils import WLTestCase, get_fixture
@override_settings(
SEARCH_INDEX = tempfile.mkdtemp(prefix='djangotest_search_'),
)
+@skipIf(getattr(settings, 'NO_SEARCH_INDEX', False),
+ u'Requires search server and NO_SEARCH_INDEX=False.')
class BookSearchTests(WLTestCase):
def setUp(self):
WLTestCase.setUp(self)
index.delete_query(self.search.index.query(uid="*"))
index.index.commit()
- with self.settings(NO_SEARCH_INDEX=False):
- self.do_doktora = Book.from_xml_file(
- get_fixture('do-doktora.xml', opds))
- self.do_anusie = Book.from_xml_file(
- get_fixture('fraszka-do-anusie.xml', catalogue))
+ self.do_doktora = Book.from_xml_file(
+ get_fixture('do-doktora.xml', opds))
+ self.do_anusie = Book.from_xml_file(
+ get_fixture('fraszka-do-anusie.xml', catalogue))
def test_search_perfect_book_author(self):
books = self.search.search_books(self.search.index.query(authors=u"sęp szarzyński"))