Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
e965270f
Commit
e965270f
authored
Jan 16, 2017
by
Artem Muterko
Committed by
Tom Christie
Jan 16, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Template html renderer tests (#4817)
parent
50c2d71a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
1 deletions
+42
-1
tests/test_htmlrenderer.py
+42
-1
No files found.
tests/test_htmlrenderer.py
View file @
e965270f
from
__future__
import
unicode_literals
from
__future__
import
unicode_literals
import
django.template.loader
import
django.template.loader
import
pytest
from
django.conf.urls
import
url
from
django.conf.urls
import
url
from
django.core.exceptions
import
PermissionDenied
from
django.core.exceptions
import
ImproperlyConfigured
,
PermissionDenied
from
django.http
import
Http404
from
django.http
import
Http404
from
django.template
import
Template
,
TemplateDoesNotExist
from
django.template
import
Template
,
TemplateDoesNotExist
from
django.test
import
TestCase
,
override_settings
from
django.test
import
TestCase
,
override_settings
...
@@ -46,6 +47,12 @@ urlpatterns = [
...
@@ -46,6 +47,12 @@ urlpatterns = [
@override_settings
(
ROOT_URLCONF
=
'tests.test_htmlrenderer'
)
@override_settings
(
ROOT_URLCONF
=
'tests.test_htmlrenderer'
)
class
TemplateHTMLRendererTests
(
TestCase
):
class
TemplateHTMLRendererTests
(
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
class
MockResponse
(
object
):
template_name
=
None
self
.
mock_response
=
MockResponse
()
self
.
_monkey_patch_get_template
()
def
_monkey_patch_get_template
(
self
):
"""
"""
Monkeypatch get_template
Monkeypatch get_template
"""
"""
...
@@ -87,6 +94,40 @@ class TemplateHTMLRendererTests(TestCase):
...
@@ -87,6 +94,40 @@ class TemplateHTMLRendererTests(TestCase):
self
.
assertEqual
(
response
.
content
,
six
.
b
(
"403 Forbidden"
))
self
.
assertEqual
(
response
.
content
,
six
.
b
(
"403 Forbidden"
))
self
.
assertEqual
(
response
[
'Content-Type'
],
'text/html; charset=utf-8'
)
self
.
assertEqual
(
response
[
'Content-Type'
],
'text/html; charset=utf-8'
)
# 2 tests below are based on order of if statements in corresponding method
# of TemplateHTMLRenderer
def
test_get_template_names_returns_own_template_name
(
self
):
renderer
=
TemplateHTMLRenderer
()
renderer
.
template_name
=
'test_template'
template_name
=
renderer
.
get_template_names
(
self
.
mock_response
,
view
=
{})
assert
template_name
==
[
'test_template'
]
def
test_get_template_names_returns_view_template_name
(
self
):
renderer
=
TemplateHTMLRenderer
()
class
MockResponse
(
object
):
template_name
=
None
class
MockView
(
object
):
def
get_template_names
(
self
):
return
[
'template from get_template_names method'
]
class
MockView2
(
object
):
template_name
=
'template from template_name attribute'
template_name
=
renderer
.
get_template_names
(
self
.
mock_response
,
MockView
())
assert
template_name
==
[
'template from get_template_names method'
]
template_name
=
renderer
.
get_template_names
(
self
.
mock_response
,
MockView2
())
assert
template_name
==
[
'template from template_name attribute'
]
def
test_get_template_names_raises_error_if_no_template_found
(
self
):
renderer
=
TemplateHTMLRenderer
()
with
pytest
.
raises
(
ImproperlyConfigured
):
renderer
.
get_template_names
(
self
.
mock_response
,
view
=
object
())
@override_settings
(
ROOT_URLCONF
=
'tests.test_htmlrenderer'
)
@override_settings
(
ROOT_URLCONF
=
'tests.test_htmlrenderer'
)
class
TemplateHTMLRendererExceptionTests
(
TestCase
):
class
TemplateHTMLRendererExceptionTests
(
TestCase
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment