Ejemplo n.º 1
0
 def test_proxy(self):
     if not django1_1:
         return
     fullhistory.end_session()
     tp = TestProxyModel(field1="test1")
     tp.save()
     self.assertEquals(1, len(tp.history.all()))
Ejemplo n.º 2
0
 def test_proxy(self):
     if not django1_1:
         return
     fullhistory.end_session()
     tp = TestProxyModel(field1='test1')
     tp.save()
     self.assertEquals(1, len(tp.history.all()))
Ejemplo n.º 3
0
    def test_details(self):

        # Check for errors

        fullhistory.end_session()
        t3 = Test3Model(field1='test1', field2=5)
        t3.save()

        self.assertEqual(1,
                         len(FullHistory.objects.actions_for_object(t3)))
        self.assertEqual('C',
                         FullHistory.objects.actions_for_object(t3)[0].action)
        t3.field2 = 7
        t3.save()
        self.assertEqual('U',
                         FullHistory.objects.actions_for_object(t3)[1].action)
        pk = t3.pk
        FullHistory.objects.audit(t3)
        t3.delete()

        self.assertEqual('D',
                         FullHistory.objects.actions_for_object(model=Test3Model,
                         pk=pk).reverse()[0].action)
        FullHistory.objects.audit(model=Test3Model, pk=pk)

        previous_revision = -1
        for history in \
            FullHistory.objects.actions_for_object(model=Test3Model,
                pk=pk):
            self.assertEqual(previous_revision + 1, history.revision)
            previous_revision = history.revision

        # lets rollback to the 3rd version

        t3 = FullHistory.objects.rollback(version=3, model=Test3Model,
                pk=pk)
        t3 = Test3Model.objects.get(pk=pk)
        FullHistory.objects.audit(t3)
        t3.delete()

        t3 = FullHistory.objects.rollback(model=Test3Model, pk=pk)
        t3 = Test3Model.objects.get(pk=pk)

        actions = FullHistory.objects.actions_for_object(t3)
        first = actions[0]
        last = actions[len(actions) - 1]
        first.next()
        last.previous()
        self.assertRaises(FullHistory.DoesNotExist, first.previous)
        self.assertRaises(FullHistory.DoesNotExist, last.next)
        while True:
            try:
                previous = first
                first = first.next()
                self.assertNotEqual(first.pk, previous.pk)
            except FullHistory.DoesNotExist:
                self.assertEquals(first.pk, last.pk)
                break
Ejemplo n.º 4
0
    def test_details(self):
        # Check for errors
        fullhistory.end_session()
        t3 = Test3Model(field1="test1", field2=5)
        t3.save()

        self.assertEqual(1, len(FullHistory.objects.actions_for_object(t3)))
        self.assertEqual('C',
                         FullHistory.objects.actions_for_object(t3)[0].action)
        t3.field2 = 7
        t3.save()
        self.assertEqual('U',
                         FullHistory.objects.actions_for_object(t3)[1].action)
        pk = t3.pk
        FullHistory.objects.audit(t3)
        t3.delete()

        self.assertEqual(
            'D',
            FullHistory.objects.actions_for_object(model=Test3Model,
                                                   pk=pk).reverse()[0].action)
        FullHistory.objects.audit(model=Test3Model, pk=pk)

        previous_revision = -1
        for history in FullHistory.objects.actions_for_object(model=Test3Model,
                                                              pk=pk):
            self.assertEqual(previous_revision + 1, history.revision)
            previous_revision = history.revision
        #lets rollback to the 3rd version
        t3 = FullHistory.objects.rollback(version=3, model=Test3Model, pk=pk)
        t3 = Test3Model.objects.get(pk=pk)
        FullHistory.objects.audit(t3)
        t3.delete()

        t3 = FullHistory.objects.rollback(model=Test3Model, pk=pk)
        t3 = Test3Model.objects.get(pk=pk)

        actions = FullHistory.objects.actions_for_object(t3)
        first = actions[0]
        last = actions[len(actions) - 1]
        first.next()
        last.previous()
        self.assertRaises(FullHistory.DoesNotExist, first.previous)
        self.assertRaises(FullHistory.DoesNotExist, last.next)
        while True:
            try:
                previous = first
                first = first.next()
                self.assertNotEqual(first.pk, previous.pk)
            except FullHistory.DoesNotExist:
                self.assertEquals(first.pk, last.pk)
                break
