def setUp(self):
        self.root_page = Page.objects.get(id=1)
        """
        Create a homepage which satisfies all required fields for positive test.
        """
        self.homepage = HomePageFactory.build_with_fk_objs_committed()
        self.root_page.add_child(instance=self.homepage)
        """
        Set up children pages for TOC
        5 IndexPage with 4 children InformationPage each
        """
        self.index_pages = []
        for i in range(5):
            index_page = IndexPageFactory.build()
            self.homepage.add_child(instance=index_page)
            self.index_pages.append(index_page)

            for j in range(4):
                information_page = InformationPageFactory.build()
                index_page.add_child(instance=information_page)
        """
        Set up information page as children of homepage
        """
        self.information_page = InformationPageFactory.build()
        self.homepage.add_child(instance=self.information_page)
    def test_subheading_within_accordion_uses_subsubheading_template(self):
        page = self.homepage.add_child(instance=InformationPageFactory.build(
            body=json.dumps([{
                "type": "accordion",
                "value": {
                    "items": [{
                        "content": [
                            {
                                "type":
                                "subheading",
                                "value":
                                "Being inside an accordion, "
                                "with its own h2 title, I should use "
                                "subsubheading_block.html",
                            },
                        ]
                    }]
                },
            }])))
        response = self.client.get(page.url)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(
            response,
            "patterns/molecules/streamfield/blocks/subsubheading_block.html")

        self.assertTemplateNotUsed(
            response,
            "patterns/molecules/streamfield/blocks/heading_block.html")
        self.assertTemplateNotUsed(
            response,
            "patterns/molecules/streamfield/blocks/subheading_block.html")
Пример #3
0
    def setUp(self):
        """Test the following structure:

        - site: "www site"
            - section_one: "Gozer index"
                - zuul_page: "Zuul eggs"
                    - vinz_clortho_page: "Vinz Clortho"
                - egon_page: "Egon"
            - section_two: "Dana eggs index"
        - second_site: "second site"
            - section_bee: "bee eggs"
                - cee_page: "cee"
        """

        self.site = Site.objects.get(is_default_site=True)
        self.site.site_name = "www site"
        self.site.save()

        homepage = HomePage.objects.first()

        self.section_one = IndexPageFactory.build(title="Gozer index")
        homepage.add_child(instance=self.section_one)
        self.zuul_page = InformationPageFactory.build(title="Zuul eggs")
        self.section_one.add_child(instance=self.zuul_page)
        self.egon_page = InformationPageFactory.build(title="Egon")
        self.section_one.add_child(instance=self.egon_page)

        self.vinz_clortho_page = InformationPageFactory.build(title="vinz clortho")
        self.zuul_page.add_child(instance=self.vinz_clortho_page)

        self.section_two = IndexPageFactory.build(title="Dana eggs index")
        homepage.add_child(instance=self.section_two)

        root_page = Page.objects.get(id=1)
        homepage_two = HomePageFactory.build_with_fk_objs_committed()
        root_page.add_child(instance=homepage_two)
        self.second_site = Site.objects.create(
            root_page=homepage_two, site_name="second site", hostname=SECOND_HOSTNAME,
        )

        self.section_bee = IndexPageFactory.build(title="bee eggs")
        homepage_two.add_child(instance=self.section_bee)
        self.cee_page = InformationPageFactory.build(title="cee")
        self.section_bee.add_child(instance=self.cee_page)

        update_search_index()
    def setUp(self):
        self.login()

        self.default_site = Site.objects.get(is_default_site=True)
        self.root_page = self.default_site.root_page
        self.info_page = InformationPageFactory.build()
        self.root_page.add_child(instance=self.info_page)

        self.assertIsNotNone(self.info_page.id)
Пример #5
0
    def test_basic_search_behaviour(self):
        hit_page = self.homepage.add_child(
            instance=InformationPageFactory.build(
                title="screwdrivers",
                listing_summary="abcdef",
            ))
        update_search_index()

        response = self.client.get(reverse("search") + "?query=screwdrivers")
        self.assertContains(response, hit_page.listing_summary)
        self.assertEqual(len(response.context["search_results"]), 1)
        self.assertIn(Page.objects.get(pk=hit_page.pk),
                      response.context["search_results"])
