Esempio n. 1
0
from django import template
from django.test import override_settings
from tests.BaseTestWithDB import BaseTestWithDB
from tests.chapters.ChaptersTestDataGenerator import ChaptersTestDataGenerator
from tests.interactives.InteractivesTestDataGenerator import InteractivesTestDataGenerator
from tests.helpers import template_settings_for_test

templates = template_settings_for_test(
    "tests/config/templatetags/assets/templates/")


@override_settings(TEMPLATES=templates)
class RenderHTMLFieldTest(BaseTestWithDB):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.test_data = ChaptersTestDataGenerator()
        self.interactive_test_data = InteractivesTestDataGenerator()

    def render_template(self, string, context=None):
        context = context or {}
        context = template.Context(context)
        return template.Template(string).render(context)

    def test_render_html_field_without_tags(self):
        chapter = self.test_data.create_chapter(1)
        context = {"chapter": chapter}
        rendered = self.render_template(
            "{% load render_html_field %}\n{% render_html_field chapter.introduction %}",
            context)
        self.assertHTMLEqual(rendered, "<p>Introduction for chapter 1</p>")
from django.test import override_settings
from django.http import Http404
from tests.BaseTestWithDB import BaseTestWithDB
from tests.helpers import template_settings_for_test
from utils.render_interactive_html import render_interactive_html
from interactives.models import Interactive

templates = template_settings_for_test("tests/utils/assets/templates/")


@override_settings(TEMPLATES=templates)
@override_settings(INTERACTIVES_BASE_TEMPLATES_PATH="base/")
class RenderInteractiveHTMLTest(BaseTestWithDB):

    def test_render_interactive_html_in_page(self):
        Interactive(
            slug="interactive-in-page",
            name="Interacive in-page",
            template="interactive-in-page.html",
        ).save()
        result = render_interactive_html("interactive-in-page", "in-page")
        self.assertHTMLEqual(
            result,
            """
            <h1>in-page mode</h1>
            <p>Interactive in-page HTML</p>
            <p>Interactive in-page CSS</p>
            <p>Interactive in-page JS</p>
            """,
        )
Esempio n. 3
0
from http import HTTPStatus
from django.urls import reverse
from django.test import override_settings
from tests.BaseTestWithDB import BaseTestWithDB
from tests.interactives.InteractivesTestDataGenerator import InteractivesTestDataGenerator
from tests.helpers import template_settings_for_test

templates = template_settings_for_test("tests/interactives/views/assets/templates/")


@override_settings(TEMPLATES=templates)
@override_settings(INTERACTIVES_BASE_TEMPLATES_PATH="base/")
class InteractivesViewTest(BaseTestWithDB):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.test_data = InteractivesTestDataGenerator()
        self.language = "en"

    def test_interactive_view_whole_page_with_valid_slug(self):
        self.test_data.create_interactive(1)
        kwargs = {
            "interactive_slug": "interactive-1"
        }
        url = reverse("interactives:interactive", kwargs=kwargs)
        response = self.client.get(url)
        self.assertEqual(HTTPStatus.OK, response.status_code)
        self.assertTemplateUsed(response, "base/whole-page.html")

    def test_interactive_view_whole_page_with_invalid_slug(self):
        kwargs = {