示例#1
0
 def test_no_implementations(self):
     with mask_modules('pylibmc', 'memcache'):
         with reset_modules('celery.backends.cache'):
             from celery.backends import cache
             cache._imp = [None]
             with self.assertRaises(ImproperlyConfigured):
                 cache.get_best_memcache()
示例#2
0
 def test_no_implementations(self):
     with mask_modules('pylibmc', 'memcache'):
         with reset_modules('celery.backends.cache'):
             from celery.backends import cache
             cache._imp = [None]
             with self.assertRaises(ImproperlyConfigured):
                 cache.get_best_memcache()
示例#3
0
 def test_memcache(self):
     with self.mock_memcache():
         with reset_modules('celery.backends.cache'):
             with mask_modules('pylibmc'):
                 from celery.backends import cache
                 cache._imp = [None]
                 self.assertEqual(cache.get_best_memcache()[0]().__module__,
                                  'memcache')
示例#4
0
 def test_memcache(self):
     with self.mock_memcache():
         with reset_modules('celery.backends.cache'):
             with mask_modules('pylibmc'):
                 from celery.backends import cache
                 cache._imp = [None]
                 self.assertEqual(cache.get_best_memcache()[0]().__module__,
                                  'memcache')
示例#5
0
 def test_no_cpickle(self):
     prev = sys.modules.pop('celery.utils.serialization', None)
     try:
         with mask_modules('cPickle'):
             from celery.utils.serialization import pickle
             import pickle as orig_pickle
             self.assertIs(pickle.dumps, orig_pickle.dumps)
     finally:
         sys.modules['celery.utils.serialization'] = prev
示例#6
0
 def test_no_cpickle(self):
     prev = sys.modules.pop('celery.utils.serialization', None)
     try:
         with mask_modules('cPickle'):
             from celery.utils.serialization import pickle
             import pickle as orig_pickle
             self.assertIs(pickle.dumps, orig_pickle.dumps)
     finally:
         sys.modules['celery.utils.serialization'] = prev
示例#7
0
 def test_memcache_bytes_key(self):
     with self.mock_memcache():
         with reset_modules('celery.backends.cache'):
             with mask_modules('pylibmc'):
                 from celery.backends import cache
                 cache._imp = [None]
                 task_id, result = str_to_bytes(uuid()), 42
                 b = cache.CacheBackend(backend='memcache', app=self.app)
                 b.store_result(task_id, result, state=states.SUCCESS)
                 self.assertEqual(b.get_result(task_id), result)
示例#8
0
 def test_memcache_bytes_key(self):
     with self.mock_memcache():
         with reset_modules('celery.backends.cache'):
             with mask_modules('pylibmc'):
                 from celery.backends import cache
                 cache._imp = [None]
                 task_id, result = str_to_bytes(uuid()), 42
                 b = cache.CacheBackend(backend='memcache', app=self.app)
                 b.store_result(task_id, result, status=states.SUCCESS)
                 self.assertEqual(b.get_result(task_id), result)
示例#9
0
    def test_memcache_unicode_key(self):
        with self.mock_memcache():
            with reset_modules("celery.backends.cache"):
                with mask_modules("pylibmc"):
                    from celery.backends import cache

                    cache._imp = [None]
                    task_id, result = string(uuid()), 42
                    b = cache.CacheBackend(backend="memcache", app=self.app)
                    b.store_result(task_id, result, status=states.SUCCESS)
                    self.assertEqual(b.get_result(task_id), result)
示例#10
0
 def test_oracle_errors(self):
     with patch_modules('cx_Oracle'):
         import cx_Oracle as mod
         mod.DatabaseError = Mock()
         mod.InterfaceError = Mock()
         mod.OperationalError = Mock()
         with self.fixup_context(self.app) as (f, _, _):
             self.assertIn(mod.DatabaseError, f.database_errors)
             self.assertIn(mod.InterfaceError, f.database_errors)
             self.assertIn(mod.OperationalError, f.database_errors)
     with mask_modules('cx_Oracle'):
         with self.fixup_context(self.app):
             pass
示例#11
0
 def test_oracle_errors(self):
     with patch_modules('cx_Oracle'):
         import cx_Oracle as mod
         mod.DatabaseError = Mock()
         mod.InterfaceError = Mock()
         mod.OperationalError = Mock()
         with self.fixup_context(self.app) as (f, _, _):
             self.assertIn(mod.DatabaseError, f.database_errors)
             self.assertIn(mod.InterfaceError, f.database_errors)
             self.assertIn(mod.OperationalError, f.database_errors)
     with mask_modules('cx_Oracle'):
         with self.fixup_context(self.app):
             pass
