コード例 #1
0
    def test_sibling_menu_items_are_copied(self):
        """The implementation of versioning for MenuContent correctly
        copies sibling MenuItem objects
        """
        original_root = factories.RootMenuItemFactory()
        original_version = factories.MenuVersionFactory(
            content__root=original_root)
        original_child = factories.ChildMenuItemFactory(parent=original_root)
        original_sibling = factories.SiblingMenuItemFactory(
            sibling=original_child, hide_node=True)

        new_version = original_version.copy(self.user)

        new_root = new_version.content.root
        # If this throws DoesNotExist then the sibling clearly wasn't duplicated
        new_sibling = MenuItem.objects.get(path=new_root.path +
                                           original_sibling.path[4:])
        # The fields in the sibling have been copied over correctly
        self.assertEqual(new_sibling.title, original_sibling.title)
        self.assertEqual(new_sibling.content, original_sibling.content)
        self.assertEqual(new_sibling.link_target, original_sibling.link_target)
        self.assertEqual(new_sibling.soft_root, original_sibling.soft_root)
        self.assertEqual(new_sibling.hide_node, original_sibling.hide_node)
        # The new sibling is indeed a sibling node of the new child
        new_child = MenuItem.objects.get(path=new_root.path +
                                         original_child.path[4:])
        self.assertTrue(new_child.is_sibling_of(new_child))
コード例 #2
0
    def test_child_menu_items_are_copied(self):
        """The implementation of versioning for MenuContent correctly
        copies child MenuItem objects
        """
        original_root = factories.RootMenuItemFactory()
        original_version = factories.MenuVersionFactory(
            content__root=original_root)
        original_child = factories.ChildMenuItemFactory(parent=original_root,
                                                        soft_root=True,
                                                        hide_node=True)

        new_version = original_version.copy(self.user)

        new_root = new_version.content.root
        # If this throws DoesNotExist then the child clearly wasn't duplicated
        new_child = MenuItem.objects.exclude(
            pk__in=[original_root.pk, original_child.pk, new_root.pk]).get()
        # The fields in the child have been copied over correctly
        self.assertEqual(new_child.title, original_child.title)
        self.assertEqual(new_child.content, original_child.content)
        self.assertEqual(new_child.link_target, original_child.link_target)
        self.assertEqual(new_child.soft_root, original_child.soft_root)
        self.assertEqual(new_child.hide_node, original_child.hide_node)

        # The new child is indeed a child node of the new root
        self.assertTrue(new_child.is_child_of(new_root))
コード例 #3
0
    def test_navigation_compare_view(self):
        """
        When comparing navigation content, the original and new version should be in the context
        """
        original_root = factories.RootMenuItemFactory()
        original_version = factories.MenuVersionFactory(
            content__root=original_root)
        original_child = factories.ChildMenuItemFactory(parent=original_root,
                                                        soft_root=True,
                                                        hide_node=True)

        new_version = original_version.copy(self.user)

        new_root = new_version.content.root
        # If this throws DoesNotExist then the child clearly wasn't duplicated
        MenuItem.objects.exclude(
            pk__in=[original_root.pk, original_child.pk, new_root.pk]).get()

        endpoint = "/en/admin/djangocms_versioning/menucontentversion/"
        endpoint += "%d/compare/?compare_to=%d" % (new_version.pk,
                                                   original_version.pk)

        with self.login_user_context(self.user):
            response = self.client.get(endpoint)

        self.assertEqual(response.status_code, 200)
        self.assertContains(response,
                            "Comparing Version #{}".format(new_version.number))
        self.assertContains(response, "Version #{}".format(new_version.number))
        self.assertContains(response,
                            "Version #{}".format(original_version.number))
コード例 #4
0
    def test_only_display_node_tree_of_current_root(self):
        child = factories.ChildMenuItemFactory(parent=self.menu_root)
        root2 = factories.RootMenuItemFactory()
        child_of_root2 = factories.ChildMenuItemFactory(parent=root2)
        form = MenuItemForm(menu_root=self.menu_root)

        menu_item_ids = [choice[0] for choice in form.fields["_ref_node_id"].choices]

        # The menu items that should be in choices are indeed there
        self.assertIn(self.menu_root.pk, menu_item_ids)
        self.assertIn(child.pk, menu_item_ids)
        # Those from other root nodes are not
        self.assertNotIn(root2.pk, menu_item_ids)
        self.assertNotIn(child_of_root2.pk, menu_item_ids)
        # And the general count is correct
        self.assertEqual(len(form.fields["_ref_node_id"].choices), 3)
コード例 #5
0
 def setUp(self):
     self.menu_root = factories.RootMenuItemFactory()
     self.page_content = factories.PageContentFactory()
     self.page_ct = ContentType.objects.get_for_model(Page)