def testEagerRegistration(self): # Register the model and test. register(ReversionTestModel3, eager_signals=[pre_delete]) self.assertTrue(is_registered(ReversionTestModel3)) self.assertRaises( RegistrationError, lambda: register(ReversionTestModel3, eager_signals=[pre_delete])) self.assertTrue(ReversionTestModel3 in get_registered_models()) self.assertTrue( isinstance(get_adapter(ReversionTestModel3), VersionAdapter)) self.assertEqual( [], default_revision_manager._signals[ReversionTestModel3]) self.assertEqual( [pre_delete], default_revision_manager._eager_signals[ReversionTestModel3]) # Unregister the model and text. unregister(ReversionTestModel3) self.assertFalse(is_registered(ReversionTestModel3)) self.assertRaises(RegistrationError, lambda: unregister(ReversionTestModel3)) self.assertTrue(ReversionTestModel3 not in get_registered_models()) self.assertRaises(RegistrationError, lambda: isinstance(get_adapter(ReversionTestModel3))) self.assertFalse( ReversionTestModel3 in default_revision_manager._signals) self.assertFalse( ReversionTestModel3 in default_revision_manager._eager_signals)
def check_deregistration(self, test_model): # Unregister the model and text. unregister(test_model) self.assertFalse(is_registered(test_model)) self.assertRaises(RegistrationError, lambda: unregister(test_model)) self.assertTrue(test_model not in get_registered_models()) self.assertRaises(RegistrationError, lambda: isinstance(get_adapter(test_model)))
def check_registration(self, test_model): # Register the model and test. register(test_model) self.assertTrue(is_registered(test_model)) self.assertRaises(RegistrationError, lambda: register(test_model)) self.assertTrue(test_model in get_registered_models()) self.assertTrue(isinstance(get_adapter(test_model), VersionAdapter))
def tearDown(self): # Unregister the test models. unregister(ReversionTestModel1) unregister(ReversionTestModel2) unregister(ReversionTestModel3) # Delete the test models. ReversionTestModel1.objects.all().delete() ReversionTestModel2.objects.all().delete() ReversionTestModel3.objects.all().delete() User.objects.all().delete() del self.test11 del self.test12 del self.test21 del self.test22 del self.test31 del self.test32 del self.user # Delete the revisions index. Revision.objects.all().delete() # Unregister all remaining models. for registered_model in get_registered_models(): unregister(registered_model) # Re-register initial registered models. for initial_model, adapter in self.initial_registered_models: register(initial_model, adapter_cls=adapter) del self.initial_registered_models
def setUp(self): # Unregister all registered models. self.initial_registered_models = [] for registered_model in get_registered_models(): self.initial_registered_models.append((registered_model, get_adapter(registered_model).__class__)) unregister(registered_model) # Register the test models. register(ReversionTestModel1) register(ReversionTestModel2) register(ReversionTestModel3, eager_signals=[pre_delete]) # Create some test data. self.test11 = ReversionTestModel1.objects.create( name = "model1 instance1 version1", ) self.test12 = ReversionTestModel1.objects.create( name = "model1 instance2 version1", ) self.test21 = ReversionTestModel2.objects.create( name = "model2 instance1 version1", ) self.test22 = ReversionTestModel2.objects.create( name = "model2 instance2 version1", ) self.test31 = ReversionTestModel3.objects.create( name = "model3 instance1 version1", ) self.test32 = ReversionTestModel3.objects.create( name = "model3 instance2 version1", ) self.user = User.objects.create( username = "******", )
def setUp(self): # Unregister all registered models. self.initial_registered_models = [] for registered_model in get_registered_models(): self.initial_registered_models.append( (registered_model, get_adapter(registered_model).__class__)) unregister(registered_model) # Register the test models. register(ReversionTestModel1) register(ReversionTestModel2) register(ReversionTestModel3, eager_signals=[pre_delete]) # Create some test data. self.test11 = ReversionTestModel1.objects.create( name="model1 instance1 version1", ) self.test12 = ReversionTestModel1.objects.create( name="model1 instance2 version1", ) self.test21 = ReversionTestModel2.objects.create( name="model2 instance1 version1", ) self.test22 = ReversionTestModel2.objects.create( name="model2 instance2 version1", ) self.test31 = ReversionTestModel3.objects.create( name="model3 instance1 version1", ) self.test32 = ReversionTestModel3.objects.create( name="model3 instance2 version1", ) self.user = User.objects.create(username="******", )
def testEagerRegistration(self): # Register the model and test. register(ReversionTestModel3, eager_signals=[pre_delete]) self.assertTrue(is_registered(ReversionTestModel3)) self.assertRaises(RegistrationError, lambda: register(ReversionTestModel3, eager_signals=[pre_delete])) self.assertTrue(ReversionTestModel3 in get_registered_models()) self.assertTrue(isinstance(get_adapter(ReversionTestModel3), VersionAdapter)) self.assertEqual([], default_revision_manager._signals[ReversionTestModel3]) self.assertEqual([pre_delete], default_revision_manager._eager_signals[ReversionTestModel3]) # Unregister the model and text. unregister(ReversionTestModel3) self.assertFalse(is_registered(ReversionTestModel3)) self.assertRaises(RegistrationError, lambda: unregister(ReversionTestModel3)) self.assertTrue(ReversionTestModel3 not in get_registered_models()) self.assertRaises(RegistrationError, lambda: isinstance(get_adapter(ReversionTestModel3))) self.assertFalse(ReversionTestModel3 in default_revision_manager._signals) self.assertFalse(ReversionTestModel3 in default_revision_manager._eager_signals)
def test_model_registering(self): test_app = get_app(app_label="tests") models = get_models( app_mod=test_app, include_auto_created=False, include_deferred=False, include_swapped=False ) default_registered = len(reversion.get_registered_models()) custom_registered = len(custom_revision_manager.get_registered_models()) self.assertEqual(default_registered + custom_registered, len(models))
def tearDown(self): # Unregister the test models. unregister(ReversionTestModel1) unregister(ReversionTestModel2) unregister(ReversionTestModel3) # Unregister all remaining models. for registered_model in get_registered_models(): unregister(registered_model) # Re-register initial registered models. for initial_model, adapter in self.initial_registered_models: register(initial_model, adapter_cls=adapter) del self.initial_registered_models