forked from celery/django-celery
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes loader so DB connection is not closed for eager tasks.
Closes celery#116.
- Loading branch information
Showing
4 changed files
with
41 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
from django.db import models # noqa | ||
|
||
# Create your models here. | ||
|
||
class Thing(models.Model): | ||
name = models.CharField(max_length=10) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,15 @@ | ||
from celery.task import task | ||
|
||
from django.db.models import get_model | ||
|
||
|
||
@task(name="c.unittest.SomeAppTask") | ||
def SomeAppTask(**kwargs): | ||
return 42 | ||
|
||
|
||
@task(name="c.unittest.SomeModelTask") | ||
def SomeModelTask(pk): | ||
model = get_model("someapp", "Thing") | ||
thing = model.objects.get(pk=pk) | ||
return thing.name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from __future__ import absolute_import | ||
|
||
from django.test.testcases import TestCase as DjangoTestCase | ||
|
||
from someapp.models import Thing | ||
from someapp.tasks import SomeModelTask | ||
|
||
|
||
class SimpleTest(DjangoTestCase): | ||
|
||
def setUp(self): | ||
self.thing = Thing.objects.create(name=u"Foo") | ||
|
||
def test_apply_task(self): | ||
"Apply task function." | ||
result = SomeModelTask.apply(kwargs={'pk': self.thing.pk}) | ||
self.assertEqual(result.get(), self.thing.name) | ||
|
||
def test_task_function(self): | ||
"Run task function." | ||
result = SomeModelTask(pk=self.thing.pk) | ||
self.assertEqual(result, self.thing.name) |