示例#12
0
 def test_fixup(self):
     with patch('celery.fixups.django.DjangoFixup') as Fixup:
         with patch.dict(os.environ, DJANGO_SETTINGS_MODULE=''):
             fixup(self.app)
             self.assertFalse(Fixup.called)
         with patch.dict(os.environ, DJANGO_SETTINGS_MODULE='settings'):
             with mask_modules('django'):
                 with self.assertWarnsRegex(UserWarning, 'but Django is'):
                     fixup(self.app)
                     self.assertFalse(Fixup.called)
             with patch_modules('django'):
                 fixup(self.app)
                 self.assertTrue(Fixup.called)
示例#13
0
 def test_fixup(self):
     with patch('celery.fixups.django.DjangoFixup') as Fixup:
         with patch.dict(os.environ, DJANGO_SETTINGS_MODULE=''):
             fixup(self.app)
             self.assertFalse(Fixup.called)
         with patch.dict(os.environ, DJANGO_SETTINGS_MODULE='settings'):
             with mask_modules('django'):
                 with self.assertWarnsRegex(UserWarning, 'but Django is'):
                     fixup(self.app)
                     self.assertFalse(Fixup.called)
             with patch_modules('django'):
                 fixup(self.app)
                 self.assertTrue(Fixup.called)
示例#14
0
 def test_fixup(self):
     with patch("celery.fixups.django.DjangoFixup") as Fixup:
         with patch.dict(os.environ, DJANGO_SETTINGS_MODULE=""):
             fixup(self.app)
             self.assertFalse(Fixup.called)
         with patch.dict(os.environ, DJANGO_SETTINGS_MODULE="settings"):
             with mask_modules("django"):
                 with self.assertWarnsRegex(UserWarning, "but Django is"):
                     fixup(self.app)
                     self.assertFalse(Fixup.called)
             with patch_modules("django"):
                 fixup(self.app)
                 self.assertTrue(Fixup.called)
示例#15
0
    def test_pg_errors(self):
        with patch_modules("psycopg2"):
            import psycopg2 as mod

            mod.DatabaseError = Mock()
            mod.InterfaceError = Mock()
            mod.OperationalError = Mock()
            with self.fixup_context(self.app) as (f, _, _):
                self.assertIn(mod.DatabaseError, f.database_errors)
                self.assertIn(mod.InterfaceError, f.database_errors)
                self.assertIn(mod.OperationalError, f.database_errors)
        with mask_modules("psycopg2"):
            with self.fixup_context(self.app):
                pass
示例#16
0
 def test_pool_no_multiprocessing(self):
     with mask_modules('multiprocessing.util'):
         pool = self.app.pool
         self.assertIs(pool, self.app._pool)
示例#17
0
 def test_setup_logging_subsystem_no_mputil(self):
     with restore_logging():
         with mask_modules('billiard.util'):
             self.app.log.setup_logging_subsystem()
示例#18
0
 def test_setup_logging_subsystem_no_mputil(self):
     with restore_logging():
         with mask_modules('billiard.util'):
             self.app.log.setup_logging_subsystem()
示例#19
0
 def test_missing_SQLAlchemy_raises_ImproperlyConfigured(self):
     with mask_modules('sqlalchemy'):
         from celery.backends.database import _sqlalchemy_installed
         with self.assertRaises(ImproperlyConfigured):
             _sqlalchemy_installed()
示例#20
0
    def test_without_threadpool(self):

        with mask_modules('threadpool'):
            with self.assertRaises(ImportError):
                TaskPool()
示例#21
0
    def test_without_threadpool(self):

        with mask_modules('threadpool'):
            with self.assertRaises(ImportError):
                TaskPool(app=self.app)
示例#22
0
 def test_pool_no_multiprocessing(self):
     with mask_modules('multiprocessing.util'):
         pool = self.app.pool
         self.assertIs(pool, self.app._pool)
示例#23
0
 def test_setup_logging_subsystem_no_mputil(self):
     from celery.utils import log as logtools
     with restore_logging():
         with mask_modules('billiard.util'):
             self.app.log.setup_logging_subsystem()
示例#24
0
 def test_missing_SQLAlchemy_raises_ImproperlyConfigured(self):
     with mask_modules('sqlalchemy'):
         from celery.backends.database import _sqlalchemy_installed
         with self.assertRaises(ImproperlyConfigured):
             _sqlalchemy_installed()