def test_autodiscover_overwrite(self): """ Test autodiscover with an overwrite of the module name """ from test_appregister.models import registry registry.autodiscover('questions2') names = [(c.__module__, c.__name__) for c in registry.all()] self.assertIn(('test_appregister.questions2', 'MyAutoDiscoveredQuestion2'), names)
def test_autodiscover_import_error(self): """ Test autodiscover with a module that raises an import error. This is to test that the ImportError isn't masked by being misinterpreted as the question_error module not existing. """ from test_appregister.models import registry with self.assertRaises(ImportError): registry.autodiscover('questions_error')
def test_autodiscover(self): """ Test a basic autodiscover to find all the registered items in each Django app """ from test_appregister.models import registry registry.autodiscover() names = [(c.__module__, c.__name__) for c in registry.all()] self.assertIn(('test_appregister.questions', 'MyAutoDiscoveredQuestion'), names)