コード例 #1
0
    def test_valid_if_changing_existing_child_node(self):
        item = factories.ChildMenuItemFactory(parent=self.menu_root)
        data = {
            "title": "My new Title",
            "content_type": self.page_ct.pk,
            "object_id": self.page_content.page.pk,
            "_ref_node_id": item.id,
            "numchild": 1,
            "link_target": "_self",
            "_position": "first-child",
        }
        form = MenuItemForm(menu_root=self.menu_root, data=data, instance=item)

        is_valid = form.is_valid()

        self.assertTrue(is_valid)
コード例 #2
0
    def test_skipping_validation_for_object_id_for_root_menuitem(self):
        data = {
            "title": "My new Title",
            "content_type": self.page_ct.pk,
            "_ref_node_id": self.menu_root.id,
            "object_id": 99,
            "numchild": 1,
            "link_target": "_self",
            "_position": "first-child",
        }
        form = MenuItemForm(menu_root=self.menu_root, data=data)
        is_valid = form.is_valid()

        self.assertFalse(is_valid)
        self.assertIn("object_id", form.errors)
        self.assertListEqual(form.errors["object_id"], ["Invalid object"])
コード例 #3
0
    def test_title_is_required(self):
        data = {
            "title": "",
            "content_type": self.page_ct.pk,
            "object_id": self.page_content.page.pk,
            "_ref_node_id": self.menu_root.id,
            "numchild": 1,
            "link_target": "_self",
            "_position": "first-child",
        }
        form = MenuItemForm(menu_root=self.menu_root, data=data)

        is_valid = form.is_valid()

        self.assertFalse(is_valid)
        self.assertIn("title", form.errors)
        self.assertIn("This field is required.", form.errors["title"])
コード例 #4
0
    def test_invalid_object_id(self):
        item = factories.ChildMenuItemFactory(parent=self.menu_root)
        data = {
            "title": "My new Title",
            "content_type": self.page_ct.pk,
            "_ref_node_id": item.id,
            "object_id": 99,
            "numchild": 1,
            "link_target": "_self",
            "_position": "first-child",
        }
        form = MenuItemForm(menu_root=self.menu_root, data=data)

        is_valid = form.is_valid()

        self.assertFalse(is_valid)
        self.assertIn("object_id", form.errors)
        self.assertListEqual(form.errors["object_id"], ["Invalid object"])
コード例 #5
0
    def test_invalid_content_type_id(self):
        data = {
            "title": "My new Title",
            "content_type": self.get_superuser().pk,
            "_ref_node_id": self.menu_root.id,
            "object_id": 1,
            "numchild": 1,
            "link_target": "_self",
            "_position": "first-child",
        }
        form = MenuItemForm(menu_root=self.menu_root, data=data)
        is_valid = form.is_valid()

        self.assertFalse(is_valid)
        self.assertIn("content_type", form.errors)
        self.assertListEqual(
            form.errors["content_type"],
            ["Select a valid choice. That choice is not one of the available choices."],
        )
コード例 #6
0
    def test_invalid_if_trying_to_add_left_sibling_of_existing_root_node(self):
        data = {
            "title": "My new Title",
            "content_type": self.page_ct.pk,
            "object_id": self.page_content.page.pk,
            "_ref_node_id": self.menu_root.id,
            "numchild": 1,
            "link_target": "_self",
            "_position": "left",
        }
        form = MenuItemForm(menu_root=self.menu_root, data=data)

        is_valid = form.is_valid()

        self.assertFalse(is_valid)
        self.assertIn("_ref_node_id", form.errors)
        self.assertListEqual(
            form.errors["_ref_node_id"], ["You cannot add a sibling for this menu item"]
        )
コード例 #7
0
    def test_invalid_if_no_relative_node_specified_and_right_position(self):
        data = {
            "title": "My new Title",
            "content_type": self.page_ct.pk,
            "object_id": self.page_content.page.pk,
            "_ref_node_id": 0,
            "numchild": 1,
            "link_target": "_self",
            "_position": "right",
        }
        form = MenuItemForm(menu_root=self.menu_root, data=data)

        is_valid = form.is_valid()

        self.assertFalse(is_valid)
        self.assertIn("_ref_node_id", form.errors)
        self.assertListEqual(
            form.errors["_ref_node_id"], ["You must specify a relative menu item"]
        )
コード例 #8
0
    def test_invalid_if_relative_node_id_points_to_non_existing_node(self):
        data = {
            "title": "My new Title",
            "content_type": self.page_ct.pk,
            "object_id": self.page_content.page.pk,
            "_ref_node_id": 167,  # node does not exist
            "numchild": 1,
            "link_target": "_self",
            "_position": "first-child",
        }
        form = MenuItemForm(menu_root=self.menu_root, data=data)

        is_valid = form.is_valid()

        self.assertFalse(is_valid)
        self.assertIn("_ref_node_id", form.errors)
        self.assertListEqual(
            form.errors["_ref_node_id"],
            ["Select a valid choice. 167 is not one of the available choices."],
        )
コード例 #9
0
 def test_doesnt_throw_500_errors_if_data_missing_from_post(self):
     form = MenuItemForm(menu_root=self.menu_root, data={})
     try:
         form.is_valid()
     except Exception as e:
         self.fail(str(e))