Esempio n. 1
0
    def test_revision_deserialization(self):
        window, _, _ = self._new_window(width=500, height=300)
        self.assertEqual(window.revision, 2)

        child1, _, _ = self._new_window(parent=window)
        child2, _, _ = self._new_window(parent=window)

        window, _, _ = yawf.dispatch.dispatch(window, self.sender, "minimize_all")

        versions = reversion.get_for_object(window)
        self.assertEqual(len(versions), 2)
        last_version = versions[0]
        message_revision = last_version.revision

        # checking log record
        log_record = main_record_for_revision(message_revision)
        self.assertEqual(log_record.message, "minimize_all")
        self.assertEqual(log_record.object_id, window.id)

        # checking revision
        rev = deserialize_revision(message_revision)
        versions = rev.get_versions_for_record(log_record)
        self.assertEqual(len(versions), 1)
        version = versions[0]
        self.assertEqual(last_version, version)
        previous = previous_version(version)
        diff = versions_diff(previous, version, full=True)
        self.assertItemsEqual(
            diff[0],
            {"field_name": "open_status", "old": "normal", "new": "minimized", "field_verbose_name": "open status"},
        )
        self.assertItemsEqual(
            diff[1], {"field_name": "revision", "old": "2", "new": "3", "field_verbose_name": "revision"}
        )
Esempio n. 2
0
    def test_revision_diff(self):
        window, _, _ = self._new_window(width=500, height=300)
        self.assertEqual(window.revision, 2)

        resized_window, _, _ = yawf.dispatch.dispatch(window, self.sender, "edit__resize", dict(width=200, height=300))
        self.assertEqual(resized_window.revision, 3)

        versions = reversion.get_for_object(window)
        self.assertEqual(len(versions), 2)
        new_rev = versions[0]
        old_rev = versions[1]

        diff = list(diff_fields(old_rev, new_rev))
        self.assertItemsEqual(diff, ["width"])

        diff = versions_diff(old_rev, new_rev)
        self.assertItemsEqual(diff, [{"field_name": "width", "old": 500, "new": 200, "field_verbose_name": "width"}])