Ejemplo n.º 1
0
    def test_cms_plugins_blogpost_cascade_variant(self):
        """
        If the variant is not specified on the blogpost plugin, it should render
        according to variant variable eventually present in the context of its
        container.
        """
        # Create an blogpost
        blogpost = BlogPostFactory(page_title="public title",
                                   should_publish=True)
        blogpost_page = blogpost.extended_object

        # Create a page to add the plugin to
        page = create_i18n_page("A page")
        placeholder = page.placeholders.get(slot="maincontent")

        # Add blogpost plugin with default template
        model_instance = add_plugin(placeholder,
                                    BlogPostPlugin,
                                    "en",
                                    page=blogpost_page)

        # Get generated html
        request = RequestFactory()
        request.current_page = page
        request.path_info = "/en/my-path/"
        request.user = AnonymousUser()
        context = {
            "current_page": page,
            "blogpost_variant": "xxl",
            "request": request
        }
        renderer = ContentRenderer(request=request)
        html = renderer.render_plugin(model_instance, context)

        self.assertIn("blogpost-xxl", html)
Ejemplo n.º 2
0
    def test_is_request_to_misago(self):
        """
        is_request_to_misago correctly detects requests directed at Misago
        """
        misago_prefix = reverse('misago:index')

        for path in VALID_PATHS:
            request = RequestFactory().get('/')
            request.path_info = path
            self.assertTrue(
                is_request_to_misago(request),
                '"%s" is not overlapped by "%s"' % (path, misago_prefix))

        for path in INVALID_PATHS:
            request = RequestFactory().get('/')
            request.path_info = path
            self.assertFalse(
                is_request_to_misago(request),
                '"%s" is overlapped by "%s"' % (path, misago_prefix))
Ejemplo n.º 3
0
    def test_is_request_to_misago(self):
        """
        is_request_to_misago correctly detects requests directed at Misago
        """
        misago_prefix = reverse('misago:index')

        for path in VALID_PATHS:
            request = RequestFactory().get('/')
            request.path_info = path
            self.assertTrue(
                is_request_to_misago(request),
                '"%s" is not overlapped by "%s"' % (path, misago_prefix))

        for path in INVALID_PATHS:
            request = RequestFactory().get('/')
            request.path_info = path
            self.assertFalse(
                is_request_to_misago(request),
                '"%s" is overlapped by "%s"' % (path, misago_prefix))
Ejemplo n.º 4
0
    def get_content_from_path(self, path):
        """
        Imitates a basic http request using DummyHandler to retrieve
        resulting output (HTML, XML, whatever)
        """
        request = RequestFactory().get(path)
        request.path_info = path
        request.META.setdefault('SERVER_PORT', 80)
        request.META.setdefault('SERVER_NAME', self.server_name)

        handler = DummyHandler()
        try:
            response = handler(request)
        except Exception, err:
            raise StaticGeneratorException("The requested page(\"%s\") raised an exception. Static Generation failed. Error: %s" % (path, str(err)))
Ejemplo n.º 5
0
    def get_content_from_path(self, path):
        """
        Imitates a basic http request using DummyHandler to retrieve
        resulting output (HTML, XML, whatever)
        """

        request = RequestFactory().get(path)
        # We must parse the path to grab query string
        parsed = urlparse.urlparse(path)
        request.path_info = parsed.path
        request.GET = QueryDict(parsed.query)
        request.META.setdefault('SERVER_PORT', 80)
        request.META.setdefault('SERVER_NAME', self.server_name)
        request.META.setdefault('REMOTE_ADDR', '127.0.0.1')

        handler = DummyHandler()
        try:
            response = handler(request)
        except Exception, err:
            raise StaticGeneratorException("The requested page(\"%s\") raised an exception. Static Generation failed. Error: %s" % (path, str(err)))
Ejemplo n.º 6
0
    def get_content_from_path(self, path):
        """
        Imitates a basic http request using DummyHandler to retrieve
        resulting output (HTML, XML, whatever)
        """

        request = RequestFactory().get(path)
        # We must parse the path to grab query string
        parsed = urlparse.urlparse(path)
        request.path_info = parsed.path
        request.GET = QueryDict(parsed.query)
        request.META.setdefault('SERVER_PORT', 80)
        request.META.setdefault('SERVER_NAME', self.server_name)
        request.META.setdefault('REMOTE_ADDR', '127.0.0.1')

        handler = DummyHandler()
        try:
            response = handler(request)
        except Exception, err:
            raise StaticGeneratorException(
                "The requested page(\"%s\") raised an exception. Static Generation failed. Error: %s"
                % (path, str(err)))
Ejemplo n.º 7
0
    def test_cms_plugins_organization_render_context_variant(self):
        """
        The organization plugin should render according to the variant plugin
        option.
        """
        # Create an organization
        organization = OrganizationFactory(page_title="public title",
                                           should_publish=True)
        organization_page = organization.extended_object

        # Create a page to add the plugin to
        page = create_i18n_page("A page")
        placeholder = page.placeholders.get(slot="maincontent")

        # Add organization plugin with default template
        model_instance = add_plugin(
            placeholder,
            OrganizationPlugin,
            "en",
            page=organization_page,
            variant="small",
        )

        # Get generated html
        request = RequestFactory()
        request.current_page = page
        request.path_info = "/en/my-path/"
        request.user = AnonymousUser()
        context = {
            "current_page": page,
            "organization_variant": "xxl",
            "request": request,
        }
        renderer = ContentRenderer(request=request)
        html = renderer.render_plugin(model_instance, context)

        self.assertIn("organization-small", html)