def test_va_diff_new_column_and_del_column(self):
        p = UserTable(**self.p1)
        p._updated_by = '1'
        self._add_and_test_version(p, 0)

        print("111", p.__table__.c)
        self.addTestNullableColumn()
        p = self.session.query(UserTable).get(p.id)
        print("222", p.__table__.c)
        p.col1 = 'test'
        p.test_column1 = 'tc1'
        p._updated_by = '2'
        self.session.commit()

        res = UserTable.va_diff(self.session, va_id=p.va_id)
        print("RESULT", res)
        self.assertEqual(
            res, {
                'va_prev_version': 0,
                'va_version': 1,
                'prev_user_id': '1',
                'user_id': '2',
                'change': {
                    'col1': {
                        'this': 'test',
                        'prev': 'foobar'
                    },
                    'test_column1': {
                        'prev': None,
                        'this': 'tc1',
                    }
                }
            })
        print("PASSED")
        self.deleteTestNullableColumn()
        print("DELETED")
        p = self.session.query(UserTable).get(p.id)
        print("P COLS", p.__table__.c)
        p.col1 = 'test2'
        p._updated_by = '1'
        self.session.commit()
        res = UserTable.va_diff(self.session, va_id=p.va_id)
        print("ANOTHER RES", res)
        self.assertEqual(
            res, {
                'va_prev_version': 1,
                'va_version': 2,
                'prev_user_id': '2',
                'user_id': '1',
                'change': {
                    'col1': {
                        'this': 'test2',
                        'prev': 'test'
                    },
                    'test_column1': {
                        'prev': 'tc1',
                        'this': None,
                    }
                }
            })
    def test_va_diff_basic_va_version(self):
        p = UserTable(**self.p1)
        p._updated_by = '1'
        self._add_and_test_version(p, 0)
        p = self.session.query(UserTable).get(p.id)

        p.col1 = 'test'
        p._updated_by = '2'
        self.session.commit()
        log = self.session.query(ArchiveTable).get(p.va_id)

        res = UserTable.va_diff(self.session, log.va_version)
        self.assertEqual(
            res, {
                'va_prev_version': 0,
                'va_version': 1,
                'prev_user_id': '1',
                'user_id': '2',
                'change': {
                    'col1': {
                        'this': 'test',
                        'prev': 'foobar'
                    }
                }
            })
    def test_va_diff_2parallel_history(self):
        p1 = UserTable(**self.p1)
        p2 = UserTable(**self.p2)
        p1._updated_by = '1'
        p2._updated_by = '1'

        self._add_and_test_version(p1, 0)
        self._add_and_test_version(p2, 0)
        p1 = self.session.query(UserTable).get(p1.id)
        p2 = self.session.query(UserTable).get(p2.id)
        p1.col1 = 'test1'
        p2.col1 = 'test2'
        p1._updated_by = '2'
        p2._updated_by = '2'
        self.session.commit()
        res_p1 = UserTable.va_diff(self.session, va_id=p1.va_id)
        self.assertEqual(
            res_p1, {
                'va_prev_version': 0,
                'va_version': 1,
                'prev_user_id': '1',
                'user_id': '2',
                'change': {
                    'col1': {
                        'this': 'test1',
                        'prev': 'foobar'
                    }
                }
            })
        res_p2 = UserTable.va_diff(self.session, va_id=p2.va_id)
        self.assertEqual(
            res_p2, {
                'va_prev_version': 0,
                'va_version': 1,
                'prev_user_id': '1',
                'user_id': '2',
                'change': {
                    'col1': {
                        'this': 'test2',
                        'prev': 'baz'
                    }
                }
            })
    def test_va_diff_first_version(self):
        p = UserTable(**self.p1)
        p._updated_by = '1'
        self._add_and_test_version(p, 0)
        p = self.session.query(UserTable).get(p.id)

        res = UserTable.va_diff(self.session, va_id=p.va_id)
        self.assertEqual(
            res, {
                'va_prev_version': None,
                'va_version': 0,
                'prev_user_id': None,
                'user_id': '1',
                'change': {
                    'col1': {
                        'this': 'foobar',
                        'prev': None
                    },
                    'col2': {
                        'this': 10,
                        'prev': None
                    },
                    'col3': {
                        'prev': None,
                        'this': 1
                    },
                    'product_id': {
                        'prev': None,
                        'this': 10
                    },
                    'id': {
                        'this': 1,
                        'prev': None
                    }
                }
            })