Always attempt to build HTML and fix_tree_tags when publishing a book. Also, some...
authorRadek Czajka <radekczajka@nowoczesnapolska.org.pl>
Thu, 4 Sep 2014 13:14:42 +0000 (15:14 +0200)
committerRadek Czajka <radekczajka@nowoczesnapolska.org.pl>
Thu, 4 Sep 2014 13:14:42 +0000 (15:14 +0200)
apps/api/tests.py
apps/catalogue/fields.py
apps/catalogue/models/book.py
apps/opds/tests/__init__.py
apps/picture/tests/picture_import.py
apps/search/tests/index.py

index 0a638dc..87c4f75 100644 (file)
@@ -17,6 +17,7 @@ import picture.tests
 
 @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'}}
index ebf71c2..89b76ee 100644 (file)
@@ -134,22 +134,23 @@ class BuildHtml(BuildEbook):
 
         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(**{
@@ -209,6 +210,7 @@ class BuildHtml(BuildEbook):
             book.fix_tree_tags()
             book.html_built.send(sender=book)
             return True
+        book.fix_tree_tags()
         return False
 
 @BuildEbook.register('cover_thumb')
index 1ab2c42..c91ce11 100644 (file)
@@ -330,8 +330,8 @@ class Book(models.Model):
             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()
index 8d51b7b..ea72f06 100755 (executable)
@@ -2,7 +2,9 @@
 # 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,
@@ -14,6 +16,8 @@ from search import Index, Search
 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):
@@ -22,11 +26,10 @@ class OpdsSearchTests(WLTestCase):
         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."""
index 84009e6..1b01d33 100644 (file)
@@ -14,8 +14,15 @@ class PictureTest(WLTestCase):
     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()
 
@@ -27,10 +34,10 @@ class PictureTest(WLTestCase):
 
 
     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
 
index d244a2c..fc2da1e 100644 (file)
@@ -2,6 +2,7 @@
 # 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
@@ -16,6 +17,8 @@ import opds
 @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)
@@ -25,11 +28,10 @@ class BookSearchTests(WLTestCase):
         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"))