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 mock.mask_modules('django'): with self.assertWarnsRegex(UserWarning, 'but Django is'): fixup(self.app) self.assertFalse(Fixup.called) with mock.module_exists('django'): fixup(self.app) self.assertTrue(Fixup.called)
def test_fixup(self): with patch('celery.fixups.django.DjangoFixup') as Fixup: with patch.dict(os.environ, DJANGO_SETTINGS_MODULE=''): fixup(self.app) Fixup.assert_not_called() with patch.dict(os.environ, DJANGO_SETTINGS_MODULE='settings'): with mock.mask_modules('django'): with self.assertWarnsRegex(UserWarning, 'but Django is'): fixup(self.app) Fixup.assert_not_called() with mock.module_exists('django'): fixup(self.app) Fixup.assert_called()
def test_oracle_errors(self): with mock.module_exists('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 mock.mask_modules('cx_Oracle'): with self.fixup_context(self.app): pass