Пример #1
0
 def test_content_equal(self):
     a = RawTextWidget.add_root(self.widgy_site, text='a')
     b = RawTextWidget.add_root(self.widgy_site, text='b')
     self.assertFalse(a.equal(b))
     b.text = 'a'
     b.save()
     self.assertTrue(a.equal(b))
Пример #2
0
 def test_content_equal(self):
     a = RawTextWidget.add_root(self.widgy_site, text='a')
     b = RawTextWidget.add_root(self.widgy_site, text='b')
     self.assertFalse(a.equal(b))
     b.text = 'a'
     b.save()
     self.assertTrue(a.equal(b))
Пример #3
0
    def test_get_history(self):
        root_node = RawTextWidget.add_root(self.widgy_site, text='first').node
        tracker = VersionTracker.objects.create(working_copy=root_node)

        commits = reversed([tracker.commit() for i in range(6)])

        self.assertSequenceEqual(list(tracker.get_history()), list(commits))
Пример #4
0
    def test_get_history(self):
        root_node = RawTextWidget.add_root(self.widgy_site, text='first').node
        tracker = VersionTracker.objects.create(working_copy=root_node)

        commits = reversed([tracker.commit() for i in range(6)])

        self.assertSequenceEqual(list(tracker.get_history()), list(commits))
Пример #5
0
    def versioned_model(self):
        node = RawTextWidget.add_root(widgy_site,
                                      text=self.string_to_look_for).node
        vt = VersionTracker.objects.create(working_copy=node)
        vt.commit()

        return VersionedPage.objects.create(version_tracker=vt)
Пример #6
0
    def test_trees_unequal_depth(self):
        a = Bucket.add_root(self.widgy_site).add_child(self.widgy_site,
                                                       RawTextWidget,
                                                       text='a')
        b = RawTextWidget.add_root(self.widgy_site, text='a')

        self.assertFalse(a.node.trees_equal(b.node))
Пример #7
0
    def test_prefetch_commits(self):
        root_node = RawTextWidget.add_root(self.widgy_site, text='first').node
        tracker = VersionTracker.objects.create(working_copy=root_node)
        user = User.objects.create()
        commits = reversed([tracker.commit(user=user) for i in range(6)])

        with self.assertNumQueries(1):
            history = tracker.get_history_list()
            for commit in history:
                # root_node and author should be prefetched too
                commit.root_node.pk
                commit.author.pk

            self.assertEqual(list(commits), history)

        tracker = VersionTracker.objects.create(
            working_copy=RawTextWidget.add_root(self.widgy_site).node)
        self.assertEqual(tracker.get_history_list(), [])
Пример #8
0
    def versioned_model(self):
        node = RawTextWidget.add_root(widgy_site,
                                      text=self.string_to_look_for).node
        vt = VersionTracker.objects.create(working_copy=node)
        vt.commit()

        return VersionedPage.objects.create(
            version_tracker=vt
        )
Пример #9
0
    def test_versioned_override(self):
        owner = self.versioned_model()

        override_string = uuid.uuid4().hex
        override = RawTextWidget.add_root(widgy_site, text=override_string).node

        rendered = self.render({'owner': owner, 'field_name': 'version_tracker', 'root_node_override': override})

        self.assertNotIn(self.string_to_look_for, rendered)
        self.assertIn(override_string, rendered)
Пример #10
0
    def test_prefetch_commits(self):
        root_node = RawTextWidget.add_root(self.widgy_site, text='first').node
        tracker = VersionTracker.objects.create(working_copy=root_node)
        user = User.objects.create()
        commits = reversed([tracker.commit(user=user) for i in range(6)])

        with self.assertNumQueries(1):
            history = tracker.get_history_list()
            for commit in history:
                # root_node and author should be prefetched too
                commit.root_node.pk
                commit.author.pk

            self.assertEqual(list(commits), history)

        tracker = VersionTracker.objects.create(
            working_copy=RawTextWidget.add_root(self.widgy_site).node
        )
        self.assertEqual(tracker.get_history_list(), [])
Пример #11
0
    def test_old_contents_cant_change(self):
        root_node = RawTextWidget.add_root(self.widgy_site, text='first').node
        tracker = VersionTracker.objects.create(working_copy=root_node)
        commit = tracker.commit()

        widget = commit.root_node.content
        widget.text = 'changed'
        with self.assertRaises(InvalidOperation):
            widget.save()

        self.assertEquals(Node.objects.get(pk=commit.root_node.pk).content.text, 'first')

        with self.assertRaises(InvalidOperation):
            widget.delete()
