<s> from __future__ import unicode_literals <EOL> import django . template . loader <EOL> from django . conf . urls import url <EOL> from django . core . exceptions import PermissionDenied <EOL> from django . http import Http404 <EOL> from django . template import Template , TemplateDoesNotExist <EOL> from django . test import TestCase <EOL> from django . utils import six <EOL> from rest_framework import status <EOL> from rest_framework . decorators import api_view , renderer_classes <EOL> from rest_framework . renderers import TemplateHTMLRenderer <EOL> from rest_framework . response import Response <EOL> @ api_view ( ( '<STR_LIT:GET>' , ) ) <EOL> @ renderer_classes ( ( TemplateHTMLRenderer , ) ) <EOL> def example ( request ) : <EOL> """<STR_LIT>""" <EOL> data = { '<STR_LIT:object>' : '<STR_LIT>' } <EOL> return Response ( data , template_name = '<STR_LIT>' ) <EOL> @ api_view ( ( '<STR_LIT:GET>' , ) ) <EOL> @ renderer_classes ( ( TemplateHTMLRenderer , ) ) <EOL> def permission_denied ( request ) : <EOL> raise PermissionDenied ( ) <EOL> @ api_view ( ( '<STR_LIT:GET>' , ) ) <EOL> @ renderer_classes ( ( TemplateHTMLRenderer , ) ) <EOL> def not_found ( request ) : <EOL> raise Http404 ( ) <EOL> urlpatterns = [ <EOL> url ( r'<STR_LIT>' , example ) , <EOL> url ( r'<STR_LIT>' , permission_denied ) , <EOL> url ( r'<STR_LIT>' , not_found ) , <EOL> ] <EOL> class TemplateHTMLRendererTests ( TestCase ) : <EOL> urls = '<STR_LIT>' <EOL> def setUp ( self ) : <EOL> """<STR_LIT>""" <EOL> self . get_template = django . template . loader . get_template <EOL> def get_template ( template_name , dirs = None ) : <EOL> if template_name == '<STR_LIT>' : <EOL> return Template ( "<STR_LIT>" ) <EOL> raise TemplateDoesNotExist ( template_name ) <EOL> def select_template ( template_name_list , dirs = None , using = None ) : <EOL> if template_name_list == [ '<STR_LIT>' ] : <EOL> return Template ( "<STR_LIT>" ) <EOL> raise TemplateDoesNotExist ( template_name_list [ <NUM_LIT:0> ] ) <EOL> django . template . loader . get_template = get_template <EOL> django . template . loader . select_template = select_template <EOL> def tearDown ( self ) : <EOL> """<STR_LIT>""" <EOL> django . template . loader . get_template = self . get_template <EOL> def test_simple_html_view ( self ) : <EOL> response = self . client . get ( '<STR_LIT:/>' ) <EOL> self . assertContains ( response , "<STR_LIT>" ) <EOL> self . assertEqual ( response [ '<STR_LIT:Content-Type>' ] , '<STR_LIT>' ) <EOL> def test_not_found_html_view ( self ) : <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , status . HTTP_404_NOT_FOUND ) <EOL> self . assertEqual ( response . content , six . b ( "<STR_LIT>" ) ) <EOL> self . assertEqual ( response [ '<STR_LIT:Content-Type>' ] , '<STR_LIT>' ) <EOL> def test_permission_denied_html_view ( self ) : <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , status . HTTP_403_FORBIDDEN ) <EOL> self . assertEqual ( response . content , six . b ( "<STR_LIT>" ) ) <EOL> self . assertEqual ( response [ '<STR_LIT:Content-Type>' ] , '<STR_LIT>' ) <EOL> class TemplateHTMLRendererExceptionTests ( TestCase ) : <EOL> urls = '<STR_LIT>' <EOL> def setUp ( self ) : <EOL> """<STR_LIT>""" <EOL> self . get_template = django . template . loader . get_template <EOL> def get_template ( template_name ) : <EOL> if template_name == '<STR_LIT>' : <EOL> return Template ( "<STR_LIT>" ) <EOL> if template_name == '<STR_LIT>' : <EOL> return Template ( "<STR_LIT>" ) <EOL> raise TemplateDoesNotExist ( template_name ) <EOL> django . template . loader . get_template = get_template <EOL> def tearDown ( self ) : <EOL> """<STR_LIT>""" <EOL> django . template . loader . get_template = self . get_template <EOL> def test_not_found_html_view_with_template ( self ) : <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , status . HTTP_404_NOT_FOUND ) <EOL> self . assertTrue ( response . content in ( <EOL> six . b ( "<STR_LIT>" ) , six . b ( "<STR_LIT>" ) ) ) <EOL> self . assertEqual ( response [ '<STR_LIT:Content-Type>' ] , '<STR_LIT>' ) <EOL> def test_permission_denied_html_view_with_template ( self ) : <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , status . HTTP_403_FORBIDDEN ) <EOL> self . assertTrue ( response . content in ( <EOL> six . b ( "<STR_LIT>" ) , six . b ( "<STR_LIT>" ) ) ) <EOL> self . assertEqual ( response [ '<STR_LIT:Content-Type>' ] , '<STR_LIT>' ) </s>
