mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-28 00:49:49 +03:00
added testcases
This commit is contained in:
parent
3c8c933e99
commit
aa0164e27d
16
tests/browsable_api/multiple_template_engines.py
Normal file
16
tests/browsable_api/multiple_template_engines.py
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
TEMPLATES = [
|
||||||
|
{
|
||||||
|
"BACKEND": "django_jinja.backend.Jinja2",
|
||||||
|
"APP_DIRS": True,
|
||||||
|
"OPTIONS": {
|
||||||
|
"match_extension": ".html",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||||
|
'APP_DIRS': True,
|
||||||
|
'OPTIONS': {
|
||||||
|
"debug": True, # We want template errors to raise
|
||||||
|
}
|
||||||
|
},
|
||||||
|
]
|
|
@ -1,8 +1,11 @@
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.test import TestCase, override_settings
|
from django.test import Client, TestCase, override_settings
|
||||||
|
from jinja2.exceptions import TemplateSyntaxError
|
||||||
|
|
||||||
from rest_framework.test import APIClient
|
from rest_framework.test import APIClient
|
||||||
|
|
||||||
|
from .multiple_template_engines import TEMPLATES
|
||||||
|
|
||||||
|
|
||||||
@override_settings(ROOT_URLCONF='tests.browsable_api.auth_urls')
|
@override_settings(ROOT_URLCONF='tests.browsable_api.auth_urls')
|
||||||
class DropdownWithAuthTests(TestCase):
|
class DropdownWithAuthTests(TestCase):
|
||||||
|
@ -72,3 +75,29 @@ class NoDropdownWithoutAuthTests(TestCase):
|
||||||
response = self.client.get('/')
|
response = self.client.get('/')
|
||||||
content = response.content.decode()
|
content = response.content.decode()
|
||||||
assert '<li class="dropdown">' not in content
|
assert '<li class="dropdown">' not in content
|
||||||
|
|
||||||
|
|
||||||
|
@override_settings(ROOT_URLCONF='tests.browsable_api.auth_urls')
|
||||||
|
@override_settings(TEMPLATES=TEMPLATES)
|
||||||
|
class CustomTemplateEngineTests(TestCase):
|
||||||
|
"""
|
||||||
|
Within django multiple template engines can be configured.
|
||||||
|
Some configurations will break the rest_framework used templates to render.
|
||||||
|
Usually the first template engine that finds a template by name will be used.
|
||||||
|
While using django_jinja2 and search extension configured to '*.html'
|
||||||
|
all the django common tags like `load` won't work anymore.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.client = Client()
|
||||||
|
|
||||||
|
def test_TemplateSyntaxError(self):
|
||||||
|
with self.assertRaises(TemplateSyntaxError):
|
||||||
|
self.client.get('/')
|
||||||
|
|
||||||
|
def test_default_template_engine_setting(self):
|
||||||
|
# FIXME: when I set this in rest_framework/settings.py
|
||||||
|
# it's working...
|
||||||
|
# no idea how to properly change this setting for this testcase?
|
||||||
|
with override_settings(REST_FRAMEWORK={'DEFAULT_TEMPLATE_ENGINE': 'django'}):
|
||||||
|
self.client.get('/')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user