Пример #12
0
    def test_old_contents_cant_change(self):
        root_node = RawTextWidget.add_root(self.widgy_site, text='first').node
        tracker = VersionTracker.objects.create(working_copy=root_node)
        commit = tracker.commit()

        widget = commit.root_node.content
        widget.text = 'changed'
        with self.assertRaises(InvalidOperation):
            widget.save()

        self.assertEquals(
            Node.objects.get(pk=commit.root_node.pk).content.text, 'first')

        with self.assertRaises(InvalidOperation):
            widget.delete()
Пример #13
0
    def test_versioned_override(self):
        owner = self.versioned_model()

        override_string = uuid.uuid4().hex
        override = RawTextWidget.add_root(widgy_site,
                                          text=override_string).node

        rendered = self.render({
            'owner': owner,
            'field_name': 'version_tracker',
            'root_node_override': override
        })

        self.assertNotIn(self.string_to_look_for, rendered)
        self.assertIn(override_string, rendered)
Пример #14
0
    def test_commit(self):
        root_node = RawTextWidget.add_root(self.widgy_site, text='first').node
        tracker = VersionTracker.objects.create(working_copy=root_node)
        commit1 = tracker.commit()

        self.assertNotEqual(tracker.working_copy, tracker.head.root_node)

        textwidget_content = tracker.working_copy.content
        textwidget_content.text = 'second'
        textwidget_content.save()
        commit2 = tracker.commit()

        self.assertEqual(commit1.root_node.content.text, 'first')
        self.assertEqual(commit2.root_node.content.text, 'second')

        self.assertEqual(commit2.parent, commit1)
        self.assertEqual(tracker.head, commit2)
Пример #15
0
    def test_frozen_node(self):
        c = RawTextWidget.add_root(self.widgy_site)
        node = c.node
        node.is_frozen = True
        node.save()

        c.text = 'asdf'
        with self.assertRaises(InvalidOperation):
            c.save()

        with self.assertRaises(InvalidOperation):
            c.delete()

        self.assertEqual(RawTextWidget.objects.get(pk=c.pk).text, '')

        with self.assertRaises(InvalidOperation):
            node.delete()
Пример #16
0
    def test_commit(self):
        root_node = RawTextWidget.add_root(self.widgy_site, text='first').node
        tracker = VersionTracker.objects.create(working_copy=root_node)
        commit1 = tracker.commit()

        self.assertNotEqual(tracker.working_copy, tracker.head.root_node)

        textwidget_content = tracker.working_copy.content
        textwidget_content.text = 'second'
        textwidget_content.save()
        commit2 = tracker.commit()

        self.assertEqual(commit1.root_node.content.text, 'first')
        self.assertEqual(commit2.root_node.content.text, 'second')

        self.assertEqual(commit2.parent, commit1)
        self.assertEqual(tracker.head, commit2)
Пример #17
0
    def test_frozen_node(self):
        c = RawTextWidget.add_root(self.widgy_site)
        node = c.node
        node.is_frozen = True
        node.save()

        c.text = 'asdf'
        with self.assertRaises(InvalidOperation):
            c.save()

        with self.assertRaises(InvalidOperation):
            c.delete()

        self.assertEqual(RawTextWidget.objects.get(pk=c.pk).text, '')

        with self.assertRaises(InvalidOperation):
            node.delete()
Пример #18
0
    def test_revert(self):
        root_node = RawTextWidget.add_root(self.widgy_site, text='first').node
        tracker = VersionTracker.objects.create(working_copy=root_node)
        commit1 = tracker.commit()

        self.assertNotEqual(tracker.working_copy, tracker.head.root_node)

        textwidget_content = tracker.working_copy.content
        textwidget_content.text = 'second'
        textwidget_content.save()
        commit2 = tracker.commit()

        commit3 = tracker.revert_to(commit1)

        textwidget_content = tracker.working_copy.content
        textwidget_content.text = 'fourth'
        textwidget_content.save()

        commit4 = tracker.commit()

        self.assertEqual(['fourth', 'first', 'second', 'first'],
                         [i.root_node.content.text for i in tracker.get_history()])