Ejemplo n.º 5
0
 def test_inheritence_historyfield(self):
     fullhistory.end_session()
     t4 = Test4Model(field1='test1', field2=-1)
     t4.save()
     t4.field1 = 'test1a'
     t4.save()
     t2 = Test2Model.objects.get(pk=t4.pk)
     self.assertTrue('field1' in t2.history.all().latest().data)
     try:
         self.assertTrue('field2' in t4.history.all().latest().data)
     except AssertionError:
         if django1_1:
             raise
Ejemplo n.º 6
0
 def test_inheritence_historyfield(self):
     fullhistory.end_session()
     t4 = Test4Model(field1="test1", field2=-1)
     t4.save()
     t4.field1 = "test1a"
     t4.save()
     t2 = Test2Model.objects.get(pk=t4.pk)
     self.assertTrue('field1' in t2.history.all().latest().data)
     try:
         self.assertTrue('field2' in t4.history.all().latest().data)
     except AssertionError:
         if django1_1:
             raise
Ejemplo n.º 7
0
 def test_django_admin(self):
     if not django1_1:
         return
     fullhistory.end_session()
     t3 = Test3Model(field1="foo")
     t3.save()
     t3.field2 = 5
     t3.save()
     
     base = '/admin/%s/%s/' % (Test3Model._meta.app_label, Test3Model._meta.module_name)
     response = self.client.get('%s%s/history/audit/' % (base, t3.pk))
     self.assertEqual(200, response.status_code)
     response = self.client.get('%s%s/history/version/1/' % (base, t3.pk))
     self.assertEqual(200, response.status_code)
     response = self.client.get('%s%s/history/version/256/' % (base, t3.pk))
     self.assertEqual(404, response.status_code)
Ejemplo n.º 8
0
 def test_autofield_with_specified_obj(self):
     """
     This fails due to the combination of an auto field and specifying an id that already is in use
     Effectively we have no way of differing a record loaded from the database (which specifies an id)
     or a record that we manually specify.
     Another scenerio is creating specific object with an id and later setting another field before saving
     In general, we should not specify the id of an object without first loading it
     The alternative is to simply take a snapshot on save and not do differences
     this would be easier but its nice to know what people changed
     """
     fullhistory.end_session()
     t3 = Test3Model(field1="test1", field2=5)
     t3.save()
     t3a = Test3Model(field1="test2", field2=600, id=t3.pk)
     t3a.save()
     self.assertRaises(AssertionError, FullHistory.objects.audit, t3)
Ejemplo n.º 9
0
 def test_autofield_with_specified_obj(self):
     """
     This fails due to the combination of an auto field and specifying an id that already is in use
     Effectively we have no way of differing a record loaded from the database (which specifies an id)
     or a record that we manually specify.
     Another scenerio is creating specific object with an id and later setting another field before saving
     In general, we should not specify the id of an object without first loading it
     The alternative is to simply take a snapshot on save and not do differences
     this would be easier but its nice to know what people changed
     """
     fullhistory.end_session()
     t3 = Test3Model(field1="test1", field2=5)
     t3.save()
     t3a = Test3Model(field1="test2", field2=600, id=t3.pk)
     t3a.save()
     self.assertRaises(AssertionError, FullHistory.objects.audit, t3)
