<s> from django . conf import settings <EOL> from django . contrib . auth . models import User <EOL> from django . contrib . flatpages . models import FlatPage <EOL> from django . contrib . sites . models import Site <EOL> from django . test import TestCase , modify_settings , override_settings <EOL> from . settings import FLATPAGES_TEMPLATES <EOL> class TestDataMixin ( object ) : <EOL> @ classmethod <EOL> def setUpTestData ( cls ) : <EOL> cls . site1 = Site ( pk = <NUM_LIT:1> , domain = '<STR_LIT>' , name = '<STR_LIT>' ) <EOL> cls . site1 . save ( ) <EOL> cls . fp1 = FlatPage . objects . create ( <EOL> url = '<STR_LIT>' , title = '<STR_LIT>' , content = "<STR_LIT>" , <EOL> enable_comments = False , template_name = '<STR_LIT>' , registration_required = False <EOL> ) <EOL> cls . fp2 = FlatPage . objects . create ( <EOL> url = '<STR_LIT>' , title = '<STR_LIT>' , content = "<STR_LIT>" , <EOL> enable_comments = False , template_name = '<STR_LIT>' , registration_required = False <EOL> ) <EOL> cls . fp3 = FlatPage . objects . create ( <EOL> url = '<STR_LIT>' , title = '<STR_LIT>' , content = "<STR_LIT>" , <EOL> enable_comments = False , template_name = '<STR_LIT>' , registration_required = True <EOL> ) <EOL> cls . fp4 = FlatPage . objects . create ( <EOL> url = '<STR_LIT>' , title = '<STR_LIT>' , content = "<STR_LIT>" , <EOL> enable_comments = False , template_name = '<STR_LIT>' , registration_required = True <EOL> ) <EOL> cls . fp1 . sites . add ( cls . site1 ) <EOL> cls . fp2 . sites . add ( cls . site1 ) <EOL> cls . fp3 . sites . add ( cls . site1 ) <EOL> cls . fp4 . sites . add ( cls . site1 ) <EOL> @ modify_settings ( INSTALLED_APPS = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> @ override_settings ( <EOL> LOGIN_URL = '<STR_LIT>' , <EOL> MIDDLEWARE_CLASSES = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] , <EOL> ROOT_URLCONF = '<STR_LIT>' , <EOL> TEMPLATES = FLATPAGES_TEMPLATES , <EOL> SITE_ID = <NUM_LIT:1> , <EOL> ) <EOL> class FlatpageMiddlewareTests ( TestDataMixin , TestCase ) : <EOL> def test_view_flatpage ( self ) : <EOL> "<STR_LIT>" <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertContains ( response , "<STR_LIT>" ) <EOL> def test_view_non_existent_flatpage ( self ) : <EOL> "<STR_LIT>" <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_view_authenticated_flatpage ( self ) : <EOL> "<STR_LIT>" <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertRedirects ( response , '<STR_LIT>' ) <EOL> user = User . objects . create_user ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . client . force_login ( user ) <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertContains ( response , "<STR_LIT>" ) <EOL> def test_fallback_flatpage ( self ) : <EOL> "<STR_LIT>" <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertContains ( response , "<STR_LIT>" ) <EOL> def test_fallback_non_existent_flatpage ( self ) : <EOL> "<STR_LIT>" <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_fallback_authenticated_flatpage ( self ) : <EOL> "<STR_LIT>" <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertRedirects ( response , '<STR_LIT>' ) <EOL> user = User . objects . create_user ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . client . force_login ( user ) <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertContains ( response , "<STR_LIT>" ) <EOL> def test_fallback_flatpage_special_chars ( self ) : <EOL> "<STR_LIT>" <EOL> fp = FlatPage . objects . create ( <EOL> url = "<STR_LIT>" , <EOL> title = "<STR_LIT>" , <EOL> content = "<STR_LIT>" , <EOL> enable_comments = False , <EOL> registration_required = False , <EOL> ) <EOL> fp . sites . add ( settings . SITE_ID ) <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertContains ( response , "<STR_LIT>" ) <EOL> @ modify_settings ( INSTALLED_APPS = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> @ override_settings ( <EOL> APPEND_SLASH = True , <EOL> LOGIN_URL = '<STR_LIT>' , <EOL> MIDDLEWARE_CLASSES = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] , <EOL> ROOT_URLCONF = '<STR_LIT>' , <EOL> TEMPLATES = FLATPAGES_TEMPLATES , <EOL> SITE_ID = <NUM_LIT:1> , <EOL> ) <EOL> class FlatpageMiddlewareAppendSlashTests ( TestDataMixin , TestCase ) : <EOL> def test_redirect_view_flatpage ( self ) : <EOL> "<STR_LIT>" <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertRedirects ( response , '<STR_LIT>' , status_code = <NUM_LIT> ) <EOL> def test_redirect_view_non_existent_flatpage ( self ) : <EOL> "<STR_LIT>" <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_redirect_fallback_flatpage ( self ) : <EOL> "<STR_LIT>" <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertRedirects ( response , '<STR_LIT>' , status_code = <NUM_LIT> ) <EOL> def test_redirect_fallback_non_existent_flatpage ( self ) : <EOL> "<STR_LIT>" <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_redirect_fallback_flatpage_special_chars ( self ) : <EOL> "<STR_LIT>" <EOL> fp = FlatPage . objects . create ( <EOL> url = "<STR_LIT>" , <EOL> title = "<STR_LIT>" , <EOL> content = "<STR_LIT>" , <EOL> enable_comments = False , <EOL> registration_required = False , <EOL> ) <EOL> fp . sites . add ( settings . SITE_ID ) <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertRedirects ( response , '<STR_LIT>' , status_code = <NUM_LIT> ) <EOL> def test_redirect_fallback_flatpage_root ( self ) : <EOL> "<STR_LIT>" <EOL> fp = FlatPage . objects . create ( <EOL> url = "<STR_LIT:/>" , <EOL> title = "<STR_LIT>" , <EOL> content = "<STR_LIT>" , <EOL> enable_comments = False , <EOL> registration_required = False , <EOL> ) <EOL> fp . sites . add ( settings . SITE_ID ) <EOL> response = self . client . get ( '<STR_LIT:/>' ) <EOL> self . assertContains ( response , "<STR_LIT>" ) </s>
