Exemplo n.º 1
0
    def test_singular_blog_page_query(self):
        query = """
        {
            firstPost {
                id
            }
        }
        """

        blog_post = BlogPageFactory()
        another_post = BlogPageFactory()
        results = self.client.execute(query, context_value=self.request)

        self.assertTrue("firstPost" in results["data"])
        self.assertEqual(int(results["data"]["firstPost"]["id"]), blog_post.id)

        query = """
        {
            firstPost(order: "-id") {
                id
            }
        }
        """
        results = self.client.execute(query, context_value=self.request)

        self.assertTrue("firstPost" in results["data"])
        self.assertEqual(int(results["data"]["firstPost"]["id"]),
                         another_post.id)
Exemplo n.º 2
0
 def setUp(self):
     super().setUp()
     BlogPageFactory(parent=self.home, title="Test post 1", slug="post-one")
     BlogPageFactory(parent=self.home, title="Test post 2", slug="post-two")
     BlogPageFactory(parent=self.home,
                     title="Test post 3",
                     slug="post-three")
Exemplo n.º 3
0
    def test_singular_blog_page_query(self):
        def query():
            return """
        {
            firstPost {
                id
            }
        }
        """

        blog_post = BlogPageFactory()
        another_post = BlogPageFactory()
        results = self.client.execute(query())

        self.assertTrue("firstPost" in results["data"])
        self.assertEqual(int(results["data"]["firstPost"]["id"]), blog_post.id)

        results = self.client.execute("""
            {
                firstPost(order: "-id") {
                    id
                }
            }
            """)

        self.assertTrue("firstPost" in results["data"])
        self.assertEqual(int(results["data"]["firstPost"]["id"]),
                         another_post.id)
Exemplo n.º 4
0
 def setUp(self):
     super().setUp()
     self.factory = RequestFactory()
     self.request = self.factory.get("/")
     self.request.user = AnonymousUser()
     self.blog_post = BlogPageFactory(parent=self.home, slug="post-one")
     self.another_post = BlogPageFactory(parent=self.home, slug="post-two")
     self.child_post = BlogPageFactory(parent=self.another_post,
                                       slug="post-one")
Exemplo n.º 5
0
    def test_blog_body_pagechooserblock(self):
        another_blog_post = BlogPageFactory(body=[("page", self.blog_page)],
                                            parent=self.home)
        block_type = "PageChooserBlock"
        block_query = """
        page {
            ... on BlogPage {
                date
                authors
            }
        }
        """
        query_blocks = self.get_blocks_from_body(block_type,
                                                 block_query=block_query,
                                                 page_id=another_blog_post.id)

        # Check output.
        count = 0
        for block in another_blog_post.body:
            if type(block.block).__name__ != block_type:
                continue

            # Test the values
            page_data = query_blocks[count]["page"]
            page = block.value
            self.assertEquals(page_data["date"], str(page.date))
            self.assertEquals(
                page_data["authors"],
                list(page.authors.values_list("person__name", flat=True)),
            )
            # Increment the count
            count += 1
        # Check that we test all blocks that were returned.
        self.assertEquals(len(query_blocks), count)
Exemplo n.º 6
0
    def test_singular_blog_page_query(self):
        query = """
        {
            firstPost {
                id
            }
        }
        """

        # add a new blog post
        another_post = BlogPageFactory()
        factory = RequestFactory()
        request = factory.get("/")
        request.user = AnonymousUser()
        results = self.client.execute(query, context_value=request)

        self.assertTrue("firstPost" in results["data"])
        self.assertEqual(int(results["data"]["firstPost"]["id"]),
                         self.blog_page.id)

        query = """
        {
            firstPost(order: "-id") {
                id
            }
        }
        """
        results = self.client.execute(query, context_value=request)

        self.assertTrue("firstPost" in results["data"])
        self.assertEqual(int(results["data"]["firstPost"]["id"]),
                         another_post.id)
