Ejemplo n.º 1
0
    def test_get_root_page__more_than_one(self):
        """
        If there are multiple root pages in the database, `get_root_page`
        should raise a MultipleObjectsReturned exception
        """
        # Create a new root page
        Page.add_root(instance=Page(title="Route 2"))

        with self.assertRaises(Site.MultipleObjectsReturned) as cm:
            get_root_page()

        self.assertEqual(
            cm.exception.args,
            ('Foliage can\'t auto-determine the root page. '
             'More than one Page exists with depth 1 in the database!', ))
Ejemplo n.º 2
0
    def clear(self, quiet=False):
        """
        Clear all the RevolvCustomPages and RevolvLinkPages and reset the site
        root page. We need to reset the site root page because of how django-treebeard
        works. In order to keep a tree of related models, the parent Pages store
        meta information about their children, including paths.

        This means that we can't actually just delete all the Page models that
        we created in seed(): we instead have to do that AND delete the root page
        and reset it.

        References:
            wagtail Site model: https://github.com/torchbox/wagtail/blob/e937d7a1a32052966b6dfa9768168ea990f7916a/wagtail/wagtailcore/models.py#L52
            treebeard add_root() docs: https://tabo.pe/projects/django-treebeard/docs/1.61/api.html#treebeard.models.Node.add_root
        """
        try:
            only_site = Site.objects.all()[0]
            only_site.root_page.delete()
            new_root_page = Page.add_root(title="RE-volv Main Site Root")
            only_site.root_page = new_root_page
            only_site.save()
        except ObjectDoesNotExist as e:
            if not quiet:
                print "[Seed:Warning] Error in %s when trying to clear: %s" % (
                    self.__class__.__name__, str(e))
Ejemplo n.º 3
0
    def _create(cls, *args, **kwargs):
        try:
            root = Page.objects.get(depth=0)
        except Page.DoesNotExist:
            root = Page.add_root(title='root')

        return root.add_child(title=kwargs['title'])
Ejemplo n.º 4
0
    def test_create_news(self):
        self.assertEqual(NewsStory.objects.count(), 0)
        root = Page.add_root(title='Root page')

        news_folder = pkg_resources.resource_filename(
            'akllt', 'tests/fixtures/naujienos'
        )
        news = import_news(news_folder)
        for news_story in news:
            root.add_child(instance=NewsStory(
                title=news_story['title'],
                date=news_story['date'],
                blurb=news_story['blurb'],
                body=news_story['body'],
            ))
Ejemplo n.º 5
0
    def test_get_site__more_than_one(self):
        """
        If there are multiple sites in the database, `get_site` should raise
        a MultipleObjectsReturned exeption
        """
        # Create a second site with a new root page
        root_page = Page.add_root(instance=Page(title="Second Sight"))
        Site.objects.create(hostname='secondsight.com',
                            port=80,
                            root_page=root_page)

        with self.assertRaises(Site.MultipleObjectsReturned) as cm:
            get_site()

        self.assertEqual(cm.exception.args,
                         ("Foliage can't auto-determine the Wagtail Site. "
                          "More than one Site exists in the database!", ))
Ejemplo n.º 6
0
    def clear(self, quiet=False):
        """
        Clear all the RevolvCustomPages and RevolvLinkPages and reset the site
        root page. We need to reset the site root page because of how django-treebeard
        works. In order to keep a tree of related models, the parent Pages store
        meta information about their children, including paths.

        This means that we can't actually just delete all the Page models that
        we created in seed(): we instead have to do that AND delete the root page
        and reset it.

        References:
            wagtail Site model: https://github.com/torchbox/wagtail/blob/e937d7a1a32052966b6dfa9768168ea990f7916a/wagtail/wagtailcore/models.py#L52
            treebeard add_root() docs: https://tabo.pe/projects/django-treebeard/docs/1.61/api.html#treebeard.models.Node.add_root
        """
        try:
            only_site = Site.objects.all()[0]
            only_site.root_page.delete()
            new_root_page = Page.add_root(title="RE-volv Main Site Root")
            only_site.root_page = new_root_page
            only_site.save()
        except ObjectDoesNotExist as e:
            if not quiet:
                print "[Seed:Warning] Error in %s when trying to clear: %s" % (self.__class__.__name__, str(e))