<s> import sys <EOL> from django . contrib . admin . models import CHANGE , LogEntry <EOL> from django . contrib . auth import get_user_model <EOL> from django . contrib . auth . models import Permission <EOL> from django . contrib . contenttypes . models import ContentType <EOL> from django . core . urlresolvers import clear_url_caches , reverse , resolve <EOL> from django . test . utils import override_settings <EOL> from django . utils import six <EOL> from django . utils . timezone import now <EOL> from cms . api import create_page , create_title <EOL> from cms . app_base import CMSApp <EOL> from cms . apphook_pool import apphook_pool <EOL> from cms . appresolver import applications_page_check , clear_app_resolvers , get_app_patterns <EOL> from cms . cms_toolbars import PlaceholderToolbar <EOL> from cms . models import Title , Page <EOL> from cms . test_utils . project . placeholderapp . models import Example1 <EOL> from cms . test_utils . testcases import CMSTestCase <EOL> from cms . tests . test_menu_utils import DumbPageLanguageUrl <EOL> from cms . toolbar . toolbar import CMSToolbar <EOL> from cms . utils . conf import get_cms_setting <EOL> from cms . utils . i18n import force_language <EOL> from cms . utils . urlutils import admin_reverse <EOL> from menus . utils import DefaultLanguageChanger <EOL> APP_NAME = '<STR_LIT>' <EOL> NS_APP_NAME = '<STR_LIT>' <EOL> APP_MODULE = "<STR_LIT>" <EOL> class ApphooksTestCase ( CMSTestCase ) : <EOL> def setUp ( self ) : <EOL> clear_app_resolvers ( ) <EOL> clear_url_caches ( ) <EOL> if APP_MODULE in sys . modules : <EOL> del sys . modules [ APP_MODULE ] <EOL> self . reload_urls ( ) <EOL> self . apphook_clear ( ) <EOL> def tearDown ( self ) : <EOL> clear_app_resolvers ( ) <EOL> clear_url_caches ( ) <EOL> if APP_MODULE in sys . modules : <EOL> del sys . modules [ APP_MODULE ] <EOL> self . reload_urls ( ) <EOL> self . apphook_clear ( ) <EOL> def reload_urls ( self ) : <EOL> from django . conf import settings <EOL> url_modules = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> settings . ROOT_URLCONF , <EOL> ] <EOL> clear_app_resolvers ( ) <EOL> clear_url_caches ( ) <EOL> for module in url_modules : <EOL> if module in sys . modules : <EOL> del sys . modules [ module ] <EOL> def _fake_logentry ( self , instance_id , user , text , model = Page ) : <EOL> LogEntry . objects . log_action ( <EOL> user_id = user . id , <EOL> content_type_id = ContentType . objects . get_for_model ( model ) . pk , <EOL> object_id = instance_id , <EOL> object_repr = text , <EOL> action_flag = CHANGE , <EOL> ) <EOL> entry = LogEntry . objects . filter ( user = user , action_flag__in = ( CHANGE , ) ) [ <NUM_LIT:0> ] <EOL> session = self . client . session <EOL> session [ '<STR_LIT>' ] = entry . pk <EOL> session . save ( ) <EOL> def create_base_structure ( self , apphook , title_langs , namespace = None ) : <EOL> self . apphook_clear ( ) <EOL> superuser = get_user_model ( ) . objects . create_superuser ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . superuser = superuser <EOL> page = create_page ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> created_by = superuser , published = True ) <EOL> create_title ( '<STR_LIT>' , page . get_title ( ) , page ) <EOL> page . publish ( '<STR_LIT>' ) <EOL> child_page = create_page ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> created_by = superuser , published = True , parent = page ) <EOL> create_title ( '<STR_LIT>' , child_page . get_title ( ) , child_page ) <EOL> child_page . publish ( '<STR_LIT>' ) <EOL> child_child_page = create_page ( "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , created_by = superuser , published = True , parent = child_page , apphook = apphook , <EOL> apphook_namespace = namespace ) <EOL> create_title ( "<STR_LIT>" , child_child_page . get_title ( ) , child_child_page ) <EOL> child_child_page . publish ( '<STR_LIT>' ) <EOL> child_child_page = self . reload ( child_child_page ) <EOL> if isinstance ( title_langs , six . string_types ) : <EOL> titles = child_child_page . publisher_public . get_title_obj ( title_langs ) <EOL> else : <EOL> titles = [ child_child_page . publisher_public . get_title_obj ( l ) for l in title_langs ] <EOL> self . reload_urls ( ) <EOL> return titles <EOL> @ override_settings ( CMS_APPHOOKS = [ '<STR_LIT>' % ( APP_MODULE , APP_NAME ) ] ) <EOL> def test_explicit_apphooks ( self ) : <EOL> """<STR_LIT>""" <EOL> self . apphook_clear ( ) <EOL> hooks = apphook_pool . get_apphooks ( ) <EOL> app_names = [ hook [ <NUM_LIT:0> ] for hook in hooks ] <EOL> self . assertEqual ( len ( hooks ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( app_names , [ APP_NAME ] ) <EOL> self . apphook_clear ( ) <EOL> @ override_settings ( <EOL> INSTALLED_APPS = [ '<STR_LIT>' ] , <EOL> ROOT_URLCONF = '<STR_LIT>' , <EOL> ) <EOL> def test_implicit_apphooks ( self ) : <EOL> """<STR_LIT>""" <EOL> self . apphook_clear ( ) <EOL> hooks = apphook_pool . get_apphooks ( ) <EOL> app_names = [ hook [ <NUM_LIT:0> ] for hook in hooks ] <EOL> self . assertEqual ( len ( hooks ) , <NUM_LIT:6> ) <EOL> self . assertIn ( NS_APP_NAME , app_names ) <EOL> self . assertIn ( APP_NAME , app_names ) <EOL> self . apphook_clear ( ) <EOL> def test_apphook_on_root ( self ) : <EOL> self . apphook_clear ( ) <EOL> superuser = get_user_model ( ) . objects . create_superuser ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> page = create_page ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> created_by = superuser , published = True , apphook = "<STR_LIT>" ) <EOL> blank_page = create_page ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> created_by = superuser , published = True , apphook = "<STR_LIT>" , slug = '<STR_LIT>' ) <EOL> english_title = page . title_set . all ( ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( english_title . language , '<STR_LIT>' ) <EOL> create_title ( "<STR_LIT>" , "<STR_LIT>" , page ) <EOL> self . assertTrue ( page . publish ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( page . publish ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( blank_page . publish ( '<STR_LIT>' ) ) <EOL> with force_language ( "<STR_LIT>" ) : <EOL> response = self . client . get ( self . get_pages_root ( ) ) <EOL> self . assertTemplateUsed ( response , '<STR_LIT>' ) <EOL> self . assertContains ( response , '<STR_LIT>' ) <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertTemplateUsed ( response , '<STR_LIT>' ) <EOL> self . apphook_clear ( ) <EOL> @ override_settings ( ROOT_URLCONF = '<STR_LIT>' ) <EOL> def test_apphook_on_root_reverse ( self ) : <EOL> self . apphook_clear ( ) <EOL> superuser = get_user_model ( ) . objects . create_superuser ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> page = create_page ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> created_by = superuser , published = True , apphook = "<STR_LIT>" ) <EOL> create_title ( "<STR_LIT>" , "<STR_LIT>" , page ) <EOL> self . assertTrue ( page . publish ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( page . publish ( '<STR_LIT>' ) ) <EOL> self . reload_urls ( ) <EOL> self . assertFalse ( reverse ( '<STR_LIT>' ) . startswith ( '<STR_LIT>' ) ) <EOL> self . apphook_clear ( ) <EOL> @ override_settings ( ROOT_URLCONF = '<STR_LIT>' ) <EOL> def test_get_page_for_apphook ( self ) : <EOL> en_title , de_title = self . create_base_structure ( APP_NAME , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> with force_language ( "<STR_LIT>" ) : <EOL> path = reverse ( '<STR_LIT>' ) <EOL> request = self . get_request ( path ) <EOL> request . LANGUAGE_CODE = '<STR_LIT>' <EOL> attached_to_page = applications_page_check ( request , path = path [ <NUM_LIT:1> : ] ) <EOL> self . assertEqual ( attached_to_page . pk , en_title . page . pk ) <EOL> response = self . client . get ( path ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( response , '<STR_LIT>' ) <EOL> self . assertContains ( response , en_title . title ) <EOL> with force_language ( "<STR_LIT>" ) : <EOL> path = reverse ( '<STR_LIT>' ) <EOL> request = self . get_request ( path ) <EOL> request . LANGUAGE_CODE = '<STR_LIT>' <EOL> attached_to_page = applications_page_check ( request , path = path [ <NUM_LIT:1> : ] ) <EOL> self . assertEqual ( attached_to_page . pk , de_title . page . pk ) <EOL> response = self . client . get ( path ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( response , '<STR_LIT>' ) <EOL> self . assertContains ( response , de_title . title ) <EOL> self . apphook_clear ( ) <EOL> @ override_settings ( ROOT_URLCONF = '<STR_LIT>' ) <EOL> def test_apphook_permissions ( self ) : <EOL> en_title , de_title = self . create_base_structure ( APP_NAME , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> with force_language ( "<STR_LIT>" ) : <EOL> path = reverse ( '<STR_LIT>' ) <EOL> response = self . client . get ( path ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> page = en_title . page . publisher_public <EOL> page . login_required = True <EOL> page . save ( ) <EOL> page . publish ( '<STR_LIT>' ) <EOL> response = self . client . get ( path ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . apphook_clear ( ) <EOL> @ override_settings ( ROOT_URLCONF = '<STR_LIT>' ) <EOL> def test_apphook_permissions_preserves_view_name ( self ) : <EOL> self . create_base_structure ( APP_NAME , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> view_names = ( <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ) <EOL> with force_language ( "<STR_LIT>" ) : <EOL> for url_name , view_name in view_names : <EOL> path = reverse ( url_name ) <EOL> match = resolve ( path ) <EOL> self . assertEqual ( match . func . __name__ , view_name ) <EOL> def test_apphooks_with_excluded_permissions ( self ) : <EOL> en_title = self . create_base_structure ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> with force_language ( "<STR_LIT>" ) : <EOL> excluded_path = reverse ( '<STR_LIT>' ) <EOL> not_excluded_path = reverse ( '<STR_LIT>' ) <EOL> page = en_title . page . publisher_public <EOL> page . login_required = True <EOL> page . save ( ) <EOL> page . publish ( '<STR_LIT>' ) <EOL> excluded_response = self . client . get ( excluded_path ) <EOL> not_excluded_response = self . client . get ( not_excluded_path ) <EOL> self . assertEqual ( excluded_response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( not_excluded_response . status_code , <NUM_LIT> ) <EOL> self . apphook_clear ( ) <EOL> @ override_settings ( ROOT_URLCONF = '<STR_LIT>' ) <EOL> def test_get_page_for_apphook_on_preview_or_edit ( self ) : <EOL> if get_user_model ( ) . USERNAME_FIELD == '<STR_LIT:email>' : <EOL> superuser = get_user_model ( ) . objects . create_superuser ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> else : <EOL> superuser = get_user_model ( ) . objects . create_superuser ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> page = create_page ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> created_by = superuser , published = True , apphook = APP_NAME ) <EOL> create_title ( '<STR_LIT>' , page . get_title ( ) , page ) <EOL> page . publish ( '<STR_LIT>' ) <EOL> page . publish ( '<STR_LIT>' ) <EOL> page . save ( ) <EOL> public_page = page . get_public_object ( ) <EOL> with self . login_user_context ( superuser ) : <EOL> with force_language ( "<STR_LIT>" ) : <EOL> path = reverse ( '<STR_LIT>' ) <EOL> request = self . get_request ( path + '<STR_LIT>' % get_cms_setting ( '<STR_LIT>' ) ) <EOL> request . LANGUAGE_CODE = '<STR_LIT>' <EOL> attached_to_page = applications_page_check ( request , path = path [ <NUM_LIT:1> : ] ) <EOL> response = self . client . get ( path + "<STR_LIT>" ) <EOL> self . assertContains ( response , '<STR_LIT>' ) <EOL> with force_language ( "<STR_LIT>" ) : <EOL> path = reverse ( '<STR_LIT>' ) <EOL> request = self . get_request ( path + '<STR_LIT>' % get_cms_setting ( '<STR_LIT>' ) ) <EOL> request . LANGUAGE_CODE = '<STR_LIT>' <EOL> attached_to_page = applications_page_check ( request , path = path [ <NUM_LIT:1> : ] ) <EOL> self . assertEqual ( attached_to_page . pk , public_page . pk ) <EOL> @ override_settings ( ROOT_URLCONF = '<STR_LIT>' ) <EOL> def test_get_root_page_for_apphook_with_instance_namespace ( self ) : <EOL> en_title = self . create_base_structure ( NS_APP_NAME , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . reload_urls ( ) <EOL> with force_language ( "<STR_LIT>" ) : <EOL> reverse ( "<STR_LIT>" ) <EOL> reverse ( "<STR_LIT>" ) <EOL> reverse ( "<STR_LIT>" ) <EOL> path = reverse ( '<STR_LIT>' ) <EOL> path_instance = reverse ( '<STR_LIT>' ) <EOL> self . assertEqual ( path , path_instance ) <EOL> request = self . get_request ( path ) <EOL> request . LANGUAGE_CODE = '<STR_LIT>' <EOL> attached_to_page = applications_page_check ( request , path = path [ <NUM_LIT:1> : ] ) <EOL> self . assertEqual ( attached_to_page . pk , en_title . page . pk ) <EOL> self . apphook_clear ( ) <EOL> @ override_settings ( ROOT_URLCONF = '<STR_LIT>' ) <EOL> def test_get_child_page_for_apphook_with_instance_namespace ( self ) : <EOL> en_title = self . create_base_structure ( NS_APP_NAME , '<STR_LIT>' , '<STR_LIT>' ) <EOL> with force_language ( "<STR_LIT>" ) : <EOL> path = reverse ( '<STR_LIT>' ) <EOL> path_instance1 = reverse ( '<STR_LIT>' ) <EOL> path_instance2 = reverse ( '<STR_LIT>' , current_app = '<STR_LIT>' ) <EOL> self . assertEqual ( path , path_instance1 ) <EOL> self . assertEqual ( path , path_instance2 ) <EOL> request = self . get_request ( path ) <EOL> request . LANGUAGE_CODE = '<STR_LIT>' <EOL> attached_to_page = applications_page_check ( request , path = path [ <NUM_LIT:1> : ] ) <EOL> self . assertEqual ( attached_to_page . pk , en_title . page_id ) <EOL> self . apphook_clear ( ) <EOL> @ override_settings ( ROOT_URLCONF = '<STR_LIT>' ) <EOL> def test_get_sub_page_for_apphook_with_implicit_current_app ( self ) : <EOL> en_title = self . create_base_structure ( NS_APP_NAME , '<STR_LIT>' , '<STR_LIT>' ) <EOL> with force_language ( "<STR_LIT>" ) : <EOL> path = reverse ( '<STR_LIT>' ) <EOL> request = self . get_request ( path ) <EOL> request . LANGUAGE_CODE = '<STR_LIT>' <EOL> attached_to_page = applications_page_check ( request , path = path [ <NUM_LIT:1> : ] ) <EOL> self . assertEqual ( attached_to_page . pk , en_title . page . pk ) <EOL> response = self . client . get ( path ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( response , '<STR_LIT>' ) <EOL> self . assertContains ( response , '<STR_LIT>' ) <EOL> self . assertContains ( response , path ) <EOL> self . apphook_clear ( ) <EOL> @ override_settings ( ROOT_URLCONF = '<STR_LIT>' ) <EOL> def test_default_language_changer_with_implicit_current_app ( self ) : <EOL> self . create_base_structure ( NS_APP_NAME , [ '<STR_LIT>' , '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . reload_urls ( ) <EOL> with force_language ( "<STR_LIT>" ) : <EOL> path = reverse ( '<STR_LIT>' ) <EOL> request = self . get_request ( path ) <EOL> request . LANGUAGE_CODE = '<STR_LIT>' <EOL> url = DefaultLanguageChanger ( request ) ( '<STR_LIT>' ) <EOL> self . assertEqual ( url , path ) <EOL> url = DefaultLanguageChanger ( request ) ( '<STR_LIT>' ) <EOL> self . assertEqual ( url , '<STR_LIT>' % path [ <NUM_LIT:3> : ] . replace ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> self . apphook_clear ( ) <EOL> @ override_settings ( ROOT_URLCONF = '<STR_LIT>' ) <EOL> def test_get_i18n_apphook_with_explicit_current_app ( self ) : <EOL> titles = self . create_base_structure ( NS_APP_NAME , [ '<STR_LIT>' , '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> public_de_title = titles [ <NUM_LIT:1> ] <EOL> de_title = Title . objects . get ( page = public_de_title . page . publisher_draft , language = "<STR_LIT>" ) <EOL> de_title . slug = "<STR_LIT>" <EOL> de_title . save ( ) <EOL> de_title . page . publish ( '<STR_LIT>' ) <EOL> page2 = create_page ( "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , created_by = self . superuser , published = True , parent = de_title . page . parent , <EOL> apphook = NS_APP_NAME , <EOL> apphook_namespace = "<STR_LIT>" ) <EOL> create_title ( "<STR_LIT>" , "<STR_LIT>" , page2 , slug = "<STR_LIT>" ) <EOL> page2 . publish ( '<STR_LIT>' ) <EOL> clear_app_resolvers ( ) <EOL> clear_url_caches ( ) <EOL> if APP_MODULE in sys . modules : <EOL> del sys . modules [ APP_MODULE ] <EOL> self . reload_urls ( ) <EOL> with force_language ( "<STR_LIT>" ) : <EOL> reverse ( '<STR_LIT>' , current_app = "<STR_LIT>" ) <EOL> reverse ( '<STR_LIT>' , current_app = "<STR_LIT>" ) <EOL> reverse ( '<STR_LIT>' ) <EOL> with force_language ( "<STR_LIT>" ) : <EOL> reverse ( '<STR_LIT>' , current_app = "<STR_LIT>" ) <EOL> reverse ( '<STR_LIT>' , current_app = "<STR_LIT>" ) <EOL> reverse ( '<STR_LIT>' ) <EOL> @ override_settings ( ROOT_URLCONF = '<STR_LIT>' ) <EOL> def test_apphook_include_extra_parameters ( self ) : <EOL> self . create_base_structure ( NS_APP_NAME , [ '<STR_LIT>' , '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> with force_language ( "<STR_LIT>" ) : <EOL> path = reverse ( '<STR_LIT>' ) <EOL> request = self . get_request ( path ) <EOL> request . LANGUAGE_CODE = '<STR_LIT>' <EOL> response = self . client . get ( path ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( response , '<STR_LIT>' ) <EOL> self . assertContains ( response , '<STR_LIT>' ) <EOL> @ override_settings ( ROOT_URLCONF = '<STR_LIT>' ) <EOL> def test_get_sub_page_for_apphook_with_explicit_current_app ( self ) : <EOL> en_title = self . create_base_structure ( NS_APP_NAME , '<STR_LIT>' , '<STR_LIT>' ) <EOL> with force_language ( "<STR_LIT>" ) : <EOL> path = reverse ( '<STR_LIT>' ) <EOL> request = self . get_request ( path ) <EOL> request . LANGUAGE_CODE = '<STR_LIT>' <EOL> attached_to_page = applications_page_check ( request , path = path [ <NUM_LIT:1> : ] ) <EOL> self . assertEqual ( attached_to_page . pk , en_title . page . pk ) <EOL> response = self . client . get ( path ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( response , '<STR_LIT>' ) <EOL> self . assertContains ( response , '<STR_LIT>' ) <EOL> self . assertContains ( response , path ) <EOL> self . apphook_clear ( ) <EOL> @ override_settings ( ROOT_URLCONF = '<STR_LIT>' ) <EOL> def test_include_urlconf ( self ) : <EOL> self . create_base_structure ( APP_NAME , '<STR_LIT>' ) <EOL> path = reverse ( '<STR_LIT>' ) <EOL> response = self . client . get ( path ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( response , '<STR_LIT>' ) <EOL> self . assertContains ( response , "<STR_LIT>" ) <EOL> path = reverse ( '<STR_LIT>' ) <EOL> response = self . client . get ( path ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( response , '<STR_LIT>' ) <EOL> self . assertContains ( response , "<STR_LIT>" ) <EOL> with force_language ( "<STR_LIT>" ) : <EOL> path = reverse ( '<STR_LIT>' ) <EOL> response = self . client . get ( path ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( response , '<STR_LIT>' ) <EOL> self . assertContains ( response , "<STR_LIT>" ) <EOL> with force_language ( "<STR_LIT>" ) : <EOL> path = reverse ( '<STR_LIT>' ) <EOL> response = self . client . get ( path ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( response , '<STR_LIT>' ) <EOL> self . assertContains ( response , "<STR_LIT>" ) <EOL> self . apphook_clear ( ) <EOL> @ override_settings ( CMS_PERMISSION = False , ROOT_URLCONF = '<STR_LIT>' ) <EOL> def test_apphook_breaking_under_home_with_new_path_caching ( self ) : <EOL> home = create_page ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , published = True ) <EOL> child = create_page ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , published = True , parent = home ) <EOL> not_home = create_page ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , published = True , parent = child ) <EOL> create_page ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , published = True , parent = not_home , apphook = '<STR_LIT>' ) <EOL> with force_language ( "<STR_LIT>" ) : <EOL> self . reload_urls ( ) <EOL> urlpatterns = get_app_patterns ( ) <EOL> resolver = urlpatterns [ <NUM_LIT:0> ] <EOL> url = resolver . reverse ( '<STR_LIT>' ) <EOL> self . assertEqual ( url , '<STR_LIT>' ) <EOL> @ override_settings ( ROOT_URLCONF = '<STR_LIT>' ) <EOL> def test_apphook_urlpattern_order ( self ) : <EOL> self . create_base_structure ( APP_NAME , '<STR_LIT>' ) <EOL> path = reverse ( '<STR_LIT>' ) <EOL> response = self . client . get ( path ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( response , '<STR_LIT>' ) <EOL> self . assertContains ( response , "<STR_LIT>" ) <EOL> @ override_settings ( ROOT_URLCONF = '<STR_LIT>' ) <EOL> def test_apphooks_receive_url_params ( self ) : <EOL> self . create_base_structure ( APP_NAME , '<STR_LIT>' ) <EOL> path = reverse ( '<STR_LIT>' , kwargs = dict ( my_params = '<STR_LIT>' ) ) <EOL> response = self . client . get ( path ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( response , '<STR_LIT>' ) <EOL> self . assertContains ( response , '<STR_LIT>' ) <EOL> @ override_settings ( ROOT_URLCONF = '<STR_LIT>' ) <EOL> def test_multiple_apphooks ( self ) : <EOL> self . apphook_clear ( ) <EOL> superuser = get_user_model ( ) . objects . create_superuser ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> create_page ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , created_by = superuser , published = True , ) <EOL> create_page ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> created_by = superuser , published = True , apphook = "<STR_LIT>" ) <EOL> create_page ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> created_by = superuser , published = True , apphook = "<STR_LIT>" ) <EOL> reverse ( '<STR_LIT>' ) <EOL> reverse ( '<STR_LIT>' ) <EOL> self . apphook_clear ( ) <EOL> def test_apphook_pool_register_returns_apphook ( self ) : <EOL> @ apphook_pool . register <EOL> class TestApp ( CMSApp ) : <EOL> name = "<STR_LIT>" <EOL> self . assertIsNotNone ( TestApp ) <EOL> apphook_pool . apphooks . append ( "<STR_LIT:foo>" ) <EOL> @ apphook_pool . register <EOL> class TestApp2 ( CMSApp ) : <EOL> name = "<STR_LIT>" <EOL> self . assertIsNotNone ( TestApp2 ) <EOL> @ override_settings ( ROOT_URLCONF = '<STR_LIT>' ) <EOL> def test_toolbar_current_app_namespace ( self ) : <EOL> self . create_base_structure ( NS_APP_NAME , '<STR_LIT>' , '<STR_LIT>' ) <EOL> with force_language ( "<STR_LIT>" ) : <EOL> path = reverse ( '<STR_LIT>' ) <EOL> request = self . get_request ( path ) <EOL> toolbar = CMSToolbar ( request ) <EOL> self . assertTrue ( toolbar . toolbars [ '<STR_LIT>' ] . is_current_app ) <EOL> self . assertFalse ( toolbar . toolbars [ '<STR_LIT>' ] . is_current_app ) <EOL> with force_language ( "<STR_LIT>" ) : <EOL> path = reverse ( '<STR_LIT>' ) <EOL> request = self . get_request ( path ) <EOL> toolbar = CMSToolbar ( request ) <EOL> self . assertEqual ( toolbar . toolbars [ '<STR_LIT>' ] . app_path , <EOL> '<STR_LIT>' ) <EOL> self . assertTrue ( toolbar . toolbars [ '<STR_LIT>' ] . is_current_app ) <EOL> self . assertEqual ( toolbar . toolbars [ '<STR_LIT>' ] . app_path , <EOL> '<STR_LIT>' ) <EOL> self . assertFalse ( toolbar . toolbars [ '<STR_LIT>' ] . is_current_app ) <EOL> @ override_settings ( ROOT_URLCONF = '<STR_LIT>' ) <EOL> def test_toolbar_current_app_apphook_with_implicit_current_app ( self ) : <EOL> self . create_base_structure ( NS_APP_NAME , '<STR_LIT>' , '<STR_LIT>' ) <EOL> with force_language ( "<STR_LIT>" ) : <EOL> path = reverse ( '<STR_LIT>' ) <EOL> request = self . get_request ( path ) <EOL> toolbar = CMSToolbar ( request ) <EOL> self . assertEqual ( toolbar . toolbars [ '<STR_LIT>' ] . app_path , <EOL> '<STR_LIT>' ) <EOL> self . assertTrue ( toolbar . toolbars [ '<STR_LIT>' ] . is_current_app ) <EOL> self . assertEqual ( toolbar . toolbars [ '<STR_LIT>' ] . app_path , <EOL> '<STR_LIT>' ) <EOL> self . assertFalse ( toolbar . toolbars [ '<STR_LIT>' ] . is_current_app ) <EOL> @ override_settings ( ROOT_URLCONF = '<STR_LIT>' ) <EOL> def test_toolbar_no_namespace ( self ) : <EOL> self . create_base_structure ( APP_NAME , '<STR_LIT>' ) <EOL> path = reverse ( '<STR_LIT>' , kwargs = { '<STR_LIT:id>' : <NUM_LIT:20> } ) <EOL> request = self . get_request ( path ) <EOL> toolbar = CMSToolbar ( request ) <EOL> self . assertFalse ( toolbar . toolbars [ '<STR_LIT>' ] . is_current_app ) <EOL> self . assertFalse ( toolbar . toolbars [ '<STR_LIT>' ] . is_current_app ) <EOL> self . assertTrue ( toolbar . toolbars [ '<STR_LIT>' ] . is_current_app ) <EOL> @ override_settings ( ROOT_URLCONF = '<STR_LIT>' ) <EOL> def test_toolbar_multiple_supported_apps ( self ) : <EOL> self . create_base_structure ( APP_NAME , '<STR_LIT>' ) <EOL> path = reverse ( '<STR_LIT>' , kwargs = { '<STR_LIT:id>' : <NUM_LIT:20> } ) <EOL> request = self . get_request ( path ) <EOL> toolbar = CMSToolbar ( request ) <EOL> self . assertEqual ( toolbar . toolbars [ '<STR_LIT>' ] . app_path , <EOL> '<STR_LIT>' ) <EOL> self . assertFalse ( toolbar . toolbars [ '<STR_LIT>' ] . is_current_app ) <EOL> self . assertEqual ( toolbar . toolbars [ '<STR_LIT>' ] . app_path , <EOL> '<STR_LIT>' ) <EOL> self . assertFalse ( toolbar . toolbars [ '<STR_LIT>' ] . is_current_app ) <EOL> self . assertEqual ( toolbar . toolbars [ '<STR_LIT>' ] . app_path , <EOL> '<STR_LIT>' ) <EOL> self . assertTrue ( toolbar . toolbars [ '<STR_LIT>' ] . is_current_app ) <EOL> self . assertEqual ( toolbar . toolbars [ '<STR_LIT>' ] . app_path , <EOL> '<STR_LIT>' ) <EOL> self . assertTrue ( toolbar . toolbars [ '<STR_LIT>' ] . is_current_app ) <EOL> @ override_settings ( <EOL> CMS_APPHOOKS = [ '<STR_LIT>' ] , <EOL> ROOT_URLCONF = '<STR_LIT>' , <EOL> ) <EOL> def test_toolbar_staff ( self ) : <EOL> apphooks = ( <EOL> '<STR_LIT>' , <EOL> ) <EOL> with self . settings ( CMS_APPHOOKS = apphooks , ROOT_URLCONF = '<STR_LIT>' ) : <EOL> self . create_base_structure ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> ex1 = Example1 . objects . create ( char_1 = '<STR_LIT:1>' , char_2 = '<STR_LIT:2>' , char_3 = '<STR_LIT:3>' , char_4 = '<STR_LIT:4>' , date_field = now ( ) ) <EOL> path = reverse ( '<STR_LIT>' , kwargs = { '<STR_LIT>' : ex1 . pk } ) <EOL> self . user = self . _create_user ( '<STR_LIT>' , True , True ) <EOL> with self . login_user_context ( self . user ) : <EOL> response = self . client . get ( path + "<STR_LIT>" ) <EOL> toolbar = CMSToolbar ( response . context [ '<STR_LIT>' ] ) <EOL> toolbar . populate ( ) <EOL> placeholder_toolbar = PlaceholderToolbar ( response . context [ '<STR_LIT>' ] , toolbar , True , path ) <EOL> placeholder_toolbar . populate ( ) <EOL> placeholder_toolbar . init_placeholders_from_request ( ) <EOL> placeholder_toolbar . add_structure_mode ( ) <EOL> self . assertEqual ( len ( placeholder_toolbar . toolbar . get_right_items ( ) ) , <NUM_LIT:1> ) <EOL> self . user = self . _create_user ( '<STR_LIT>' , True , False ) <EOL> with self . login_user_context ( self . user ) : <EOL> response = self . client . get ( path + "<STR_LIT>" ) <EOL> response . context [ '<STR_LIT>' ] . user = get_user_model ( ) . objects . get ( pk = self . user . pk ) <EOL> toolbar = CMSToolbar ( response . context [ '<STR_LIT>' ] ) <EOL> toolbar . populate ( ) <EOL> placeholder_toolbar = PlaceholderToolbar ( response . context [ '<STR_LIT>' ] , toolbar , True , path ) <EOL> placeholder_toolbar . populate ( ) <EOL> placeholder_toolbar . init_placeholders_from_request ( ) <EOL> placeholder_toolbar . add_structure_mode ( ) <EOL> self . assertEqual ( len ( placeholder_toolbar . toolbar . get_right_items ( ) ) , <NUM_LIT:0> ) <EOL> self . user . user_permissions . add ( Permission . objects . get ( codename = '<STR_LIT>' ) ) <EOL> with self . login_user_context ( self . user ) : <EOL> response = self . client . get ( path + "<STR_LIT>" ) <EOL> response . context [ '<STR_LIT>' ] . user = get_user_model ( ) . objects . get ( pk = self . user . pk ) <EOL> toolbar = CMSToolbar ( response . context [ '<STR_LIT>' ] ) <EOL> toolbar . populate ( ) <EOL> placeholder_toolbar = PlaceholderToolbar ( response . context [ '<STR_LIT>' ] , toolbar , True , path ) <EOL> placeholder_toolbar . populate ( ) <EOL> placeholder_toolbar . init_placeholders_from_request ( ) <EOL> placeholder_toolbar . add_structure_mode ( ) <EOL> self . assertEqual ( len ( placeholder_toolbar . toolbar . get_right_items ( ) ) , <NUM_LIT:0> ) <EOL> permission = Permission . objects . get ( codename = '<STR_LIT>' ) <EOL> self . user . user_permissions . add ( permission ) <EOL> response . context [ '<STR_LIT>' ] . user = get_user_model ( ) . objects . get ( pk = self . user . pk ) <EOL> placeholder_toolbar = PlaceholderToolbar ( response . context [ '<STR_LIT>' ] , toolbar , True , path ) <EOL> placeholder_toolbar . populate ( ) <EOL> placeholder_toolbar . init_placeholders_from_request ( ) <EOL> placeholder_toolbar . add_structure_mode ( ) <EOL> self . assertEqual ( len ( placeholder_toolbar . toolbar . get_right_items ( ) ) , <NUM_LIT:1> ) <EOL> self . user = None <EOL> def test_page_edit_redirect_models ( self ) : <EOL> apphooks = ( <EOL> '<STR_LIT>' , <EOL> ) <EOL> ex1 = Example1 . objects . create ( char_1 = "<STR_LIT>" , char_2 = "<STR_LIT>" , <EOL> char_3 = "<STR_LIT>" , char_4 = "<STR_LIT>" ) <EOL> with self . settings ( CMS_APPHOOKS = apphooks , ROOT_URLCONF = '<STR_LIT>' ) : <EOL> self . create_base_structure ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> url = admin_reverse ( '<STR_LIT>' ) <EOL> self . user = self . _create_user ( '<STR_LIT>' , True , True ) <EOL> with self . login_user_context ( self . user ) : <EOL> response = self . client . post ( url , { '<STR_LIT>' : ex1 . pk , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . content . decode ( '<STR_LIT:utf-8>' ) , ex1 . get_absolute_url ( ) ) <EOL> def test_nested_apphooks_urls ( self ) : <EOL> with self . settings ( ROOT_URLCONF = '<STR_LIT>' ) : <EOL> self . apphook_clear ( ) <EOL> superuser = get_user_model ( ) . objects . create_superuser ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> create_page ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , created_by = superuser , published = True , ) <EOL> parent_page = create_page ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> created_by = superuser , published = True , apphook = "<STR_LIT>" ) <EOL> create_page ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , parent = parent_page , <EOL> created_by = superuser , published = True , apphook = "<STR_LIT>" ) <EOL> parent_app_path = reverse ( '<STR_LIT>' , kwargs = { '<STR_LIT:path>' : '<STR_LIT>' } ) <EOL> child_app_path = reverse ( '<STR_LIT>' , kwargs = { '<STR_LIT:path>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( parent_app_path , '<STR_LIT>' ) <EOL> self . assertEqual ( child_app_path , '<STR_LIT>' ) <EOL> response = self . client . get ( parent_app_path ) <EOL> self . assertContains ( response , '<STR_LIT>' , status_code = <NUM_LIT:200> ) <EOL> response = self . client . get ( child_app_path ) <EOL> self . assertContains ( response , '<STR_LIT>' , status_code = <NUM_LIT:200> ) <EOL> self . apphook_clear ( ) <EOL> class ApphooksPageLanguageUrlTestCase ( CMSTestCase ) : <EOL> def setUp ( self ) : <EOL> clear_app_resolvers ( ) <EOL> clear_url_caches ( ) <EOL> if APP_MODULE in sys . modules : <EOL> del sys . modules [ APP_MODULE ] <EOL> self . reload_urls ( ) <EOL> def tearDown ( self ) : <EOL> clear_app_resolvers ( ) <EOL> clear_url_caches ( ) <EOL> if APP_MODULE in sys . modules : <EOL> del sys . modules [ APP_MODULE ] <EOL> self . apphook_clear ( ) <EOL> def reload_urls ( self ) : <EOL> from django . conf import settings <EOL> url_modules = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> settings . ROOT_URLCONF , <EOL> ] <EOL> clear_app_resolvers ( ) <EOL> clear_url_caches ( ) <EOL> for module in url_modules : <EOL> if module in sys . modules : <EOL> del sys . modules [ module ] <EOL> def test_page_language_url_for_apphook ( self ) : <EOL> self . apphook_clear ( ) <EOL> superuser = get_user_model ( ) . objects . create_superuser ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> page = create_page ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> created_by = superuser ) <EOL> create_title ( '<STR_LIT>' , page . get_title ( ) , page ) <EOL> page . publish ( '<STR_LIT>' ) <EOL> page . publish ( '<STR_LIT>' ) <EOL> child_page = create_page ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> created_by = superuser , parent = page ) <EOL> create_title ( '<STR_LIT>' , child_page . get_title ( ) , child_page ) <EOL> child_page . publish ( '<STR_LIT>' ) <EOL> child_page . publish ( '<STR_LIT>' ) <EOL> child_child_page = create_page ( "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , created_by = superuser , parent = child_page , apphook = '<STR_LIT>' ) <EOL> create_title ( "<STR_LIT>" , '<STR_LIT>' % child_child_page . get_title ( ) , child_child_page ) <EOL> child_child_page . publish ( '<STR_LIT>' ) <EOL> child_child_page . publish ( '<STR_LIT>' ) <EOL> child_child_page = self . reload ( child_child_page ) <EOL> with force_language ( "<STR_LIT>" ) : <EOL> path = reverse ( '<STR_LIT>' ) <EOL> request = self . get_request ( path ) <EOL> request . LANGUAGE_CODE = '<STR_LIT>' <EOL> request . current_page = child_child_page <EOL> fake_context = { '<STR_LIT>' : request } <EOL> tag = DumbPageLanguageUrl ( ) <EOL> output = tag . get_context ( fake_context , '<STR_LIT>' ) <EOL> url = output [ '<STR_LIT:content>' ] <EOL> self . assertEqual ( url , '<STR_LIT>' ) <EOL> output = tag . get_context ( fake_context , '<STR_LIT>' ) <EOL> url = output [ '<STR_LIT:content>' ] <EOL> self . assertEqual ( url , '<STR_LIT>' ) <EOL> output = tag . get_context ( fake_context , '<STR_LIT>' ) <EOL> url = output [ '<STR_LIT:content>' ] <EOL> self . assertEqual ( url , '<STR_LIT>' ) <EOL> self . apphook_clear ( ) </s>