Exemplo n.º 7
0
    def test_pages_content_type_filter(self):
        def query(content_type):
            return (
                """
            {
                pages(contentType: "%s") {
                    id
                    title
                    contentType
                    pageType
                }
            }
            """
                % content_type
            )

        results = self.client.execute(query("home.HomePage"))
        data = results["data"]["pages"]
        self.assertEquals(len(data), 1)
        self.assertEqual(int(data[0]["id"]), self.home.id)

        another_post = BlogPageFactory(parent=self.home)
        results = self.client.execute(query("home.BlogPage"))
        data = results["data"]["pages"]
        self.assertEqual(len(data), 2)
        self.assertListEqual(
            [int(p["id"]) for p in data], [self.blog_post.id, another_post.id]
        )

        results = self.client.execute(query("bogus.ContentType"))
        self.assertListEqual(results["data"]["pages"], [])
Exemplo n.º 8
0
    def test_pages_content_type_filter(self):
        query = """
        query($content_type: String) {
            pages(contentType: $content_type) {
                id
                title
                contentType
                pageType
            }
        }
        """

        results = self.client.execute(
            query, variables={"content_type": "home.HomePage"}
        )
        data = results["data"]["pages"]
        self.assertEquals(len(data), 1)
        self.assertEqual(int(data[0]["id"]), self.home.id)

        another_post = BlogPageFactory(parent=self.home)
        results = self.client.execute(
            query, variables={"content_type": "home.BlogPage"}
        )
        data = results["data"]["pages"]
        self.assertEqual(len(data), 2)
        self.assertListEqual(
            [int(p["id"]) for p in data], [self.blog_post.id, another_post.id]
        )

        results = self.client.execute(
            query, variables={"content_type": "bogus.ContentType"}
        )
        self.assertListEqual(results["data"]["pages"], [])
Exemplo n.º 9
0
 def setUp(self):
     super().setUp()
     # Create Blog
     self.blog_page = BlogPageFactory(body=[
         ("heading", "Test heading 1"),
         ("paragraph", RichText("This is a paragraph.")),
         ("heading", "Test heading 2"),
         ("image", wagtail_factories.ImageFactory()),
         ("decimal", decimal.Decimal(1.2)),
         ("date", datetime.date.today()),
         ("datetime", datetime.datetime.now()),
         (
             "carousel",
             StreamValue(
                 stream_block=CarouselBlock(),
                 stream_data=[
                     ("image",
                      wagtail_factories.ImageChooserBlockFactory()),
                     ("image",
                      wagtail_factories.ImageChooserBlockFactory()),
                 ],
             ),
         ),
         (
             "gallery",
             {
                 "title":
                 "Gallery title",
                 "images":
                 StreamValue(
                     stream_block=ImageGalleryImages(),
                     stream_data=[
                         (
                             "image",
                             {
                                 "image":
                                 wagtail_factories.ImageChooserBlockFactory(
                                 )
                             },
                         ),
                         (
                             "image",
                             {
                                 "image":
                                 wagtail_factories.ImageChooserBlockFactory(
                                 )
                             },
                         ),
                     ],
                 ),
             },
         ),
         ("objectives", ["Read all of article!"]),
         ("video", {
             "youtube_link": EmbedValue("https://youtube.com/")
         }),
     ])
Exemplo n.º 10
0
    def test_with_multisite(self):
        home_child = BlogPageFactory(slug="child", parent=self.home)

        another_home = HomePage.objects.create(title="Another home",
                                               slug="another-home",
                                               path="00010002",
                                               depth=2)
        another_site = wagtail_factories.SiteFactory(site_name="Another site",
                                                     root_page=another_home)
        another_child = BlogPageFactory(slug="child", parent=another_home)

        # with multiple sites, only the first one will be returned
        page_data = self._query_by_path("/child/")
        self.assertEquals(int(page_data["id"]), home_child.id)

        with patch("wagtail.core.models.Site.find_for_request",
                   return_value=another_site):
            page_data = self._query_by_path("/child/", in_site=True)
            self.assertEquals(int(page_data["id"]), another_child.id)

            page_data = self._query_by_path("/child", in_site=True)
            self.assertEquals(int(page_data["id"]), another_child.id)