Пример #19
0
    def test_frozen_db_is_canonical(self):
        # I'm not sure if this failure should be expected or not. Should a node
        # always recheck the database value? Or, should we use a database
        # trigger to prevent modifications at the db level?
        root_node = RawTextWidget.add_root(self.widgy_site, text='asdf')

        a = Node.objects.get(pk=root_node.pk).content
        b = Node.objects.get(pk=root_node.pk).content
        # Node has to be set before we set is_frozen, otherwise the call to
        # delete will refetch the node.
        a.node
        b.node

        a.node.is_frozen = True
        a.save()

        # Even though the b _instance_ isn't frozen, the entry in the database
        # is. It would be ok if this was a database error instead of
        # InvalidOperation, like if a BEFORE UPDATE trigger prevented an
        # update.
        with self.assertRaises(InvalidOperation):
            b.delete()
Пример #20
0
    def test_frozen_db_is_canonical(self):
        # I'm not sure if this failure should be expected or not. Should a node
        # always recheck the database value? Or, should we use a database
        # trigger to prevent modifications at the db level?
        root_node = RawTextWidget.add_root(self.widgy_site, text='asdf')

        a = Node.objects.get(pk=root_node.pk).content
        b = Node.objects.get(pk=root_node.pk).content
        # Node has to be set before we set is_frozen, otherwise the call to
        # delete will refetch the node.
        a.node
        b.node

        a.node.is_frozen = True
        a.save()

        # Even though the b _instance_ isn't frozen, the entry in the database
        # is. It would be ok if this was a database error instead of
        # InvalidOperation, like if a BEFORE UPDATE trigger prevented an
        # update.
        with self.assertRaises(InvalidOperation):
            b.delete()
Пример #21
0
    def test_reset(self):
        root_node = RawTextWidget.add_root(self.widgy_site, text='first').node
        tracker = VersionTracker.objects.create(working_copy=root_node)
        commit1 = tracker.commit()

        textwidget_content = tracker.working_copy.content
        textwidget_content.text = 'second'
        textwidget_content.save()

        tracker.reset()
        # the content should get deleted
        self.assertFalse(RawTextWidget.objects.filter(pk=textwidget_content.pk).exists())
        textwidget_content = tracker.working_copy.content
        self.assertEqual(textwidget_content.text, 'first')

        # make sure working_copy is still editable
        textwidget_content = tracker.working_copy.content
        textwidget_content.text = 'second'
        textwidget_content.save()

        tracker.reset()
        textwidget_content = tracker.working_copy.content
        self.assertEqual(textwidget_content.text, 'first')
Пример #22
0
    def test_revert(self):
        root_node = RawTextWidget.add_root(self.widgy_site, text='first').node
        tracker = VersionTracker.objects.create(working_copy=root_node)
        commit1 = tracker.commit()

        self.assertNotEqual(tracker.working_copy, tracker.head.root_node)

        textwidget_content = tracker.working_copy.content
        textwidget_content.text = 'second'
        textwidget_content.save()
        commit2 = tracker.commit()

        commit3 = tracker.revert_to(commit1)

        textwidget_content = tracker.working_copy.content
        textwidget_content.text = 'fourth'
        textwidget_content.save()

        commit4 = tracker.commit()

        self.assertEqual(
            ['fourth', 'first', 'second', 'first'],
            [i.root_node.content.text for i in tracker.get_history()])
Пример #23
0
    def test_frozen_node_raw(self):
        # even the treebeard methods called directly on the node should be frozen
        node = RawTextWidget.add_root(self.widgy_site).node
        node.is_frozen = True
        node.save()

        # 0 queries ensures that the exception is raised before any
        # modification takes place
        with self.assertNumQueries(0):
            with self.assertRaises(InvalidOperation):
                node.delete()

            with self.assertRaises(InvalidOperation):
                node.add_child()

            with self.assertRaises(InvalidOperation):
                node.add_child()

            with self.assertRaises(InvalidOperation):
                node.add_sibling()

            with self.assertRaises(InvalidOperation):
                node.move(node)
Пример #24
0
    def test_frozen_node_raw(self):
        # even the treebeard methods called directly on the node should be frozen
        node = RawTextWidget.add_root(self.widgy_site).node
        node.is_frozen = True
        node.save()

        # 0 queries ensures that the exception is raised before any
        # modification takes place
        with self.assertNumQueries(0):
            with self.assertRaises(InvalidOperation):
                node.delete()

            with self.assertRaises(InvalidOperation):
                node.add_child()

            with self.assertRaises(InvalidOperation):
                node.add_child()

            with self.assertRaises(InvalidOperation):
                node.add_sibling()

            with self.assertRaises(InvalidOperation):
                node.move(node)
