Esempio n. 1
0
    def test_trees_unequal_children(self):
        a = Bucket.add_root(self.widgy_site)
        a.add_child(self.widgy_site, RawTextWidget, text='a')
        a.add_child(self.widgy_site, RawTextWidget, text='b')

        b = Bucket.add_root(self.widgy_site)
        b.add_child(self.widgy_site, RawTextWidget, text='a')

        self.assertFalse(a.node.trees_equal(b.node))
Esempio n. 2
0
    def test_trees_unequal_children(self):
        a = Bucket.add_root(self.widgy_site)
        a.add_child(self.widgy_site, RawTextWidget, text='a')
        a.add_child(self.widgy_site, RawTextWidget, text='b')

        b = Bucket.add_root(self.widgy_site)
        b.add_child(self.widgy_site, RawTextWidget, text='a')

        self.assertFalse(a.node.trees_equal(b.node))
Esempio n. 3
0
    def test_tree_structure_versioned(self):
        root_node = Bucket.add_root(self.widgy_site).node
        root_node.content.add_child(
            self.widgy_site,
            RawTextWidget,
            text='a')
        root_node.content.add_child(
            self.widgy_site,
            RawTextWidget,
            text='b')

        # if the root_node isn't refetched, get_children is somehow empty. I
        # don't know why
        root_node = Node.objects.get(pk=root_node.pk)
        tracker = VersionTracker.objects.create(working_copy=root_node)
        commit1 = tracker.commit()

        new_a, new_b = tracker.working_copy.content.get_children()
        new_b.reposition(self.widgy_site, right=new_a)
        tracker.working_copy = Node.objects.get(pk=root_node.pk)
        commit2 = tracker.commit()
        self.assertEqual(['a', 'b'],
                         [i.content.text for i in commit1.root_node.get_children()])
        self.assertEqual(['b', 'a'],
                         [i.content.text for i in commit2.root_node.get_children()])
Esempio n. 4
0
    def test_clone_tree_uses_prefetch(self):
        root = Bucket.add_root(self.widgy_site)
        root.add_child(self.widgy_site, RawTextWidget, text='a')
        root.add_child(self.widgy_site, RawTextWidget, text='b')

        root_node = root.node
        root_node.prefetch_tree()

        # - root content (1 query)
        # - root node (2 queries)
        # - 2 text contents (2 queries)
        # - subnodes (1 query)
        with self.assertNumQueries(6):
            root_node.clone_tree()
Esempio n. 5
0
    def test_clone_tree_uses_prefetch(self):
        root = Bucket.add_root(self.widgy_site)
        root.add_child(self.widgy_site, RawTextWidget, text='a')
        root.add_child(self.widgy_site, RawTextWidget, text='b')

        root_node = root.node
        root_node.prefetch_tree()

        # - root content (1 query)
        # - root node (2 queries)
        # - 2 text contents (2 queries)
        # - subnodes (1 query)
        with self.assertNumQueries(6):
            root_node.clone_tree()
Esempio n. 6
0
    def test_old_structure_cant_change(self):
        root_node = Bucket.add_root(self.widgy_site).node
        root_node.content.add_child(self.widgy_site, RawTextWidget, text='a')
        root_node.content.add_child(self.widgy_site, RawTextWidget, text='b')
        root_node = Node.objects.get(pk=root_node.pk)
        tracker = VersionTracker.objects.create(working_copy=root_node)
        commit = tracker.commit()

        a, b = Node.objects.get(pk=commit.root_node.pk).content.get_children()
        with self.assertRaises(InvalidOperation):
            b.reposition(self.widgy_site, right=a)

        with self.assertRaises(InvalidOperation):
            commit.root_node.content.add_child(self.widgy_site, RawTextWidget, text='c')

        self.assertEqual([i.content.text for i in commit.root_node.get_children()],
                         ['a', 'b'])
Esempio n. 7
0
    def test_deep_deletion_prevented(self):
        # do the deletion on something other than the root node
        related = Related.objects.create()
        root_node = Bucket.add_root(self.widgy_site).node
        root_node.content.add_child(self.widgy_site, ForeignKeyWidget, foo=related)
        root_node = Node.objects.get(pk=root_node.pk)
        tracker = VersionTracker.objects.create(working_copy=root_node)
        commit = tracker.commit()

        # the related object must not be able to be deleted
        with self.assertRaises((ProtectedError, InvalidOperation)):
            with atomic_or_nop():
                related.delete()

        # the related object must still exist
        Related.objects.get(pk=related.pk)

        # the node and content must still exist
        Node.objects.get(pk=commit.root_node.pk)
        ForeignKeyWidget.objects.get(pk=commit.root_node.content.get_children()[0].pk)
Esempio n. 8
0
    def test_old_structure_cant_change(self):
        root_node = Bucket.add_root(self.widgy_site).node
        root_node.content.add_child(self.widgy_site, RawTextWidget, text='a')
        root_node.content.add_child(self.widgy_site, RawTextWidget, text='b')
        root_node = Node.objects.get(pk=root_node.pk)
        tracker = VersionTracker.objects.create(working_copy=root_node)
        commit = tracker.commit()

        a, b = Node.objects.get(pk=commit.root_node.pk).content.get_children()
        with self.assertRaises(InvalidOperation):
            b.reposition(self.widgy_site, right=a)

        with self.assertRaises(InvalidOperation):
            commit.root_node.content.add_child(self.widgy_site,
                                               RawTextWidget,
                                               text='c')

        self.assertEqual(
            [i.content.text for i in commit.root_node.get_children()],
            ['a', 'b'])
Esempio n. 9
0
    def test_tree_structure_versioned(self):
        root_node = Bucket.add_root(self.widgy_site).node
        root_node.content.add_child(self.widgy_site, RawTextWidget, text='a')
        root_node.content.add_child(self.widgy_site, RawTextWidget, text='b')

        # if the root_node isn't refetched, get_children is somehow empty. I
        # don't know why
        root_node = Node.objects.get(pk=root_node.pk)
        tracker = VersionTracker.objects.create(working_copy=root_node)
        commit1 = tracker.commit()

        new_a, new_b = tracker.working_copy.content.get_children()
        new_b.reposition(self.widgy_site, right=new_a)
        tracker.working_copy = Node.objects.get(pk=root_node.pk)
        commit2 = tracker.commit()
        self.assertEqual(
            ['a', 'b'],
            [i.content.text for i in commit1.root_node.get_children()])
        self.assertEqual(
            ['b', 'a'],
            [i.content.text for i in commit2.root_node.get_children()])
Esempio n. 10
0
    def test_deep_deletion_prevented(self):
        # do the deletion on something other than the root node
        related = Related.objects.create()
        root_node = Bucket.add_root(self.widgy_site).node
        root_node.content.add_child(self.widgy_site,
                                    ForeignKeyWidget,
                                    foo=related)
        root_node = Node.objects.get(pk=root_node.pk)
        tracker = VersionTracker.objects.create(working_copy=root_node)
        commit = tracker.commit()

        # the related object must not be able to be deleted
        with self.assertRaises((ProtectedError, InvalidOperation)):
            with atomic_or_nop():
                related.delete()

        # the related object must still exist
        Related.objects.get(pk=related.pk)

        # the node and content must still exist
        Node.objects.get(pk=commit.root_node.pk)
        ForeignKeyWidget.objects.get(
            pk=commit.root_node.content.get_children()[0].pk)