Exemplo n.º 11
0
    def test_page_url_path_filter(self):
        home_child = BlogPageFactory(slug="child", parent=self.home)
        parent = BlogPageFactory(slug="parent", parent=self.home)

        child = BlogPageFactory(slug="child", parent=parent)

        page_data = self._query_by_path("/parent/child/")
        self.assertEquals(int(page_data["id"]), child.id)

        # query without trailing slash
        page_data = self._query_by_path("/parent/child")
        self.assertEquals(int(page_data["id"]), child.id)

        # we have two pages with the same slug, however /home/child will
        # be returned first because of its position in the tree
        page_data = self._query_by_path("/child")
        self.assertEquals(int(page_data["id"]), home_child.id)

        page_data = self._query_by_path("/")
        self.assertEquals(int(page_data["id"]), self.home.id)

        page_data = self._query_by_path("foo/bar")
        self.assertIsNone(page_data)
Exemplo n.º 12
0
 def setUp(self):
     super().setUp()
     # Create Blog
     self.blog_page = BlogPageFactory(body=[
         ("heading", "Test heading 1"),
         ("paragraph", RichText("This is a paragraph.")),
         ("heading", "Test heading 2"),
         ("image", wagtail_factories.ImageFactory()),
         ("decimal", decimal.Decimal(1.2)),
         ("date", datetime.date.today()),
         ("datetime", datetime.datetime.now()),
         (
             "gallery",
             {
                 "title":
                 "Gallery title",
                 "images":
                 StreamValue(
                     stream_block=ImageGalleryImages(),
                     stream_data=[
                         (
                             "image",
                             {
                                 "image":
                                 wagtail_factories.ImageChooserBlockFactory(
                                 )
                             },
                         ),
                         (
                             "image",
                             {
                                 "image":
                                 wagtail_factories.ImageChooserBlockFactory(
                                 )
                             },
                         ),
                     ],
                 ),
             },
         ),
     ])
Exemplo n.º 13
0
 def test_empty_list_in_structblock(self):
     another_blog_post = BlogPageFactory(body=[("text_and_buttons", {
         "buttons": []
     })],
                                         parent=self.home)
     block_type = "TextAndButtonsBlock"
     block_query = """
     buttons {
         ... on ButtonBlock {
             buttonText
             buttonLink
         }
     }
     """
     query_blocks = self.get_blocks_from_body(block_type,
                                              block_query=block_query,
                                              page_id=another_blog_post.id)
     self.assertEqual(query_blocks, [{
         "blockType": "TextAndButtonsBlock",
         "buttons": []
     }])
Exemplo n.º 14
0
    def test_page(self):
        query = """
        query($id: Int) {
            page(id: $id) {
                contentType
                parent {
                    contentType
                }
            }
        }
        """

        blog_page = BlogPageFactory(parent=HomePage.objects.first())

        executed = self.client.execute(query, variables={"id": blog_page.id})

        self.assertEquals(type(executed["data"]), dict_type)
        self.assertEquals(type(executed["data"]["page"]), dict_type)

        page_data = executed["data"]["page"]
        self.assertEquals(page_data["contentType"], "home.BlogPage")
        self.assertEquals(page_data["parent"]["contentType"], "home.HomePage")
Exemplo n.º 15
0
 def setUp(self):
     super().setUp()
     self.blog_post = BlogPageFactory(parent=self.home, slug="post-one")
     self.another_post = BlogPageFactory(parent=self.home, slug="post-two")
     self.child_post = BlogPageFactory(parent=self.another_post,
                                       slug="post-one")
Exemplo n.º 16
0
 def setUp(self):
     super().setUp()
     self.blog_post = BlogPageFactory(parent=self.home, slug="post-one")
     self.name = "Jean-Claude"
     # A randomly generated slug is set here in order to avoid conflicted slug during tests
     self.slug = str(uuid.uuid4().hex[:6].upper())