Ejemplo n.º 10
0
    def test_django_admin(self):
        if not django1_1:
            return
        fullhistory.end_session()
        t3 = Test3Model(field1="foo")
        t3.save()
        t3.field2 = 5
        t3.save()

        base = '/admin/%s/%s/' % (Test3Model._meta.app_label,
                                  Test3Model._meta.module_name)
        response = self.client.get('%s%s/history/audit/' % (base, t3.pk))
        self.assertEqual(200, response.status_code)
        response = self.client.get('%s%s/history/version/1/' % (base, t3.pk))
        self.assertEqual(200, response.status_code)
        response = self.client.get('%s%s/history/version/256/' % (base, t3.pk))
        self.assertEqual(404, response.status_code)
Ejemplo n.º 11
0
 def test_inheritence(self):
     fullhistory.end_session()
     t4 = Test4Model(field1='test1', field2=-1)
     t4.save()
     for history in fullhistory.get_active_histories():
         if 'field1' in history.data:
             break
     else:
         self.fail('Did not find field1 in history')
     t4.field1 = 'test1a'
     t4.save()
     t4 = Test4Model.objects.get(pk=t4.pk)
     t4.field2 = 0
     t4.save()
     t2 = Test2Model.objects.get(pk=t4.pk)
     t2.field1 = 'test1b'
     t2.save()
     t4.delete()
Ejemplo n.º 12
0
 def test_inheritence(self):
     fullhistory.end_session()
     t4 = Test4Model(field1="test1", field2=-1)
     t4.save()
     for history in fullhistory.get_active_histories():
         if 'field1' in history.data:
             break
     else:
         self.fail("Did not find field1 in history")
     t4.field1 = "test1a"
     t4.save()
     t4 = Test4Model.objects.get(pk=t4.pk)
     t4.field2 = 0
     t4.save()
     t2 = Test2Model.objects.get(pk=t4.pk)
     t2.field1 = "test1b"
     t2.save()
     t4.delete()
Ejemplo n.º 13
0
 def test_m2m_adjustments(self):
     fullhistory.end_session()
     t1a = Test1Model(field1="test")
     t1a.save()
     t3 = Test3Model(field1="testa", field2=5)
     t3.save()
     t3.test1_m2m.add(t1a)
     history = fullhistory.adjust_history(t3)
     self.assertNotEqual(None, history)
     self.assertTrue('test1_m2m' in history.data)
     self.assertEqual(1, len(history.data['test1_m2m']))
     self.assertEqual(history.data['test1_m2m'][0], [t1a.pk])
     fullhistory.end_session()
     t1b = Test1Model(field1="testb")
     t1b.save()
     t3.test1_m2m.add(t1b)
     history = fullhistory.adjust_history(t3)
     self.assertEqual(history.data['test1_m2m'][0], [t1a.pk])
     self.assertTrue(t1a.pk in history.data['test1_m2m'][1] and t1b.pk in history.data['test1_m2m'][1])
     self.assertEqual(2, len(FullHistory.objects.actions_for_object(t3)))
Ejemplo n.º 14
0
 def test_m2m_adjustments(self):
     fullhistory.end_session()
     t1a = Test1Model(field1="test")
     t1a.save()
     t3 = Test3Model(field1="testa", field2=5)
     t3.save()
     t3.test1_m2m.add(t1a)
     history = fullhistory.adjust_history(t3)
     self.assertNotEqual(None, history)
     self.assertTrue('test1_m2m' in history.data)
     self.assertEqual(1, len(history.data['test1_m2m']))
     self.assertEqual(history.data['test1_m2m'][0], [t1a.pk])
     fullhistory.end_session()
     t1b = Test1Model(field1="testb")
     t1b.save()
     t3.test1_m2m.add(t1b)
     history = fullhistory.adjust_history(t3)
     self.assertEqual(history.data['test1_m2m'][0], [t1a.pk])
     self.assertTrue(t1a.pk in history.data['test1_m2m'][1]
                     and t1b.pk in history.data['test1_m2m'][1])
     self.assertEqual(2, len(FullHistory.objects.actions_for_object(t3)))