File: test_discovery.py

package info (click to toggle)
django-celery 3.1.16-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 784 kB
  • ctags: 933
  • sloc: python: 4,082; makefile: 92; sh: 62
file content (45 lines) | stat: -rw-r--r-- 1,531 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from __future__ import absolute_import, unicode_literals

import warnings

import django
from django.conf import settings

from celery.registry import tasks

from djcelery.loaders import autodiscover
from djcelery.tests.utils import unittest


class TestDiscovery(unittest.TestCase):

    def assertDiscovery(self):
        apps = autodiscover()
        self.assertTrue(apps)
        self.assertIn('c.unittest.SomeAppTask', tasks)
        self.assertEqual(tasks['c.unittest.SomeAppTask'].run(), 42)

    def test_discovery(self):
        if 'someapp' in settings.INSTALLED_APPS:
            self.assertDiscovery()

    def test_discovery_with_broken(self):
        warnings.resetwarnings()
        if 'someapp' in settings.INSTALLED_APPS:
            if django.VERSION < (1, 7):
                # Django < 1.7
                installed_apps = list(settings.INSTALLED_APPS)
                settings.INSTALLED_APPS = installed_apps + ['xxxnot.aexist']
                try:
                    # we should get a warning when loading xxxnot.aexist
                    with warnings.catch_warnings(record=True) as log:
                        autodiscover()
                        self.assertTrue(log)
                finally:
                    settings.INSTALLED_APPS = installed_apps
            else:
                # Django 1.7
                with warnings.catch_warnings(record=True) as log:
                    # we should not get any warnings
                    autodiscover()
                    self.assertEqual(log, [])