Exemplo n.º 17
0
    def setUp(self):
        super().setUp()

        # Create Blog
        self.blog_page = BlogPageFactory(
            body=[
                ("heading", "Test heading 1"),
                ("paragraph", RichText("This is a paragraph.")),
                ("heading", "Test heading 2"),
                ("image", wagtail_factories.ImageFactory()),
                ("decimal", decimal.Decimal(1.2)),
                ("date", datetime.date.today()),
                ("datetime", datetime.datetime.now()),
                (
                    "carousel",
                    StreamValue(
                        stream_block=CarouselBlock(),
                        stream_data=[
                            ("image",
                             wagtail_factories.ImageChooserBlockFactory()),
                            ("image",
                             wagtail_factories.ImageChooserBlockFactory()),
                        ],
                    ),
                ),
                (
                    "gallery",
                    {
                        "title":
                        "Gallery title",
                        "images":
                        StreamValue(
                            stream_block=ImageGalleryImages(),
                            stream_data=[
                                (
                                    "image",
                                    {
                                        "image":
                                        wagtail_factories.
                                        ImageChooserBlockFactory()
                                    },
                                ),
                                (
                                    "image",
                                    {
                                        "image":
                                        wagtail_factories.
                                        ImageChooserBlockFactory()
                                    },
                                ),
                            ],
                        ),
                    },
                ),
                ("callout", {
                    "text": RichText("<p>Hello, World</p>")
                }),
                ("objectives", ["Read all of article!"]),
                (
                    "video",
                    {
                        "youtube_link":
                        EmbedValue(
                            "https://www.youtube.com/watch?v=_U79Wc965vw")
                    },
                ),
                (
                    "text_and_buttons",
                    {
                        "text":
                        "Button text",
                        "buttons": [{
                            "button_text": "btn",
                            "button_link": "https://www.graphql.com/",
                        }],
                        "mainbutton": {
                            "button_text": "Take me to the source",
                            "button_link": "https://wagtail.io/",
                        },
                    },
                ),
                ("text_with_callable", TextWithCallableBlockFactory()),
            ],
            parent=self.home,
        )
Exemplo n.º 18
0
 def setUp(self):
     super().setUp()
     self.factory = RequestFactory()
     self.blog_post = BlogPageFactory(parent=self.home)
Exemplo n.º 19
0
    def test_site_pages_content_type_filter(self):
        query = """
        query($hostname: String $content_type: String) {
            site(hostname: $hostname) {
                siteName
                pages(contentType: $content_type) {
                    title
                    contentType
                }
            }
        }
        """
        # grapple test site root page
        results = self.client.execute(
            query,
            variables={
                "hostname": self.site.hostname,
                "content_type": "wagtailcore.Page",
            },
        )
        data = results["data"]["site"]["pages"]
        self.assertEquals(len(data), 1)
        self.assertEquals(data[0]["title"], self.site.root_page.title)

        # Shouldn't return any data
        results = self.client.execute(
            query,
            variables={"hostname": self.site.hostname, "content_type": "home.HomePage"},
        )
        data = results["data"]["site"]["pages"]
        self.assertEquals(len(data), 0)

        # localhost root page
        results = self.client.execute(
            query,
            variables={
                "hostname": self.home.get_site().hostname,
                "content_type": "home.HomePage",
            },
        )
        data = results["data"]["site"]["pages"]
        self.assertEquals(len(data), 1)
        self.assertEquals(data[0]["contentType"], "home.HomePage")
        self.assertEquals(data[0]["title"], self.home.title)

        # Blog page under grapple test site
        blog = BlogPageFactory(
            parent=self.site.root_page, title="blog on grapple test site"
        )
        results = self.client.execute(
            query,
            variables={"hostname": self.site.hostname, "content_type": "home.BlogPage"},
        )
        data = results["data"]["site"]["pages"]
        self.assertEquals(len(data), 1)
        self.assertEquals(data[0]["contentType"], "home.BlogPage")
        self.assertEquals(data[0]["title"], blog.title)

        # Blog page under localhost
        blog = BlogPageFactory(parent=self.home, title="blog on localhost")
        results = self.client.execute(
            query,
            variables={
                "hostname": self.home.get_site().hostname,
                "content_type": "home.BlogPage",
            },
        )
        data = results["data"]["site"]["pages"]
        self.assertEquals(len(data), 1)
        self.assertEquals(data[0]["contentType"], "home.BlogPage")
        self.assertEquals(data[0]["title"], blog.title)