Пример #1
0
 def testEagerRegistration(self):
     # Register the model and test.
     reversion.register(ReversionTestModel3, eager_signals=[pre_delete])
     self.assertTrue(reversion.is_registered(ReversionTestModel3))
     self.assertRaises(
         RegistrationError,
         lambda: reversion.register(ReversionTestModel3,
                                    eager_signals=[pre_delete]))
     self.assertTrue(
         ReversionTestModel3 in reversion.get_registered_models())
     self.assertTrue(
         isinstance(reversion.get_adapter(ReversionTestModel3),
                    reversion.VersionAdapter))
     self.assertEquals(
         [],
         reversion.default_revision_manager._signals[ReversionTestModel3])
     self.assertEquals([pre_delete], reversion.default_revision_manager.
                       _eager_signals[ReversionTestModel3])
     # Unregister the model and text.
     reversion.unregister(ReversionTestModel3)
     self.assertFalse(reversion.is_registered(ReversionTestModel3))
     self.assertRaises(RegistrationError,
                       lambda: reversion.unregister(ReversionTestModel3))
     self.assertTrue(
         ReversionTestModel3 not in reversion.get_registered_models())
     self.assertRaises(
         RegistrationError,
         lambda: isinstance(reversion.get_adapter(ReversionTestModel3)))
     self.assertFalse(
         ReversionTestModel3 in reversion.default_revision_manager._signals)
     self.assertFalse(ReversionTestModel3 in
                      reversion.default_revision_manager._eager_signals)
Пример #2
0
 def testRegistration(self):
     # Register the model and test.
     reversion.register(ReversionTestModel1)
     self.assertTrue(reversion.is_registered(ReversionTestModel1))
     self.assertRaises(RegistrationError, lambda: reversion.register(ReversionTestModel1))
     self.assertTrue(ReversionTestModel1 in reversion.get_registered_models())
     self.assertTrue(isinstance(reversion.get_adapter(ReversionTestModel1), reversion.VersionAdapter))
     # Unregister the model and text.
     reversion.unregister(ReversionTestModel1)
     self.assertFalse(reversion.is_registered(ReversionTestModel1))
     self.assertRaises(RegistrationError, lambda: reversion.unregister(ReversionTestModel1))
     self.assertTrue(ReversionTestModel1 not in reversion.get_registered_models())
     self.assertRaises(RegistrationError, lambda: isinstance(reversion.get_adapter(ReversionTestModel1)))
Пример #3
0
 def setUp(self):
     # Unregister all registered models.
     self.initial_registered_models = []
     for registered_model in reversion.get_registered_models():
         self.initial_registered_models.append(
             (registered_model,
              reversion.get_adapter(registered_model).__class__))
         reversion.unregister(registered_model)
     # Register the test models.
     reversion.register(ReversionTestModel1)
     reversion.register(ReversionTestModel2)
     reversion.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="******", )
Пример #4
0
 def setUp(self):
     # Unregister all registered models.
     self.initial_registered_models = []
     for registered_model in reversion.get_registered_models():
         self.initial_registered_models.append((registered_model, reversion.get_adapter(registered_model).__class__))
         reversion.unregister(registered_model)
     # Register the test models.
     reversion.register(ReversionTestModel1)
     reversion.register(ReversionTestModel2)
     reversion.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 = "******",
     )
Пример #5
0
 def tearDown(self):
     # Unregister the test models.
     reversion.unregister(ReversionTestModel1)
     reversion.unregister(ReversionTestModel2)
     reversion.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 reversion.get_registered_models():
         reversion.unregister(registered_model)
     # Re-register initial registered models.
     for initial_model, adapter in self.initial_registered_models:
         reversion.register(initial_model, adapter_cls=adapter)
     del self.initial_registered_models
Пример #6
0
 def check_registration(self, test_model):
     # Register the model and test.
     reversion.register(test_model)
     self.assertTrue(reversion.is_registered(test_model))
     self.assertRaises(RegistrationError, lambda: reversion.register(test_model))
     self.assertTrue(test_model in reversion.get_registered_models())
     self.assertTrue(isinstance(reversion.get_adapter(test_model), reversion.VersionAdapter))
Пример #7
0
 def check_deregistration(self, test_model):
     # Unregister the model and text.
     reversion.unregister(test_model)
     self.assertFalse(reversion.is_registered(test_model))
     self.assertRaises(RegistrationError, lambda: reversion.unregister(test_model))
     self.assertTrue(test_model not in reversion.get_registered_models())
     self.assertRaises(RegistrationError, lambda: isinstance(reversion.get_adapter(test_model)))
Пример #8
0
 def test_model_registering(self):
     test_app_config = apps.get_app_config(
         app_label="reversion_compare_tests")
     models = test_app_config.get_models(include_auto_created=False,
                                         include_swapped=False)
     default_registered = len(list(get_registered_models()))
     self.assertEqual(default_registered, len(tuple(models)))
