Example #1
0
    def _render(self, context):
        template_path = os.path.join(
            os.path.dirname(__file__), 'please-wait.html')
        template_code = open(template_path).read()

        # Normally, we would use template loaders, but could there be
        # interactions between the configs necessary here and in the parent app?
        engine = DjangoTemplates({
            'OPTIONS': {}, 'NAME': None, 'DIRS': [], 'APP_DIRS': []
        })
        # All the keys are required, but the values don't seem to matter.
        template = engine.from_string(template_code)

        return template.render(context)
Example #2
0
    def test_context_has_priority_over_template_context_processors(self):
        # See ticket #23789.
        engine = DjangoTemplates(
            {"DIRS": [], "APP_DIRS": False, "NAME": "django", "OPTIONS": {"context_processors": [test_processor_name]}}
        )

        template = engine.from_string("{{ processors }}")
        request = RequestFactory().get("/")

        # Check that context processors run
        content = template.render({}, request)
        self.assertEqual(content, "yes")

        # Check that context overrides context processors
        content = template.render({"processors": "no"}, request)
        self.assertEqual(content, "no")
Example #3
0
 def test_render_requires_dict(self):
     """django.Template.render() requires a dict."""
     engine = DjangoTemplates({
         'DIRS': [],
         'APP_DIRS': False,
         'NAME': 'django',
         'OPTIONS': {},
     })
     template = engine.from_string('')
     context = Context()
     request_context = RequestContext(self.request_factory.get('/'), {})
     msg = 'context must be a dict rather than Context.'
     with self.assertRaisesMessage(TypeError, msg):
         template.render(context)
     msg = 'context must be a dict rather than RequestContext.'
     with self.assertRaisesMessage(TypeError, msg):
         template.render(request_context)
Example #4
0
 def test_render_requires_dict(self):
     """django.Template.render() requires a dict."""
     engine = DjangoTemplates({
         'DIRS': [],
         'APP_DIRS': False,
         'NAME': 'django',
         'OPTIONS': {},
     })
     template = engine.from_string('')
     context = Context()
     request_context = RequestContext(RequestFactory().get('/'), {})
     msg = 'context must be a dict rather than Context.'
     with self.assertRaisesMessage(TypeError, msg):
         template.render(context)
     msg = 'context must be a dict rather than RequestContext.'
     with self.assertRaisesMessage(TypeError, msg):
         template.render(request_context)
Example #5
0
 def test_render_requires_dict(self):
     """django.Template.render() requires a dict."""
     engine = DjangoTemplates({
         "DIRS": [],
         "APP_DIRS": False,
         "NAME": "django",
         "OPTIONS": {},
     })
     template = engine.from_string("")
     context = Context()
     request_context = RequestContext(self.request_factory.get("/"), {})
     msg = "context must be a dict rather than Context."
     with self.assertRaisesMessage(TypeError, msg):
         template.render(context)
     msg = "context must be a dict rather than RequestContext."
     with self.assertRaisesMessage(TypeError, msg):
         template.render(request_context)
Example #6
0
    def test_context_has_priority_over_template_context_processors(self):
        # See ticket #23789.
        engine = DjangoTemplates({
            'DIRS': [],
            'APP_DIRS': False,
            'NAME': 'django',
            'OPTIONS': {
                'context_processors': [test_processor_name],
            },
        })

        template = engine.from_string('{{ processors }}')
        request = RequestFactory().get('/')

        # Check that context processors run
        content = template.render({}, request)
        self.assertEqual(content, 'yes')

        # Check that context overrides context processors
        content = template.render({'processors': 'no'}, request)
        self.assertEqual(content, 'no')
Example #7
0
    def test_context_has_priority_over_template_context_processors(self):
        # See ticket #23789.
        engine = DjangoTemplates({
            "DIRS": [],
            "APP_DIRS": False,
            "NAME": "django",
            "OPTIONS": {
                "context_processors": [test_processor_name],
            },
        })

        template = engine.from_string("{{ processors }}")
        request = self.request_factory.get("/")

        # Context processors run
        content = template.render({}, request)
        self.assertEqual(content, "yes")

        # Context overrides context processors
        content = template.render({"processors": "no"}, request)
        self.assertEqual(content, "no")