[Python-modules-commits] [django-celery-transactions] 01/04: Import django-celery-transactions_0.3.6.orig.tar.gz

Michael Fladischer fladi at moszumanska.debian.org
Sun Dec 6 12:58:35 UTC 2015


This is an automated email from the git hooks/post-receive script.

fladi pushed a commit to branch master
in repository django-celery-transactions.

commit 293e171125f6d7bf9178c23620d8ab28696587de
Author: Michael Fladischer <FladischerMichael at fladi.at>
Date:   Sun Dec 6 11:41:02 2015 +0100

    Import django-celery-transactions_0.3.6.orig.tar.gz
---
 AUTHORS                           |  1 +
 CHANGELOG                         | 11 ++++++++
 README.md                         |  5 ++++
 djcelery_transactions/__init__.py |  6 ++--
 setup.py                          |  2 +-
 tests/test/tests.py               | 59 ++++++++++++++++++++++++++++-----------
 6 files changed, 65 insertions(+), 19 deletions(-)

diff --git a/AUTHORS b/AUTHORS
index 40d4962..6fa7f0d 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -10,3 +10,4 @@ Jakub Paczkowski
 Tom Playford
 Nic Pottier
 Peter Sheats
+Zachary Mott
diff --git a/CHANGELOG b/CHANGELOG
index bb931db..eaf0526 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,17 @@
 Changelog
 =========
 
+0.3.6 (2015-11-15)
+------------------------
+
+- Tests shared_task. [Nicolas Grasset]
+
+- Add a replacement shared_task decorator. [Zachary B. Mott]
+
+- Update Readme.md: Django and Celery coverage. [Nicolas Grasset]
+
+  Thanks @jakob-o for pointing this out!
+
 0.3.5 (2015-10-07)
 ------------------------
 
diff --git a/README.md b/README.md
index 5ee6a7b..6bc9b8b 100644
--- a/README.md
+++ b/README.md
@@ -10,6 +10,11 @@ django-celery-transactions holds on to Celery tasks until the current database
 transaction is committed, avoiding potential race conditions as described in
 Celery's [user guide][1]. Send tasks from signal handlers without fear!
 
+## Django and Celery coverage
+
+* Django 1.6, 1.7 and 1.8 are supported and tested. 1.9 will likely require refactoring.
+* Celery 3.0.x and 3.1.x are supported, but the tests are running with 3.1.18
+
 ## Features
 
 * If the transaction is rolled back, the tasks are discarded. Django's
diff --git a/djcelery_transactions/__init__.py b/djcelery_transactions/__init__.py
index 92bf1db..dc7de13 100644
--- a/djcelery_transactions/__init__.py
+++ b/djcelery_transactions/__init__.py
@@ -3,7 +3,8 @@ from functools import partial
 import threading
 from celery import current_app
 
-from celery import task as base_task, current_app, Task
+from celery import current_app, Task
+from celery import task as base_task, shared_task as base_shared_task
 from celery.contrib.batches import Batches
 import django
 from django.conf import settings
@@ -148,8 +149,9 @@ def _send_tasks(**kwargs):
         tsk.original_apply_async(*args, **kwargs)
 
 
-# A replacement decorator.
+# Replacement decorators.
 task = partial(base_task, base=PostTransactionTask)
+shared_task = partial(base_shared_task, base=PostTransactionTask)
 
 # Hook the signal handlers up.
 transaction.signals.post_commit.connect(_send_tasks)