Пример #9
0
 def setUp(self):
     # Unregister all registered models.
     self.initial_registered_models = []
     for registered_model in reversion.get_registered_models():
         self.initial_registered_models.append((registered_model, reversion.get_adapter(registered_model).__class__))
         reversion.unregister(registered_model)
     # Register the test models.
     reversion.register(ReversionTestModel1)
     reversion.register(ReversionTestModel2)
     # 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.user = User()
     if CUSTOM_USER_MODEL:
         setattr(self.user, User.USERNAME_FIELD, '1')
     else:
         self.user.username = "******"
Пример #10
0
 def tearDown(self):
     # Unregister the test models.
     reversion.unregister(ReversionTestModel1)
     reversion.unregister(ReversionTestModel2)
     reversion.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 reversion.get_registered_models():
         reversion.unregister(registered_model)
     # Re-register initial registered models.
     for initial_model, adapter in self.initial_registered_models:
         reversion.register(initial_model, adapter_cls=adapter)
     del self.initial_registered_models
Пример #11
0
 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))
Пример #12
0
 def testEagerRegistration(self):
     # Register the model and test.
     reversion.register(ReversionTestModel3, eager_signals=[pre_delete])
     self.assertTrue(reversion.is_registered(ReversionTestModel3))
     self.assertRaises(RegistrationError, lambda: reversion.register(ReversionTestModel3, eager_signals=[pre_delete]))
     self.assertTrue(ReversionTestModel3 in reversion.get_registered_models())
     self.assertTrue(isinstance(reversion.get_adapter(ReversionTestModel3), reversion.VersionAdapter))
     self.assertEquals([], reversion.default_revision_manager._signals[ReversionTestModel3])
     self.assertEquals([pre_delete], reversion.default_revision_manager._eager_signals[ReversionTestModel3])
     # Unregister the model and text.
     reversion.unregister(ReversionTestModel3)
     self.assertFalse(reversion.is_registered(ReversionTestModel3))
     self.assertRaises(RegistrationError, lambda: reversion.unregister(ReversionTestModel3))
     self.assertTrue(ReversionTestModel3 not in reversion.get_registered_models())
     self.assertRaises(RegistrationError, lambda: isinstance(reversion.get_adapter(ReversionTestModel3)))
     self.assertFalse(ReversionTestModel3 in reversion.default_revision_manager._signals)
     self.assertFalse(ReversionTestModel3 in reversion.default_revision_manager._eager_signals)
Пример #13
0
 def check_deregistration(self, test_model):
     # Unregister the model and text.
     reversion.unregister(test_model)
     self.assertFalse(reversion.is_registered(test_model))
     self.assertRaises(RegistrationError,
                       lambda: reversion.unregister(test_model))
     self.assertTrue(test_model not in reversion.get_registered_models())
     self.assertRaises(
         RegistrationError,
         lambda: isinstance(reversion.get_adapter(test_model)))
Пример #14
0
 def test_model_registering(self):
     test_app = get_app(app_label="reversion_compare_test_app")
     models = get_models(app_mod=test_app,
                         include_auto_created=False,
                         include_deferred=False,
                         only_installed=True)
     default_registered = len(reversion.get_registered_models())
     custom_registered = len(
         custom_revision_manager.get_registered_models())
     self.assertEqual(default_registered + custom_registered, len(models))
Пример #15
0
 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))
Пример #16
0
 def check_registration(self, test_model):
     # Register the model and test.
     reversion.register(test_model)
     self.assertTrue(reversion.is_registered(test_model))
     self.assertRaises(RegistrationError,
                       lambda: reversion.register(test_model))
     self.assertTrue(test_model in reversion.get_registered_models())
     self.assertTrue(
         isinstance(reversion.get_adapter(test_model),
                    reversion.VersionAdapter))
Пример #17
0
 def test_model_registering(self):
     test_app_config = apps.get_app_config(app_label="reversion_compare_tests")
     if django.VERSION < (1, 10):
         models = test_app_config.get_models(
             include_auto_created=False, include_deferred=False, include_swapped=False
         )
     else:
         # Django >= v1.10
         models = test_app_config.get_models(include_auto_created=False, include_swapped=False)
     default_registered = len(list(get_registered_models()))
     self.assertEqual(default_registered, len(tuple(models)))
Пример #18
0
 def tearDown(self):
     # Unregister the test models.
     reversion.unregister(ReversionTestModel1)
     reversion.unregister(ReversionTestModel2)
     reversion.unregister(ReversionTestModel3)
     # Unregister all remaining models.
     for registered_model in reversion.get_registered_models():
         reversion.unregister(registered_model)
     # Re-register initial registered models.
     for initial_model, adapter in self.initial_registered_models:
         reversion.register(initial_model, adapter_cls=adapter)
     del self.initial_registered_models
