|
1 | 1 | """
|
2 | 2 | Unittests for opal.core.celery
|
3 | 3 | """
|
4 |
| -from unittest.mock import patch, MagicMock |
5 |
| - |
| 4 | +from unittest.mock import patch |
6 | 5 | from opal.core.test import OpalTestCase
|
7 | 6 |
|
8 | 7 | from opal.core import celery
|
9 | 8 |
|
| 9 | + |
10 | 10 | class DebugTaskTestCase(OpalTestCase):
|
11 |
| - def test_debug_task(self): |
| 11 | + def test_with_runtests(self): |
12 | 12 | with patch.object(celery.sys, 'stdout') as mock_stdout:
|
13 | 13 | celery.debug_task()
|
14 |
| - mock_stdout.write.assert_called_with('Request: <Context: {}>\n') |
| 14 | + mock_stdout.write.assert_called_with("Request: <Context: {'args': (), 'kwargs': {}}>\n") |
| 15 | + |
| 16 | + @patch("opal.core.celery.sys") |
| 17 | + @patch("opal.core.celery.Celery") |
| 18 | + @patch("opal.core.celery.os") |
| 19 | + def test_with_settings_module(self, os, Celery, sys): |
| 20 | + sys.argv = [] |
| 21 | + os.environ = {'DJANGO_SETTINGS_MODULE': 'already_set'} |
| 22 | + celery.set_up() |
| 23 | + Celery.assert_called_once_with('opal') |
| 24 | + app = Celery.return_value |
| 25 | + app.config_from_object.assert_called_once_with( |
| 26 | + 'django.conf:settings', namespace='CELERY' |
| 27 | + ) |
| 28 | + app.autodiscover_tasks.assert_called_once_with() |
| 29 | + |
| 30 | + @patch("opal.core.celery.sys") |
| 31 | + @patch("opal.core.celery.Celery") |
| 32 | + @patch("opal.core.celery.os") |
| 33 | + @patch("opal.core.celery.commandline") |
| 34 | + def test_without_settings_module(self, commandline, os, Celery, sys): |
| 35 | + sys.argv = [] |
| 36 | + os.environ = {} |
| 37 | + commandline.find_application_name.return_value = "my_fake_app" |
| 38 | + celery.set_up() |
| 39 | + Celery.assert_called_once_with('opal') |
| 40 | + app = Celery.return_value |
| 41 | + app.config_from_object.assert_called_once_with( |
| 42 | + 'django.conf:settings', namespace='CELERY' |
| 43 | + ) |
| 44 | + app.autodiscover_tasks.assert_called_once_with() |
| 45 | + self.assertEqual( |
| 46 | + os.environ, {"DJANGO_SETTINGS_MODULE": "my_fake_app.settings"} |
| 47 | + ) |
0 commit comments