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
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)
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)
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