def test_get_internal_page(self):
        """
        Test a existing internal page
        """
        plugin_name = "auth"
        internal_page_name = "input_username"

        is_content = internal_page.get_internal_page(
            self.fake_context, plugin_name, internal_page_name
        )
        must_content = self._get_default_ipage(
            plugin_name, internal_page_name, "html"
        )
        assert is_content == must_content
def replace_add_data(context, content):
    """
    Replace the temporary inserted "add data" tag, with all collected CSS/JS
    contents, e.g. from the internal pages.
    Note: The tag added in PyLucid.plugins_internal.page_style
    """
    internal_page_content = get_internal_page(context, "page_style", "add_data")

    context = {
        "js_data": context["js_data"],
        "css_data": context["css_data"],
    }
    html = render_string_template(
        internal_page_content, context, autoescape=False
    )

    content = content.replace(settings.ADD_DATA_TAG, html)
    return content
    def test_custom_ipage(self):
        """
        Create a custom internal page file and check if this page would be used
        and not the default one.

        -create the custom path e.g.: ./media/PyLucid/custom/auth
        -create the internal path file e.g.: ...custom/auth/input_username.html
        -get the internal page and compare the content
        -delete the test internal page file
        -delete all created path parts
        """
        plugin_name = "auth"
        internal_page_name = "input_username"

        # For the test it may not exist an custom file, yet.
        self.assertRaises(
            IOError,
            self._get_custom_ipage,
                plugin_name, internal_page_name, "html"
        )

        # Check if the path e.g. ./media/PyLucid/custom/auth/ exists
        # create and delete it, if is not exists
        base_path = os.path.join(
            settings.MEDIA_ROOT,
            settings.PYLUCID_MEDIA_DIR,
            settings.CUSTOM_INTERNAL_PAGE_DIR,
        )
        custom_path = os.path.join(base_path, plugin_name)
        paths = [
            [base_path, False], [custom_path, False]
        ]
        # Create all path parts, which doesn't exists yet.
        # Remember the created directories for later remove.
        for path in paths:
            if os.path.isdir(path[0]):
                path[1] = True
            else:
                os.mkdir(path[0])

        filepath = self._get_filepath(
            settings.CUSTOM_INTERNAL_PAGE_DIR,
            plugin_name, internal_page_name, "html"
        )
        try:
            # Create the custom internal page
            f = file(filepath, "w")
            f.write(TEST_CONTENT)
            f.close()

            # Get the content via the productive used function
            is_content = internal_page.get_internal_page(
                self.fake_context, plugin_name, internal_page_name
            )
            # Check if the content is the test content and not the default
            # internal page content
            assert is_content == TEST_CONTENT
        finally:
            try:
                # remove the test file
                os.remove(filepath)
            finally:
                # Remove all dir parts, how doesn't exists before the test
                paths.reverse()
                for path, exists in paths:
                    if exists == False:
                        os.rmdir(path)