-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
133 additions
and
78 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
language: python | ||
dist: xenial | ||
python: | ||
- "3.5" | ||
- "3.6" | ||
- "3.7" | ||
- "3.8" | ||
|
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
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,4 +1,4 @@ | ||
""" | ||
Declare our current version string | ||
""" | ||
__version__ = '0.20.0' | ||
__version__ = '0.21.0' |
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,27 +1,24 @@ | ||
from __future__ import absolute_import | ||
|
||
import os | ||
import sys | ||
|
||
from opal.core import commandline | ||
from celery import Celery | ||
|
||
# set the default Django settings module for the 'celery' program. | ||
# os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'proj.settings') | ||
|
||
from django.conf import settings # noqa | ||
def set_up(): | ||
if 'runtests.py' not in sys.argv: | ||
if 'DJANGO_SETTINGS_MODULE' not in os.environ: | ||
app_name = commandline.find_application_name() | ||
settings_location = f"{app_name}.settings" | ||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', settings_location) | ||
app = Celery('opal') | ||
app.config_from_object('django.conf:settings', namespace='CELERY') | ||
app.autodiscover_tasks() | ||
return app | ||
|
||
app = Celery('proj') | ||
|
||
# Using a string here means the worker will not have to | ||
# pickle the object when using Windows. | ||
app.config_from_object('django.conf:settings') | ||
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS) | ||
app = set_up() | ||
|
||
|
||
@app.task(bind=True) | ||
def debug_task(self): | ||
sys.stdout.write('Request: {0!r}\n'.format(self.request)) | ||
|
||
|
||
app.conf.update( | ||
CELERY_RESULT_BACKEND='djcelery.backends.database:DatabaseBackend', | ||
) |
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
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
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
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
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,14 +1,47 @@ | ||
""" | ||
Unittests for opal.core.celery | ||
""" | ||
from unittest.mock import patch, MagicMock | ||
|
||
from unittest.mock import patch | ||
from opal.core.test import OpalTestCase | ||
|
||
from opal.core import celery | ||
|
||
|
||
class DebugTaskTestCase(OpalTestCase): | ||
def test_debug_task(self): | ||
def test_with_runtests(self): | ||
with patch.object(celery.sys, 'stdout') as mock_stdout: | ||
celery.debug_task() | ||
mock_stdout.write.assert_called_with('Request: <Context: {}>\n') | ||
mock_stdout.write.assert_called_with("Request: <Context: {'args': (), 'kwargs': {}}>\n") | ||
|
||
@patch("opal.core.celery.sys") | ||
@patch("opal.core.celery.Celery") | ||
@patch("opal.core.celery.os") | ||
def test_with_settings_module(self, os, Celery, sys): | ||
sys.argv = [] | ||
os.environ = {'DJANGO_SETTINGS_MODULE': 'already_set'} | ||
celery.set_up() | ||
Celery.assert_called_once_with('opal') | ||
app = Celery.return_value | ||
app.config_from_object.assert_called_once_with( | ||
'django.conf:settings', namespace='CELERY' | ||
) | ||
app.autodiscover_tasks.assert_called_once_with() | ||
|
||
@patch("opal.core.celery.sys") | ||
@patch("opal.core.celery.Celery") | ||
@patch("opal.core.celery.os") | ||
@patch("opal.core.celery.commandline") | ||
def test_without_settings_module(self, commandline, os, Celery, sys): | ||
sys.argv = [] | ||
os.environ = {} | ||
commandline.find_application_name.return_value = "my_fake_app" | ||
celery.set_up() | ||
Celery.assert_called_once_with('opal') | ||
app = Celery.return_value | ||
app.config_from_object.assert_called_once_with( | ||
'django.conf:settings', namespace='CELERY' | ||
) | ||
app.autodiscover_tasks.assert_called_once_with() | ||
self.assertEqual( | ||
os.environ, {"DJANGO_SETTINGS_MODULE": "my_fake_app.settings"} | ||
) |
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
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
Oops, something went wrong.