<s> from django . template import TemplateDoesNotExist <EOL> from django . test import ( <EOL> Client , RequestFactory , SimpleTestCase , override_settings , <EOL> ) <EOL> from django . utils . translation import override <EOL> from django . views . csrf import CSRF_FAILURE_TEMPLATE_NAME , csrf_failure <EOL> @ override_settings ( ROOT_URLCONF = '<STR_LIT>' ) <EOL> class CsrfViewTests ( SimpleTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( CsrfViewTests , self ) . setUp ( ) <EOL> self . client = Client ( enforce_csrf_checks = True ) <EOL> @ override_settings ( <EOL> USE_I18N = True , <EOL> MIDDLEWARE_CLASSES = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] , <EOL> ) <EOL> def test_translation ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . post ( '<STR_LIT:/>' ) <EOL> self . assertContains ( response , "<STR_LIT>" , status_code = <NUM_LIT> ) <EOL> self . assertContains ( response , <EOL> "<STR_LIT>" , <EOL> status_code = <NUM_LIT> ) <EOL> with self . settings ( LANGUAGE_CODE = '<STR_LIT>' ) , override ( '<STR_LIT>' ) : <EOL> response = self . client . post ( '<STR_LIT:/>' ) <EOL> self . assertContains ( response , "<STR_LIT>" , status_code = <NUM_LIT> ) <EOL> self . assertContains ( response , <EOL> "<STR_LIT>" , <EOL> status_code = <NUM_LIT> ) <EOL> @ override_settings ( <EOL> SECURE_PROXY_SSL_HEADER = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> ) <EOL> def test_no_referer ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . post ( '<STR_LIT:/>' , HTTP_X_FORWARDED_PROTO = '<STR_LIT>' ) <EOL> self . assertContains ( response , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> status_code = <NUM_LIT> ) <EOL> def test_no_cookies ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . post ( '<STR_LIT:/>' ) <EOL> self . assertContains ( response , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> status_code = <NUM_LIT> ) <EOL> @ override_settings ( TEMPLATES = [ ] ) <EOL> def test_no_django_template_engine ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . post ( '<STR_LIT:/>' ) <EOL> self . assertContains ( response , "<STR_LIT>" , status_code = <NUM_LIT> ) <EOL> @ override_settings ( TEMPLATES = [ { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ <EOL> ( '<STR_LIT>' , { <EOL> CSRF_FAILURE_TEMPLATE_NAME : '<STR_LIT>' <EOL> } ) , <EOL> ] , <EOL> } , <EOL> } ] ) <EOL> def test_custom_template ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . post ( '<STR_LIT:/>' ) <EOL> self . assertContains ( response , "<STR_LIT>" , status_code = <NUM_LIT> ) <EOL> def test_custom_template_does_not_exist ( self ) : <EOL> """<STR_LIT>""" <EOL> factory = RequestFactory ( ) <EOL> request = factory . post ( '<STR_LIT:/>' ) <EOL> with self . assertRaises ( TemplateDoesNotExist ) : <EOL> csrf_failure ( request , template_name = "<STR_LIT>" ) </s>
