Esempio n. 1
0
 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="******", )
Esempio n. 2
0
 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)
Esempio n. 3
0
 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)))
Esempio n. 4
0
 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 = "******",
     )
Esempio n. 5
0
 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)))
Esempio n. 6
0
 def setUp(self):
     super(FollowModelsTest, self).setUp()
     unregister(ReversionTestModel1)
     register(ReversionTestModel1, follow=("testfollowmodel_set",))
     register(TestFollowModel, follow=("test_model_1", "test_model_2s",))
     self.follow1 = TestFollowModel.objects.create(
         name = "related instance1 version 1",
         test_model_1 = self.test11,
     )
     self.follow1.test_model_2s.add(self.test21, self.test22)
Esempio n. 7
0
 def setUp(self):
     super(FollowModelsTest, self).setUp()
     unregister(ReversionTestModel1)
     register(ReversionTestModel1, follow=("testfollowmodel_set", ))
     register(TestFollowModel, follow=(
         "test_model_1",
         "test_model_2s",
     ))
     self.follow1 = TestFollowModel.objects.create(
         name="related instance1 version 1",
         test_model_1=self.test11,
     )
     self.follow1.test_model_2s.add(self.test21, self.test22)
Esempio n. 8
0
 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
Esempio n. 9
0
 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
Esempio n. 10
0
 def testInlineAdmin(self):
     self.assertTrue(is_registered(InlineTestParentModel))
     # make sure model is following the child FK
     self.assertTrue('children' in get_adapter(InlineTestParentModel).follow)
     self.createInlineObjects()
     # unregister model
     unregister(InlineTestParentModel)
     self.assertFalse(is_registered(InlineTestParentModel))
     # re-register without following
     register(InlineTestParentModel)
     self.assertTrue(is_registered(InlineTestParentModel))
     # make sure model is NOT following the child FK
     self.assertFalse('children' in get_adapter(InlineTestParentModel).follow)
     self.createInlineObjects()
Esempio n. 11
0
def register_concept_reversions(concept_class, *args, **kwargs):
    from reversion import revisions as reversion

    follows = kwargs.get('reversion', {}).get('follow', [])
    # Register the concept with reversion
    reversion.register(concept_class,
                       follow=follows,
                       format='aristotle_mdr_json')

    follow_classes = kwargs.get('reversion', {}).get('follow_classes', [])
    for cls in follow_classes:
        reversion.register(cls)

    if reversion.is_registered(_concept):
        reversion.unregister(_concept)
Esempio n. 12
0
 def testInlineAdmin(self):
     self.assertTrue(is_registered(InlineTestParentModel))
     # make sure model is following the child FK
     self.assertTrue(
         'children' in get_adapter(InlineTestParentModel).follow)
     self.createInlineObjects()
     # unregister model
     unregister(InlineTestParentModel)
     self.assertFalse(is_registered(InlineTestParentModel))
     # re-register without following
     register(InlineTestParentModel)
     self.assertTrue(is_registered(InlineTestParentModel))
     # make sure model is NOT following the child FK
     self.assertFalse(
         'children' in get_adapter(InlineTestParentModel).follow)
     self.createInlineObjects()
Esempio n. 13
0
 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)
Esempio n. 14
0
 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
Esempio n. 15
0
 def tearDown(self):
     unregister(TestFollowModel)
     TestFollowModel.objects.all().delete()
     del self.follow1
     super(FollowModelsTest, self).tearDown()
Esempio n. 16
0
 def tearDown(self):
     unregister(TestFollowModel)
     TestFollowModel.objects.all().delete()
     del self.follow1
     super(FollowModelsTest, self).tearDown()
Esempio n. 17
0
 def tearDown(self):
     unregister(TestFollowModel)
     super(FollowModelsTest, self).tearDown()