def test_clear_register(self): from test_appregister.models import Question, registry class MyQuestion(Question): pass registry.register(MyQuestion) self.assertIn(MyQuestion, registry.all()) registry.clear() self.assertNotIn(MyQuestion, registry.all())
def test_doesnt_contain_base(self): """ Test the base class isn't registered. """ from test_appregister.models import Question, registry self.assertEqual(registry.all(), set()) class MyQuestion3(Question): pass registry.register(MyQuestion3) self.assertEqual(registry.all(), set([MyQuestion3, ]))
def test_unregister(self): """ Test the unregister process by registering, unregistering and registering again """ from test_appregister.models import Question, registry class MyQuestion3(Question): pass registry.register(MyQuestion3) self.assertIn(MyQuestion3, registry.all()) registry.unregister(MyQuestion3) self.assertNotIn(MyQuestion3, registry.all()) registry.register(MyQuestion3) self.assertIn(MyQuestion3, registry.all())
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_decorator_register(self): """ Test trying registering a class with a decorator. """ from test_appregister.models import Question, registry @registry.register class MyQuestion(Question): pass self.assertIn(MyQuestion, registry.all())
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)