Пример #19
0
 def tearDown(self):
     # Unregister the test models.
     reversion.unregister(ReversionTestModel1)
     reversion.unregister(ReversionTestModel2)
     reversion.unregister(ReversionTestModel3)
     # Unregister all remaining models.
     for registered_model in reversion.get_registered_models():
         reversion.unregister(registered_model)
     # Re-register initial registered models.
     for initial_model, adapter in self.initial_registered_models:
         reversion.register(initial_model, adapter_cls=adapter)
     del self.initial_registered_models
Пример #20
0
def set_version_diff(obj, v1, v2, setname, field):
    """Lookup an object that isn't the primary one, but is part
    of the same revision set, i.e. a foreign-key related date.
    TODO: Find a better way of doing this - it is probably 
    HORRIBLY slow (although only used on the diff page, so not
    that important."""
    import reversion
    from django.contrib.contenttypes.models import ContentTypeManager
    from diff_match_patch import diff_match_patch
    dmp = diff_match_patch()
    # FIXME: As well as being gross, this is fragile because
    # it doesn't account for more than one 
    model = getattr(obj, setname).model
    ctype = ContentTypeManager().get_for_model(model)
    if not model in reversion.get_registered_models():
        raise AttributeError("Model %r is not registered as a reversion model.")
    set1 = v1.revision.version_set.filter(content_type=ctype)
    set2 = v2.revision.version_set.filter(content_type=ctype)
    setobj1 = model.objects.filter([v.object_id for v in set1])
    setobj2 = model.objects.filter([v.object_id for v in set2])
    setids1 = [v.object_id for v in set1]
    setids2 = [v.object_id for v in set2]
    added = []
    persisted = []
    deleted = []
    # NB: This assumes that if a version's object
    # is 'None' than it's not in a previous version.
    for vers in set1:
        if vers.object:
            if vers.object_id not in setids2:
                added.append(vers.object)
            else:
                persisted.append(vers.object)
    for vers in set2:
        if vers.object_id not in setids1:
            deleted.append(vers)
    out = []
    for vers in added:
        diffs = dmp.diff_main(unicode(vers.field_dict[field]), u"")
        dmp.diff_cleanupSemantic(diffs)
        out.append(dmp.diff_prettyHtml(diffs))
    for vers in persisted:
        out.append(vers.field_dict[field])
    for vers in deleted:
        diffs = dmp.diff_main(u"", unicode(vers.field_dict[field]))
        dmp.diff_cleanupSemantic(diffs)
        out.append(dmp.diff_prettyHtml(diffs))
    return u"<li>" + out.join(u"</li><li>") + u"</li>"
Пример #21
0
 def testGetRegisteredModels(self):
     self.assertEqual(set(reversion.get_registered_models()),
                      set((
                          TestModel,
                          TestModelParent,
                      )))
Пример #22
0
 def testGetRegisteredModels(self):
     self.assertEqual(set(reversion.get_registered_models()), set((TestModel,)))
Пример #23
0
 def test_model_registering(self):
     test_app = get_app(app_label="reversion_compare_test_app")
     models = get_models(app_mod=test_app, include_auto_created=False, include_deferred=False, only_installed=True)
     default_registered = len(reversion.get_registered_models())
     custom_registered = len(custom_revision_manager.get_registered_models())
     self.assertEqual(default_registered + custom_registered, len(models))
Пример #24
0
 def test_model_registering(self):
     test_app = get_app(app_label="reversion_compare_test_app")
     models = get_models(app_mod=test_app, include_auto_created=False, include_deferred=False, only_installed=True)
     self.assertEqual(len(reversion.get_registered_models()), len(models))
def _get_all_model_labels():
    return [model._meta.label for model in reversion.get_registered_models()]
Пример #26
0
 def test_07_reversion(self):
     
     # Ensure that our 3 models are registered with reversion automatically
     for model in [Article, Story, Gallery]:
         self.assertTrue(model in get_registered_models())
Пример #27
0
 def setUp(self):
     super().setUp()
     for model in list(reversion.get_registered_models()):
         reversion.unregister(model)
Пример #28
0
 def setUp(self):
     super(TestBaseMixin, self).setUp()
     for model in list(reversion.get_registered_models()):
         reversion.unregister(model)
Пример #29
0
 def tearDown(self):
     super(TestBaseMixin, self).tearDown()
     for model in list(reversion.get_registered_models()):
         reversion.unregister(model)
Пример #30
0
 def test_model_registering(self):
     test_app = get_app(app_label="reversion_compare_test_app")
     models = get_models(app_mod=test_app, include_auto_created=False, include_deferred=False, only_installed=True)
     self.assertEqual(len(reversion.get_registered_models()), len(models))
Пример #31
0
 def tearDown(self):
     super(TestBaseMixin, self).tearDown()
     for model in list(reversion.get_registered_models()):
         reversion.unregister(model)