Example #1
0
    def test_generate_diff_url(self):
        domain = "http://test.com"
        notification = Notification(app, self.fqname, [], action=DESTROY_REV)
        assert notification.generate_diff_url(domain) == u""

        item = self.imw[self.item_name]
        rev1 = item.store_revision(dict(name=[
            self.item_name,
        ]),
                                   BytesIO(b'x'),
                                   trusted=True,
                                   return_rev=True)
        notification.revs = [rev1]
        assert notification.generate_diff_url(domain) == u""

        rev2 = item.store_revision(dict(name=[
            self.item_name,
        ]),
                                   BytesIO(b'xx'),
                                   trusted=True,
                                   return_rev=True)
        notification.revs = [rev2, rev1]
        assert notification.generate_diff_url(domain) == u"{0}{1}".format(
            domain,
            url_for('frontend.diff',
                    item_name=self.item_name,
                    rev1=rev1.revid,
                    rev2=rev2.revid))
Example #2
0
    def test_get_meta_diff(self):
        item = self.imw[self.item_name]
        rev1 = item.store_revision(dict(name=[self.item_name, ]), BytesIO(b'x'),
                                   trusted=True, return_rev=True)
        notification = Notification(app, self.fqname, ACTION_SAVE, None, None, rev1.data, rev1.meta)
        assert notification.get_meta_diff() == dict_diff(dict(), rev1.meta._meta)

        rev2 = item.store_revision(dict(name=[self.item_name, ]), BytesIO(b'xx'),
                                   trusted=True, return_rev=True)
        notification = Notification(app, self.fqname, ACTION_SAVE, rev1.data, rev1.meta, rev2.data, rev2.meta)
        assert notification.get_meta_diff() == dict_diff(rev1.meta._meta, rev2.meta._meta)

        actions = [DESTROY_REV, DESTROY_ALL, ACTION_TRASH, ]
        for action in actions:
            notification = Notification(app, self.fqname, action, rev2.data, rev2.meta, rev1.data, rev1.meta)
            assert notification.get_meta_diff() == dict_diff(rev2.meta._meta, dict())
Example #3
0
    def test_get_content_diff(self):
        item = self.imw[self.item_name]
        rev1 = item.store_revision(dict(name=[self.item_name, ], contenttype='text/plain;charset=utf-8'),
                                   BytesIO(b'x'), trusted=True, return_rev=True)
        notification = Notification(app, self.fqname, ACTION_SAVE, None, None, rev1.data, rev1.meta)
        assert notification.get_content_diff() == ["+ x"]
        rev1.data.seek(0, 0)

        rev2 = item.store_revision(dict(name=[self.item_name, ], contenttype='text/plain;charset=utf-8'),
                                   BytesIO(b'xx'), trusted=True, return_rev=True)
        notification = Notification(app, self.fqname, ACTION_SAVE, rev1.data, rev1.meta, rev2.data, rev2.meta,)
        assert notification.get_content_diff() == ['- x', '+ xx']
        rev2.data.seek(0, 0)

        notification = Notification(app, self.fqname, ACTION_TRASH, rev2.data, rev2.meta, None, None)
        assert notification.get_content_diff() == ['- xx']
        rev2.data.seek(0, 0)

        item = Item.create(self.item_name)
        notification = Notification(app, self.fqname, DESTROY_REV, rev2.data, rev2.meta, None, None)
        assert notification.get_content_diff() == ['- xx']
        rev2.data.seek(0, 0)

        item = Item.create(self.item_name)
        notification = Notification(app, self.fqname, DESTROY_ALL, rev2.data, rev2.meta, None, None)
        assert notification.get_content_diff() == ['- xx']
Example #4
0
    def test_get_content_diff(self):
        item = self.imw[self.item_name]
        rev1 = item.store_revision(dict(name=[
            self.item_name,
        ],
                                        contenttype='text/plain'),
                                   BytesIO(b'x'),
                                   trusted=True,
                                   return_rev=True)
        notification = Notification(app,
                                    self.fqname, [rev1],
                                    action=ACTION_SAVE)
        assert notification.get_content_diff() == ["+ x"]
        rev1.data.seek(0, 0)

        rev2 = item.store_revision(dict(name=[
            self.item_name,
        ],
                                        contenttype='text/plain'),
                                   BytesIO(b'xx'),
                                   trusted=True,
                                   return_rev=True)
        notification = Notification(app,
                                    self.fqname, [rev2, rev1],
                                    action=ACTION_SAVE)
        assert notification.get_content_diff() == ['- x', '+ xx']
        rev2.data.seek(0, 0)

        notification = Notification(app,
                                    self.fqname, [rev2, rev1],
                                    action=ACTION_TRASH)
        assert notification.get_content_diff() == ['- xx']
        rev2.data.seek(0, 0)

        item = Item.create(self.item_name)
        notification = Notification(app,
                                    self.fqname, [],
                                    content=item.rev.data,
                                    meta=rev2.meta,
                                    action=DESTROY_REV)
        assert notification.get_content_diff() == ['- xx']
        rev2.data.seek(0, 0)

        item = Item.create(self.item_name)
        notification = Notification(app,
                                    self.fqname, [],
                                    content=item.rev.data,
                                    meta=rev2.meta,
                                    action=DESTROY_ALL)
        assert notification.get_content_diff() == ['- xx']