diff --git a/setup.py b/setup.py
index 202bae3..8302275 100644
--- a/setup.py
+++ b/setup.py
@@ -7,7 +7,7 @@ from setuptools import setup, Command, find_packages
 
 setup(
     name="django-celery-transactions",
-    version="0.3.5",
+    version="0.3.6",
     description="Django transaction support for Celery tasks.",
     long_description="See https://github.com/fellowshipofone/django-celery-transactions",
     author="Nicolas Grasset",
diff --git a/tests/test/tests.py b/tests/test/tests.py
index d84fe26..937f797 100644
--- a/tests/test/tests.py
+++ b/tests/test/tests.py
@@ -1,44 +1,64 @@
 import django, os
-from djcelery_transactions import task
-if django.VERSION < (1,8):
-    from django.test import TransactionTestCase as TestCaseForTests # commit() was disabled in TestCase prior to 1.8
+from djcelery_transactions import task, shared_task
+
+if django.VERSION < (1, 8):
+    from django.test import TransactionTestCase as TestCaseForTests  # commit() was disabled in TestCase prior to 1.8
 else:
-    from django.test import TestCase as TestCaseForTests # Django 1.8 now works just fine with TestCase
+    from django.test import TestCase as TestCaseForTests  # Django 1.8 now works just fine with TestCase
 from .models import Trees, Plants
-if django.VERSION < (1,7):
+
+if django.VERSION < (1, 7):
     from django.core.cache import cache
 else:
     from django.core.cache import caches
+
     cache = caches['default']
 
-if django.VERSION >= (1,6):
+if django.VERSION >= (1, 6):
     from django.db.transaction import atomic
 else:
     from django.db import transaction
+
     atomic = transaction.commit_on_success
 
+
 @task
 def my_task():
     cache.set('my_global', 42)
 
+
 @task
 def my_model_task():
     Plants.objects.create(name='Oak')
 
 
+ at shared_task
+def my_shared_task():
+    cache.set('my_global', 42)
+
+
 try:
     from celery.registry import tasks
+
     tasks.register(my_task)
 except:
     from celery import task as base_task, current_app, Task
+
     current_app.registry.register(my_task)
 
+
 class SpecificException(Exception):
     pass
 
+
 class DjangoCeleryTestCase(TestCaseForTests):
     """Test djcelery transaction safe task manager
     """
+
+    def setUp(self):
+        super(DjangoCeleryTestCase, self).setUp()
+        self.task = my_task
+
     def tearDown(self):
         cache.delete('my_global')
 
@@ -48,7 +68,7 @@ class DjangoCeleryTestCase(TestCaseForTests):
 
         @atomic
         def do_something():
-            my_task.delay()
+            self.task.delay()
 
         do_something()
         self.assertEqual(cache.get('my_global'), 42)
@@ -59,10 +79,9 @@ class DjangoCeleryTestCase(TestCaseForTests):
 
         @atomic
         def do_something():
-
             @atomic
             def nested_do_something():
-                my_task.delay()
+                self.task.delay()
 
             nested_do_something()
 
@@ -75,8 +94,9 @@ class DjangoCeleryTestCase(TestCaseForTests):
 
         @atomic
         def do_something():
-            my_task.delay()
+            self.task.delay()
             raise SpecificException
+
         try:
             do_something()
         except SpecificException:
@@ -90,14 +110,13 @@ class DjangoCeleryTestCase(TestCaseForTests):
         self.assertEqual(r.status_code, 200)
         self.assertEqual(cache.get('my_global'), 42)
 
-
     def test_django_db_transaction_managed(self):
         """
         Check that django.db.transaction.managed is not affected
         by monkey-patching
         """
 
-        if django.VERSION >= (1,6):
+        if django.VERSION >= (1, 6):
             self.skipTest('Django 1.6 does not need this test')
 
         from django.db import transaction
@@ -109,19 +128,18 @@ class DjangoCeleryTestCase(TestCaseForTests):
         finally:
             transaction.leave_transaction_management()
 
-
     def test_multiple_models(self):
         """Check that task is consumed when no exception happens
         """
 
-        self.assertEqual( Plants.objects.count(), 0)
+        self.assertEqual(Plants.objects.count(), 0)
 
         @atomic
         def do_something():
             my_model_task.delay()
 
         do_something()
-        self.assertEqual( Plants.objects.count(), 1)
+        self.assertEqual(Plants.objects.count(), 1)
 
         Trees.objects.create(name='Grey Oak', plant=Plants.objects.get(name='Oak'))
 
@@ -131,7 +149,7 @@ class DjangoCeleryTestCase(TestCaseForTests):
 
         @atomic
         def do_something():
-            my_task.delay()
+            self.task.delay()
             self.assertIsNone(cache.get('my_global'))
 
         @atomic
@@ -141,3 +159,12 @@ class DjangoCeleryTestCase(TestCaseForTests):
 
         do_something_outside()
         self.assertEqual(cache.get('my_global'), 42)
+
+
+class SharedTaskTestCase(DjangoCeleryTestCase):
+    """Test djcelery transaction safe task manager
+    """
+
+    def setUp(self):
+        super(SharedTaskTestCase, self).setUp()
+        self.task = my_shared_task

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/django-celery-transactions.git



More information about the Python-modules-commits mailing list