Пример #25
0
    def test_reset(self):
        root_node = RawTextWidget.add_root(self.widgy_site, text='first').node
        tracker = VersionTracker.objects.create(working_copy=root_node)
        commit1 = tracker.commit()

        textwidget_content = tracker.working_copy.content
        textwidget_content.text = 'second'
        textwidget_content.save()

        tracker.reset()
        # the content should get deleted
        self.assertFalse(
            RawTextWidget.objects.filter(pk=textwidget_content.pk).exists())
        textwidget_content = tracker.working_copy.content
        self.assertEqual(textwidget_content.text, 'first')

        # make sure working_copy is still editable
        textwidget_content = tracker.working_copy.content
        textwidget_content.text = 'second'
        textwidget_content.save()

        tracker.reset()
        textwidget_content = tracker.working_copy.content
        self.assertEqual(textwidget_content.text, 'first')
Пример #26
0
    def test_edit_content(self):
        content = RawTextWidget.add_root(self.widgy_site)
        content.text = 'hello'
        content.save()

        def doit():
            url = content.to_json(self.widgy_site)['url']
            return self.put(url, {
                'attributes': {'text': 'goodbye'},
            })

        def fail():
            resp = doit()
            self.assertEqual(resp.status_code, 403)
            self.assertEqual(RawTextWidget.objects.get().text, 'hello')

        def win():
            resp = doit()
            self.assertEqual(resp.status_code, 200)
            self.assertEqual(RawTextWidget.objects.get().text, 'goodbye')
            # reset
            RawTextWidget.objects.update(text='hello')

        self.as_different_types_of_user(('change', RawTextWidget), fail, win)
Пример #27
0
    def test_trees_unequal_content_type(self):
        a = CantGoAnywhereWidget.add_root(self.widgy_site)
        b = RawTextWidget.add_root(self.widgy_site, text='a')

        self.assertFalse(a.node.trees_equal(b.node))
Пример #28
0
 def plain_model(self):
     node = RawTextWidget.add_root(widgy_site,
                                   text=self.string_to_look_for).node
     return HasAWidgy.objects.create(
         widgy=node,
     )
Пример #29
0
    def test_trees_unequal_content(self):
        a = RawTextWidget.add_root(self.widgy_site, text='b')
        b = RawTextWidget.add_root(self.widgy_site, text='a')

        self.assertFalse(a.node.trees_equal(b.node))
Пример #30
0
    def test_trees_equal_equal(self):
        a = RawTextWidget.add_root(self.widgy_site, text='a')
        b = RawTextWidget.add_root(self.widgy_site, text='a')

        self.assertTrue(a.node.trees_equal(b.node))
Пример #31
0
def make_tracker(site, vt_class=ReviewedVersionTracker):
    root_node = RawTextWidget.add_root(site, text='first').node
    tracker = vt_class.objects.create(working_copy=root_node)
    return tracker
Пример #32
0
    def test_trees_unequal_content(self):
        a = RawTextWidget.add_root(self.widgy_site, text='b')
        b = RawTextWidget.add_root(self.widgy_site, text='a')

        self.assertFalse(a.node.trees_equal(b.node))
Пример #33
0
    def test_trees_equal_equal(self):
        a = RawTextWidget.add_root(self.widgy_site, text='a')
        b = RawTextWidget.add_root(self.widgy_site, text='a')

        self.assertTrue(a.node.trees_equal(b.node))
Пример #34
0
def make_tracker(site, vt_class=ReviewedVersionTracker):
    root_node = RawTextWidget.add_root(site, text='first').node
    tracker = vt_class.objects.create(working_copy=root_node)
    return tracker
Пример #35
0
    def test_trees_unequal_content_type(self):
        a = CantGoAnywhereWidget.add_root(self.widgy_site)
        b = RawTextWidget.add_root(self.widgy_site, text='a')

        self.assertFalse(a.node.trees_equal(b.node))
Пример #36
0
    def test_trees_unequal_depth(self):
        a = Bucket.add_root(self.widgy_site).add_child(self.widgy_site, RawTextWidget, text='a')
        b = RawTextWidget.add_root(self.widgy_site, text='a')

        self.assertFalse(a.node.trees_equal(b.node))
Пример #37
0
 def plain_model(self):
     node = RawTextWidget.add_root(widgy_site,
                                   text=self.string_to_look_for).node
     return HasAWidgy.objects.create(widgy=node, )