Update Celery to 4.3
authorRadek Czajka <rczajka@rczajka.pl>
Mon, 5 Aug 2019 11:21:30 +0000 (13:21 +0200)
committerRadek Czajka <rczajka@rczajka.pl>
Mon, 5 Aug 2019 11:21:30 +0000 (13:21 +0200)
12 files changed:
README.md
requirements/requirements.txt
src/api/tests/res/responses/books-grandchild.json
src/api/tests/res/responses/ebooks.json
src/api/tests/tests.py
src/catalogue/fixtures/test-books.yaml
src/catalogue/models/book.py
src/catalogue/test_utils.py
src/catalogue/tests/test_book_import.py
src/wolnelektury/celery.py
src/wolnelektury/settings/apps.py
src/wolnelektury/settings/celery.py

index 45c7e4e..13c0ed2 100644 (file)
--- a/README.md
+++ b/README.md
@@ -59,26 +59,23 @@ Bundled software
 ================
 
 * django-chunks
-  in `apps/chunks`
+  in `src/chunks`
   based on [django-chunks](http://code.google.com/p/django-chunks/)
   by Clint Ecker <clintecker@gmail.com>,
   [New BSD License](http://www.opensource.org/licenses/bsd-license.php)
 * [django-newtagging](http://www.bitbucket.org/zuber/django-newtagging/)
-  in `apps/newtagging`
+  in `src/newtagging`
   by Marek Stępniowski <marek@stepniowski.com>,
   [MIT License](http://www.opensource.org/licenses/mit-license.php),
   based on [django-tagging](http://code.google.com/p/django-tagging/), also under [MIT License](http://www.opensource.org/licenses/mit-license.php)
 * [jPlayer](http://jplayer.org/)
-  in `apps/catalogue/static/jplayer`
+  in `src/catalogue/static/jplayer`
   by Happyworm,
   [MIT License](http://opensource.org/licenses/MIT)
 * [Switch template tag](http://djangosnippets.org/snippets/967/)
-  in `apps/wolnelektury_core/templatetags/switch_tag.py`
+  in `src/wolnelektury/templatetags/switch_tag.py`
   by adurdin
-* [Cropping engine for sorl-thumbnail](http://timmyomahony.com/blog/custom-cropping-engine-sorl-thumbnail/)
-  in `apps/picture/engine.py`
-  by Timmy O'Mahony
-* Javascript in `apps/wolnelektury_core/static/js/contrib`
+* Javascript in `src/wolnelektury/static/js/contrib`
   with relevant attribution and licensing
   
 
index 2f877e9..a5f0467 100644 (file)
@@ -44,8 +44,7 @@ sorl-thumbnail==12.5.0
 librarian==1.7.4
 
 # celery tasks
-celery>=3.1.12,<3.2
-kombu>=3.0.23,<3.1
+celery[redis]==4.3.0
 
 # spell checking
 pyenchant
index b7dd9da..6638317 100644 (file)
@@ -4,9 +4,9 @@
         "html": "Fragment", 
         "title": "Parent, Child"
     }, 
-    "txt": "http://testserver/katalog/pobierz/grandchild.txt",
+    "txt": "http://testserver/media/txt/grandchild.txt",
     "children": [], 
-    "xml": "http://testserver/katalog/pobierz/grandchild.xml",
+    "xml": "http://testserver/media/xml/grandchild.xml",
     "genres": [
         {
             "url": "http://testserver/katalog/gatunek/sonet/",
@@ -17,9 +17,9 @@
     ], 
     "title": "Grandchild", 
     "media": [], 
-    "html": "http://testserver/katalog/pobierz/grandchild.html",
-    "preview": true, 
-    "fb2": "http://testserver/katalog/pobierz/grandchild.fb2",
+    "html": "http://testserver/media/html/grandchild.html",
+    "preview": false, 
+    "fb2": "http://testserver/media/fb2/grandchild.fb2",
     "kinds": [], 
     "parent": {
         "kind": "", 
     "simple_cover": "", 
     "authors": [], 
     "audio_length": "", 
-    "epub": "http://testserver/katalog/pobierz/grandchild.epub",
+    "epub": "http://testserver/media/epub/grandchild.epub",
     "cover_thumb": "", 
-    "mobi": "http://testserver/katalog/pobierz/grandchild.mobi",
+    "mobi": "http://testserver/media/mobi/grandchild.mobi",
     "url": "http://testserver/katalog/lektura/grandchild/",
     "cover": "", 
-    "pdf": "http://testserver/katalog/pobierz/grandchild.pdf",
+    "pdf": "http://testserver/media/pdf/grandchild.pdf",
     "simple_thumb": ""
 }
index 719faac..d01f1fa 100644 (file)
         "epub": ""
     }, 
     {
-        "fb2": "http://testserver/katalog/pobierz/grandchild.fb2",
-        "mobi": "http://testserver/katalog/pobierz/grandchild.mobi",
+        "fb2": "http://testserver/media/fb2/grandchild.fb2",
+        "mobi": "http://testserver/media/mobi/grandchild.mobi",
         "title": "Grandchild",
         "author": "", 
         "cover": "", 
         "href": "http://testserver/api/books/grandchild/",
-        "pdf": "http://testserver/katalog/pobierz/grandchild.pdf",
-        "txt": "http://testserver/katalog/pobierz/grandchild.txt",
+        "pdf": "http://testserver/media/pdf/grandchild.pdf",
+        "txt": "http://testserver/media/txt/grandchild.txt",
         "slug": "grandchild", 
-        "epub": "http://testserver/katalog/pobierz/grandchild.epub"
+        "epub": "http://testserver/media/epub/grandchild.epub"
     }, 
     {
         "fb2": "", 
index c37fef3..993a524 100644 (file)
@@ -177,12 +177,15 @@ class BooksTests(ApiTest):
             '/api/filter-books/?lektura=true',
             [])
 
-        self.assert_slugs(
-            '/api/filter-books/?preview=true',
-            ['grandchild'])
+        Book.objects.filter(slug='grandchild').update(preview=True)
+        # Skipping: we don't allow previewed books in filtered list.
+        #self.assert_slugs(
+        #    '/api/filter-books/?preview=true',
+        #    ['grandchild'])
         self.assert_slugs(
             '/api/filter-books/?preview=false',
             ['child', 'parent'])
+        Book.objects.filter(slug='grandchild').update(preview=False)
 
         self.assert_slugs(
             '/api/filter-books/?audiobook=true',
@@ -231,11 +234,6 @@ class BlogTests(ApiTest):
         self.assertEqual(self.load_json('/api/blog'), [])
 
 
-class PreviewTests(ApiTest):
-    def unauth(self):
-        self.assert_json_response('/api/preview/', 'preview.json')
-
-
 class OAuth1Tests(ApiTest):
     @classmethod
     def setUpClass(cls):
@@ -436,6 +434,8 @@ class AuthorizedTests(ApiTest):
             ['parent'])
 
     def test_subscription(self):
+        Book.objects.filter(slug='grandchild').update(preview=True)
+
         self.assert_slugs('/api/preview/', ['grandchild'])
         self.assertEqual(
             self.signed_json('/api/username/'),
@@ -454,6 +454,8 @@ class AuthorizedTests(ApiTest):
                     self.signed('/api/epub/grandchild/').content,
                     b"<epub>")
 
+        Book.objects.filter(slug='grandchild').update(preview=False)
+
     def test_publish(self):
         response = self.signed('/api/books/',
                                method='POST',
index 42eefd7..fcb3617 100644 (file)
   fields:
     slug: grandchild
     title: Grandchild
-    preview: true
     sort_key: grandchild
     parent: 2
-    xml_file: secret/grandchild.xml
-    txt_file: secret/grandchild.txt
-    html_file: secret/grandchild.html
-    epub_file: secret/grandchild.epub
-    mobi_file: secret/grandchild.mobi
-    pdf_file: secret/grandchild.pdf
-    fb2_file: secret/grandchild.fb2
+    xml_file: xml/grandchild.xml
+    txt_file: txt/grandchild.txt
+    html_file: html/grandchild.html
+    epub_file: epub/grandchild.epub
+    mobi_file: mobi/grandchild.mobi
+    pdf_file: pdf/grandchild.pdf
+    fb2_file: fb2/grandchild.fb2
     created_at: "1970-01-01 0:0Z"
     changed_at: "1970-01-01 0:0Z"
 
index d47cb15..af4c941 100644 (file)
@@ -502,6 +502,7 @@ class Book(models.Model):
                 tag.save()
 
         book.tags = set(meta_tags + book_shelves)
+        book.save()  # update sort_key_author
 
         cover_changed = old_cover != book.cover_info()
         obsolete_children = set(b for b in book.children.all()
@@ -553,7 +554,6 @@ class Book(models.Model):
         for child in notify_cover_changed:
             child.parent_cover_changed()
 
-        book.save()  # update sort_key_author
         book.update_popularity()
         cls.published.send(sender=cls, instance=book)
         return book
index dd5647a..ad3e491 100644 (file)
@@ -16,7 +16,7 @@ from django.conf import settings
     MEDIA_ROOT=tempfile.mkdtemp(prefix='djangotest_'),
     CATALOGUE_DONT_BUILD={'pdf', 'mobi', 'epub', 'txt', 'fb2', 'cover'},
     NO_SEARCH_INDEX=True,
-    CELERY_ALWAYS_EAGER=True,
+    CELERY_TASK_ALWAYS_EAGER=True,
     CACHES={
             'default': {'BACKEND': 'django.core.cache.backends.dummy.DummyCache'},
         },
index da5e586..9fdb298 100644 (file)
@@ -36,6 +36,7 @@ class BookImportLogicTests(WLTestCase):
     def test_empty_book(self):
         book_text = "<utwor />"
         book = models.Book.from_text_and_meta(ContentFile(book_text), self.book_info)
+        book.refresh_from_db()
 
         self.assertEqual(book.title, "Default Book")
         self.assertEqual(book.slug, "default-book")
@@ -68,6 +69,7 @@ class BookImportLogicTests(WLTestCase):
         """
 
         book = models.Book.from_text_and_meta(ContentFile(book_text), self.book_info)
+        book.refresh_from_db()
         self.assertTrue(book.has_html_file())
 
     def test_book_with_fragment(self):
@@ -78,6 +80,7 @@ class BookImportLogicTests(WLTestCase):
         """
 
         book = models.Book.from_text_and_meta(ContentFile(book_text), self.book_info)
+        book.refresh_from_db()
         self.assertTrue(book.has_html_file())
 
         self.assertEqual(book.fragments.count(), 1)
index d1e18d7..23bf6dc 100644 (file)
@@ -13,5 +13,5 @@ os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'wolnelektury.settings')
 
 app = Celery('wolnelektury')
 
-app.config_from_object('django.conf:settings')
+app.config_from_object('django.conf:settings', namespace='CELERY')
 app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
index ba313f5..76ffa6f 100644 (file)
@@ -53,7 +53,6 @@ INSTALLED_APPS_CONTRIB = [
     'pipeline',
     'piwik',
     'sorl.thumbnail',
-    'kombu.transport.django',
     'honeypot',
     'fnpdjango',
     'getpaid',
index e5c265c..1552bc0 100644 (file)
@@ -1,9 +1,9 @@
-# -*- 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.
 #
-BROKER_URL = 'django://'
+CELERY_BROKER_URL = 'redis://'
 
 CELERY_EAGER_PROPAGATES_EXCEPTIONS = True
 CELERY_SEND_TASK_ERROR_EMAILS = True
 CELERY_ACCEPT_CONTENT = ['pickle']
+CELERY_TASK_SERIALIZER = 'pickle'