Пример #6
0
    def test_search_promotions_included_in_total_shown(self):
        hit_page = self.homepage.add_child(
            instance=InformationPageFactory.build(title="screwdrivers", ))
        update_search_index()
        response = self.client.get(reverse("search") + "?query=screwdrivers")
        self.assertEqual(len(response.context["search_results"]), 1)
        self.assertIn(Page.objects.get(pk=hit_page.pk),
                      response.context["search_results"])

        promoted_page = self.homepage.add_child(
            instance=InformationPageFactory.build(title="spanners", ))
        update_search_index()
        query = Query.objects.get(query_string="screwdrivers")
        promotion = SearchPromotion.objects.create(
            query=query,
            page=promoted_page,
            description="",
        )

        response = self.client.get(reverse("search") + "?query=screwdrivers")
        self.assertEqual(len(response.context["search_results"]), 2)
        self.assertIn(promotion, response.context["search_results"])
        self.assertIn(Page.objects.get(pk=hit_page.pk),
                      response.context["search_results"])
Пример #7
0
    def test_search_promotions_show_custom_descriptions(self):
        promoted_page = self.homepage.add_child(
            instance=InformationPageFactory.build(
                title="spanners",
                listing_summary="mnopqr",
            ))
        update_search_index()
        query = Query.objects.create(query_string="spanners")
        promotion = SearchPromotion.objects.create(
            query=query,
            page=promoted_page,
            description="stuvwx",
        )

        response = self.client.get(reverse("search") + "?query=spanners")
        self.assertContains(response, promotion.description)
Пример #8
0
    def test_search_promotions_not_listed_twice(self):
        hit_page = self.homepage.add_child(
            instance=InformationPageFactory.build(title="hammers", ))
        update_search_index()
        response = self.client.get(reverse("search") + "?query=hammers")
        self.assertEqual(len(response.context["search_results"]), 1)

        query = Query.objects.get(query_string="hammers")
        promotion = SearchPromotion.objects.create(
            query=query,
            page=hit_page,
            description="foo",
        )

        response = self.client.get(reverse("search") + "?query=hammers")
        self.assertEqual(len(response.context["search_results"]), 1)
        self.assertIn(promotion, response.context["search_results"])
    def test_subheading_uses_subheading_template(self):
        page = self.homepage.add_child(instance=InformationPageFactory.build(
            body=json.dumps(
                [{
                    "type": "subheading",
                    "value": "I should use the subheading_block.html template",
                }])))
        response = self.client.get(page.url)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(
            response,
            "patterns/molecules/streamfield/blocks/subheading_block.html")

        self.assertTemplateNotUsed(
            response,
            "patterns/molecules/streamfield/blocks/heading_block.html")
        self.assertTemplateNotUsed(
            response,
            "patterns/molecules/streamfield/blocks/subsubheading_block.html")
Пример #10
0
    def test_search_promotions_shown(self):
        promoted_page = self.homepage.add_child(
            instance=InformationPageFactory.build(
                title="spanners",
                listing_summary="ghijkl",
            ))
        update_search_index()
        response = self.client.get(reverse("search") + "?query=screwdrivers")
        self.assertEqual(len(response.context["search_results"]), 0)

        query = Query.objects.get(query_string="screwdrivers")
        promotion = SearchPromotion.objects.create(
            query=query,
            page=promoted_page,
            description="",
        )

        response = self.client.get(reverse("search") + "?query=screwdrivers")
        self.assertContains(response, promoted_page.listing_summary)
        self.assertEqual(len(response.context["search_results"]), 1)
        self.assertIn(promotion, response.context["search_results"])
 def setUp(self):
     self.homepage = HomePage.objects.first()
     self.child = InformationPageFactory.build()
     self.homepage.add_child(instance=self.child)
 def create_info_page(self):
     info_page = InformationPageFactory.build(title="Hammer Info")
     self.homepage.add_child(instance=info_page)
     self.info_page = Page.objects.get(pk=info_page.id)
    def test_false_for_info_page(self):
        page = InformationPageFactory.build()

        result = is_news_page(page)

        self.assertIs(result, False)
 def setUp(self):
     homepage = HomePage.objects.first()
     self.lookup_page = LookupPageFactory.build()
     homepage.add_child(instance=self.lookup_page)
     self.another_page = InformationPageFactory.build()
     homepage.add_child(instance=self.another_page)