<s> import uuid <EOL> from cms . test_utils . project . sampleapp . cms_apps import SampleApp <EOL> from cms . test_utils . util . context_managers import apphooks <EOL> from django . conf import settings <EOL> from django . contrib . sites . models import Site <EOL> from django . core import management <EOL> from django . core . management import CommandError <EOL> from django . test . utils import override_settings <EOL> from django . utils . six . moves import StringIO <EOL> from cms . api import create_page , add_plugin , create_title <EOL> from cms . management . commands . subcommands . list import plugin_report <EOL> from cms . models import Page , StaticPlaceholder <EOL> from cms . models . placeholdermodel import Placeholder <EOL> from cms . models . pluginmodel import CMSPlugin <EOL> from cms . test_utils . fixtures . navextenders import NavextendersFixture <EOL> from cms . test_utils . testcases import CMSTestCase <EOL> from djangocms_text_ckeditor . cms_plugins import TextPlugin <EOL> APPHOOK = "<STR_LIT>" <EOL> PLUGIN = "<STR_LIT>" <EOL> TEST_INSTALLED_APPS = [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ] + settings . PLUGIN_APPS <EOL> if settings . AUTH_USER_MODEL == "<STR_LIT>" : <EOL> TEST_INSTALLED_APPS . append ( "<STR_LIT>" ) <EOL> if settings . AUTH_USER_MODEL == "<STR_LIT>" : <EOL> TEST_INSTALLED_APPS . append ( "<STR_LIT>" ) <EOL> class ManagementTestCase ( CMSTestCase ) : <EOL> @ override_settings ( INSTALLED_APPS = TEST_INSTALLED_APPS ) <EOL> def test_list_apphooks ( self ) : <EOL> with apphooks ( SampleApp ) : <EOL> out = StringIO ( ) <EOL> create_page ( '<STR_LIT>' , "<STR_LIT>" , "<STR_LIT>" , apphook = APPHOOK ) <EOL> self . assertEqual ( Page . objects . filter ( application_urls = APPHOOK ) . count ( ) , <NUM_LIT:1> ) <EOL> management . call_command ( <EOL> "<STR_LIT>" , <EOL> "<STR_LIT:list>" , <EOL> "<STR_LIT>" , <EOL> interactive = False , <EOL> stdout = out , <EOL> ) <EOL> self . assertEqual ( out . getvalue ( ) , "<STR_LIT>" ) <EOL> def test_uninstall_apphooks_without_apphook ( self ) : <EOL> with apphooks ( ) : <EOL> out = StringIO ( ) <EOL> management . call_command ( <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> APPHOOK , <EOL> interactive = False , <EOL> stdout = out , <EOL> ) <EOL> self . assertEqual ( out . getvalue ( ) , "<STR_LIT>" ) <EOL> def test_fix_tree ( self ) : <EOL> create_page ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> page1 = create_page ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> page1 . depth = <NUM_LIT:3> <EOL> page1 . numchild = <NUM_LIT:4> <EOL> page1 . path = "<STR_LIT>" <EOL> page1 . save ( ) <EOL> out = StringIO ( ) <EOL> management . call_command ( '<STR_LIT>' , '<STR_LIT>' , interactive = False , stdout = out ) <EOL> self . assertEqual ( out . getvalue ( ) , '<STR_LIT>' ) <EOL> page1 = page1 . reload ( ) <EOL> self . assertEqual ( page1 . path , "<STR_LIT>" ) <EOL> self . assertEqual ( page1 . depth , <NUM_LIT:1> ) <EOL> self . assertEqual ( page1 . numchild , <NUM_LIT:0> ) <EOL> @ override_settings ( INSTALLED_APPS = TEST_INSTALLED_APPS ) <EOL> def test_uninstall_apphooks_with_apphook ( self ) : <EOL> with apphooks ( SampleApp ) : <EOL> out = StringIO ( ) <EOL> create_page ( '<STR_LIT>' , "<STR_LIT>" , "<STR_LIT>" , apphook = APPHOOK ) <EOL> self . assertEqual ( Page . objects . filter ( application_urls = APPHOOK ) . count ( ) , <NUM_LIT:1> ) <EOL> management . call_command ( <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> APPHOOK , <EOL> interactive = False , <EOL> stdout = out , <EOL> ) <EOL> self . assertEqual ( out . getvalue ( ) , "<STR_LIT>" ) <EOL> self . assertEqual ( Page . objects . filter ( application_urls = APPHOOK ) . count ( ) , <NUM_LIT:0> ) <EOL> @ override_settings ( INSTALLED_APPS = TEST_INSTALLED_APPS ) <EOL> def test_list_plugins ( self ) : <EOL> out = StringIO ( ) <EOL> placeholder = Placeholder . objects . create ( slot = "<STR_LIT:test>" ) <EOL> add_plugin ( placeholder , TextPlugin , "<STR_LIT>" , body = "<STR_LIT>" ) <EOL> add_plugin ( placeholder , TextPlugin , "<STR_LIT>" , body = "<STR_LIT>" ) <EOL> link_plugin = add_plugin ( placeholder , "<STR_LIT>" , "<STR_LIT>" , <EOL> name = "<STR_LIT>" , url = "<STR_LIT>" ) <EOL> self . assertEqual ( <EOL> CMSPlugin . objects . filter ( plugin_type = PLUGIN ) . count ( ) , <EOL> <NUM_LIT:2> ) <EOL> self . assertEqual ( <EOL> CMSPlugin . objects . filter ( plugin_type = "<STR_LIT>" ) . count ( ) , <EOL> <NUM_LIT:1> ) <EOL> instanceless_plugin = CMSPlugin ( language = "<STR_LIT>" , plugin_type = "<STR_LIT>" ) <EOL> instanceless_plugin . save ( ) <EOL> bogus_plugin = CMSPlugin ( language = "<STR_LIT>" , plugin_type = "<STR_LIT>" ) <EOL> bogus_plugin . save ( ) <EOL> management . call_command ( '<STR_LIT>' , '<STR_LIT:list>' , '<STR_LIT>' , interactive = False , stdout = out ) <EOL> report = plugin_report ( ) <EOL> self . assertEqual ( <EOL> len ( report ) , <EOL> <NUM_LIT:3> ) <EOL> bogus_plugins_report = report [ <NUM_LIT:0> ] <EOL> self . assertEqual ( <EOL> bogus_plugins_report [ "<STR_LIT>" ] , <EOL> None ) <EOL> self . assertEqual ( <EOL> bogus_plugins_report [ "<STR_LIT:type>" ] , <EOL> u'<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> bogus_plugins_report [ "<STR_LIT>" ] [ <NUM_LIT:0> ] , <EOL> bogus_plugin ) <EOL> link_plugins_report = report [ <NUM_LIT:1> ] <EOL> self . assertEqual ( <EOL> link_plugins_report [ "<STR_LIT>" ] , <EOL> link_plugin . __class__ ) <EOL> self . assertEqual ( <EOL> link_plugins_report [ "<STR_LIT:type>" ] , <EOL> u'<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> link_plugins_report [ "<STR_LIT>" ] [ <NUM_LIT:0> ] . get_plugin_instance ( ) [ <NUM_LIT:0> ] , <EOL> link_plugin ) <EOL> text_plugins_report = report [ <NUM_LIT:2> ] <EOL> self . assertEqual ( <EOL> text_plugins_report [ "<STR_LIT>" ] , <EOL> TextPlugin . model ) <EOL> self . assertEqual ( <EOL> text_plugins_report [ "<STR_LIT:type>" ] , <EOL> u'<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> len ( text_plugins_report [ "<STR_LIT>" ] ) , <EOL> <NUM_LIT:3> ) <EOL> self . assertEqual ( <EOL> text_plugins_report [ "<STR_LIT>" ] [ <NUM_LIT:2> ] , <EOL> instanceless_plugin ) <EOL> self . assertEqual ( <EOL> text_plugins_report [ "<STR_LIT>" ] , <EOL> [ instanceless_plugin ] ) <EOL> @ override_settings ( INSTALLED_APPS = TEST_INSTALLED_APPS ) <EOL> def test_delete_orphaned_plugins ( self ) : <EOL> placeholder = Placeholder . objects . create ( slot = "<STR_LIT:test>" ) <EOL> add_plugin ( placeholder , TextPlugin , "<STR_LIT>" , body = "<STR_LIT>" ) <EOL> add_plugin ( placeholder , TextPlugin , "<STR_LIT>" , body = "<STR_LIT>" ) <EOL> add_plugin ( placeholder , "<STR_LIT>" , "<STR_LIT>" , <EOL> name = "<STR_LIT>" , url = "<STR_LIT>" ) <EOL> instanceless_plugin = CMSPlugin ( <EOL> language = "<STR_LIT>" , plugin_type = "<STR_LIT>" ) <EOL> instanceless_plugin . save ( ) <EOL> bogus_plugin = CMSPlugin ( language = "<STR_LIT>" , plugin_type = "<STR_LIT>" ) <EOL> bogus_plugin . save ( ) <EOL> report = plugin_report ( ) <EOL> self . assertEqual ( <EOL> len ( report ) , <EOL> <NUM_LIT:3> ) <EOL> bogus_plugins_report = report [ <NUM_LIT:0> ] <EOL> self . assertEqual ( <EOL> len ( bogus_plugins_report [ "<STR_LIT>" ] ) , <EOL> <NUM_LIT:1> ) <EOL> link_plugins_report = report [ <NUM_LIT:1> ] <EOL> self . assertEqual ( <EOL> len ( link_plugins_report [ "<STR_LIT>" ] ) , <EOL> <NUM_LIT:1> ) <EOL> text_plugins_report = report [ <NUM_LIT:2> ] <EOL> self . assertEqual ( <EOL> len ( text_plugins_report [ "<STR_LIT>" ] ) , <EOL> <NUM_LIT:3> ) <EOL> self . assertEqual ( <EOL> len ( text_plugins_report [ "<STR_LIT>" ] ) , <EOL> <NUM_LIT:1> ) <EOL> out = StringIO ( ) <EOL> management . call_command ( '<STR_LIT>' , '<STR_LIT>' , interactive = False , stdout = out ) <EOL> report = plugin_report ( ) <EOL> self . assertEqual ( <EOL> len ( report ) , <EOL> <NUM_LIT:2> ) <EOL> link_plugins_report = report [ <NUM_LIT:0> ] <EOL> self . assertEqual ( <EOL> len ( link_plugins_report [ "<STR_LIT>" ] ) , <EOL> <NUM_LIT:1> ) <EOL> text_plugins_report = report [ <NUM_LIT:1> ] <EOL> self . assertEqual ( <EOL> len ( text_plugins_report [ "<STR_LIT>" ] ) , <EOL> <NUM_LIT:2> ) <EOL> self . assertEqual ( <EOL> len ( text_plugins_report [ "<STR_LIT>" ] ) , <EOL> <NUM_LIT:0> ) <EOL> def test_uninstall_plugins_without_plugin ( self ) : <EOL> out = StringIO ( ) <EOL> management . call_command ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , PLUGIN , interactive = False , stdout = out ) <EOL> self . assertEqual ( out . getvalue ( ) , "<STR_LIT>" ) <EOL> @ override_settings ( INSTALLED_APPS = TEST_INSTALLED_APPS ) <EOL> def test_uninstall_plugins_with_plugin ( self ) : <EOL> out = StringIO ( ) <EOL> placeholder = Placeholder . objects . create ( slot = "<STR_LIT:test>" ) <EOL> add_plugin ( placeholder , TextPlugin , "<STR_LIT>" , body = "<STR_LIT>" ) <EOL> self . assertEqual ( CMSPlugin . objects . filter ( plugin_type = PLUGIN ) . count ( ) , <NUM_LIT:1> ) <EOL> management . call_command ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , PLUGIN , interactive = False , stdout = out ) <EOL> self . assertEqual ( out . getvalue ( ) , "<STR_LIT>" ) <EOL> self . assertEqual ( CMSPlugin . objects . filter ( plugin_type = PLUGIN ) . count ( ) , <NUM_LIT:0> ) <EOL> class PageFixtureManagementTestCase ( NavextendersFixture , CMSTestCase ) : <EOL> def _fill_page_body ( self , page , lang ) : <EOL> ph_en = page . placeholders . get ( slot = "<STR_LIT:body>" ) <EOL> mcol1 = add_plugin ( ph_en , "<STR_LIT>" , lang , position = "<STR_LIT>" ) <EOL> add_plugin ( ph_en , "<STR_LIT>" , lang , position = "<STR_LIT>" , target = mcol1 ) <EOL> col2 = add_plugin ( ph_en , "<STR_LIT>" , lang , position = "<STR_LIT>" , target = mcol1 ) <EOL> mcol2 = add_plugin ( ph_en , "<STR_LIT>" , lang , position = "<STR_LIT>" , target = col2 ) <EOL> add_plugin ( ph_en , "<STR_LIT>" , lang , position = "<STR_LIT>" , target = mcol2 ) <EOL> col4 = add_plugin ( ph_en , "<STR_LIT>" , lang , position = "<STR_LIT>" , target = mcol2 ) <EOL> add_plugin ( ph_en , "<STR_LIT>" , lang , target = col4 , <EOL> name = "<STR_LIT>" , url = "<STR_LIT>" ) <EOL> static_placeholder = StaticPlaceholder ( code = str ( uuid . uuid4 ( ) ) , site_id = <NUM_LIT:1> ) <EOL> static_placeholder . save ( ) <EOL> add_plugin ( static_placeholder . draft , "<STR_LIT>" , lang , body = "<STR_LIT>" ) <EOL> def setUp ( self ) : <EOL> pages = Page . objects . drafts ( ) <EOL> for page in pages : <EOL> self . _fill_page_body ( page , "<STR_LIT>" ) <EOL> def test_copy_langs ( self ) : <EOL> """<STR_LIT>""" <EOL> site = <NUM_LIT:1> <EOL> number_start_plugins = CMSPlugin . objects . all ( ) . count ( ) <EOL> out = StringIO ( ) <EOL> management . call_command ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , interactive = False , stdout = out <EOL> ) <EOL> pages = Page . objects . on_site ( site ) . drafts ( ) <EOL> for page in pages : <EOL> self . assertEqual ( set ( ( u'<STR_LIT>' , u'<STR_LIT>' ) ) , set ( page . get_languages ( ) ) ) <EOL> self . assertEqual ( CMSPlugin . objects . all ( ) . count ( ) , number_start_plugins * <NUM_LIT:2> ) <EOL> self . assertEqual ( CMSPlugin . objects . filter ( language = '<STR_LIT>' ) . count ( ) , number_start_plugins ) <EOL> self . assertEqual ( CMSPlugin . objects . filter ( language = '<STR_LIT>' ) . count ( ) , number_start_plugins ) <EOL> root_page = Page . objects . on_site ( site ) . get_home ( ) <EOL> root_plugins = CMSPlugin . objects . filter ( placeholder = root_page . placeholders . get ( slot = "<STR_LIT:body>" ) ) <EOL> first_plugin_en , _ = root_plugins . get ( language = '<STR_LIT>' , parent = None ) . get_plugin_instance ( ) <EOL> first_plugin_de , _ = root_plugins . get ( language = '<STR_LIT>' , parent = None ) . get_plugin_instance ( ) <EOL> self . assertEqual ( first_plugin_en . plugin_type , first_plugin_de . plugin_type ) <EOL> link_en , _ = root_plugins . get ( language = '<STR_LIT>' , plugin_type = '<STR_LIT>' ) . get_plugin_instance ( ) <EOL> link_de , _ = root_plugins . get ( language = '<STR_LIT>' , plugin_type = '<STR_LIT>' ) . get_plugin_instance ( ) <EOL> self . assertEqual ( link_en . url , link_de . url ) <EOL> self . assertEqual ( link_en . get_position_in_placeholder ( ) , link_de . get_position_in_placeholder ( ) ) <EOL> stack_plugins = CMSPlugin . objects . filter ( placeholder = StaticPlaceholder . objects . order_by ( '<STR_LIT:?>' ) [ <NUM_LIT:0> ] . draft ) <EOL> stack_text_en , _ = stack_plugins . get ( language = '<STR_LIT>' , plugin_type = '<STR_LIT>' ) . get_plugin_instance ( ) <EOL> stack_text_de , _ = stack_plugins . get ( language = '<STR_LIT>' , plugin_type = '<STR_LIT>' ) . get_plugin_instance ( ) <EOL> self . assertEqual ( stack_text_en . plugin_type , stack_text_de . plugin_type ) <EOL> self . assertEqual ( stack_text_en . body , stack_text_de . body ) <EOL> def test_copy_langs_no_content ( self ) : <EOL> """<STR_LIT>""" <EOL> site = <NUM_LIT:1> <EOL> number_start_plugins = CMSPlugin . objects . all ( ) . count ( ) <EOL> out = StringIO ( ) <EOL> management . call_command ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> interactive = False , stdout = out <EOL> ) <EOL> pages = Page . objects . on_site ( site ) . drafts ( ) <EOL> for page in pages : <EOL> self . assertEqual ( set ( ( u'<STR_LIT>' , u'<STR_LIT>' ) ) , set ( page . get_languages ( ) ) ) <EOL> self . assertEqual ( CMSPlugin . objects . all ( ) . count ( ) , number_start_plugins ) <EOL> self . assertEqual ( CMSPlugin . objects . filter ( language = '<STR_LIT>' ) . count ( ) , number_start_plugins ) <EOL> self . assertEqual ( CMSPlugin . objects . filter ( language = '<STR_LIT>' ) . count ( ) , <NUM_LIT:0> ) <EOL> root_page = Page . objects . on_site ( site ) . get_home ( ) <EOL> root_plugins = CMSPlugin . objects . filter ( <EOL> placeholder = root_page . placeholders . get ( slot = "<STR_LIT:body>" ) ) <EOL> first_plugin_en , _ = root_plugins . get ( language = '<STR_LIT>' , parent = None ) . get_plugin_instance ( ) <EOL> first_plugin_de = None <EOL> with self . assertRaises ( CMSPlugin . DoesNotExist ) : <EOL> first_plugin_de , _ = root_plugins . get ( language = '<STR_LIT>' , parent = None ) . get_plugin_instance ( ) <EOL> self . assertIsNone ( first_plugin_de ) <EOL> stack_plugins = CMSPlugin . objects . filter ( <EOL> placeholder = StaticPlaceholder . objects . order_by ( '<STR_LIT:?>' ) [ <NUM_LIT:0> ] . draft ) <EOL> stack_text_en , _ = stack_plugins . get ( language = '<STR_LIT>' , <EOL> plugin_type = '<STR_LIT>' ) . get_plugin_instance ( ) <EOL> with self . assertRaises ( CMSPlugin . DoesNotExist ) : <EOL> stack_text_de , _ = stack_plugins . get ( language = '<STR_LIT>' , <EOL> plugin_type = '<STR_LIT>' ) . get_plugin_instance ( ) <EOL> def test_copy_sites ( self ) : <EOL> """<STR_LIT>""" <EOL> site_1_pk = <NUM_LIT:1> <EOL> site_2 = Site . objects . create ( name = '<STR_LIT>' ) <EOL> site_2_pk = site_2 . pk <EOL> phs = [ ] <EOL> for page in Page . objects . on_site ( site_1_pk ) . drafts ( ) : <EOL> phs . extend ( page . placeholders . values_list ( '<STR_LIT>' , flat = True ) ) <EOL> number_start_plugins = CMSPlugin . objects . filter ( placeholder__in = phs ) . count ( ) <EOL> out = StringIO ( ) <EOL> management . call_command ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' % site_1_pk , '<STR_LIT>' % site_2_pk , <EOL> stdout = out <EOL> ) <EOL> for page in Page . objects . on_site ( site_1_pk ) . drafts ( ) : <EOL> page . publish ( '<STR_LIT>' ) <EOL> for page in Page . objects . on_site ( site_2_pk ) . drafts ( ) : <EOL> page . publish ( '<STR_LIT>' ) <EOL> pages_1 = list ( Page . objects . on_site ( site_1_pk ) . drafts ( ) ) <EOL> pages_2 = list ( Page . objects . on_site ( site_2_pk ) . drafts ( ) ) <EOL> for index , page in enumerate ( pages_1 ) : <EOL> self . assertEqual ( page . get_title ( '<STR_LIT>' ) , pages_2 [ index ] . get_title ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( page . depth , pages_2 [ index ] . depth ) <EOL> phs_1 = [ ] <EOL> phs_2 = [ ] <EOL> for page in Page . objects . on_site ( site_1_pk ) . drafts ( ) : <EOL> phs_1 . extend ( page . placeholders . values_list ( '<STR_LIT>' , flat = True ) ) <EOL> for page in Page . objects . on_site ( site_2_pk ) . drafts ( ) : <EOL> phs_2 . extend ( page . placeholders . values_list ( '<STR_LIT>' , flat = True ) ) <EOL> self . assertEqual ( CMSPlugin . objects . filter ( placeholder__in = phs_1 ) . count ( ) , number_start_plugins ) <EOL> self . assertEqual ( CMSPlugin . objects . filter ( placeholder__in = phs_2 ) . count ( ) , number_start_plugins ) <EOL> root_page_1 = Page . objects . on_site ( site_1_pk ) . get_home ( site_1_pk ) <EOL> root_page_2 = Page . objects . on_site ( site_2_pk ) . get_home ( site_2_pk ) <EOL> root_plugins_1 = CMSPlugin . objects . filter ( placeholder = root_page_1 . placeholders . get ( slot = "<STR_LIT:body>" ) ) <EOL> root_plugins_2 = CMSPlugin . objects . filter ( placeholder = root_page_2 . placeholders . get ( slot = "<STR_LIT:body>" ) ) <EOL> first_plugin_1 , _ = root_plugins_1 . get ( language = '<STR_LIT>' , parent = None ) . get_plugin_instance ( ) <EOL> first_plugin_2 , _ = root_plugins_2 . get ( language = '<STR_LIT>' , parent = None ) . get_plugin_instance ( ) <EOL> self . assertEqual ( first_plugin_1 . plugin_type , first_plugin_2 . plugin_type ) <EOL> link_1 , _ = root_plugins_1 . get ( language = '<STR_LIT>' , plugin_type = '<STR_LIT>' ) . get_plugin_instance ( ) <EOL> link_2 , _ = root_plugins_2 . get ( language = '<STR_LIT>' , plugin_type = '<STR_LIT>' ) . get_plugin_instance ( ) <EOL> self . assertEqual ( link_1 . url , link_2 . url ) <EOL> self . assertEqual ( link_1 . get_position_in_placeholder ( ) , link_2 . get_position_in_placeholder ( ) ) <EOL> def test_copy_existing_title ( self ) : <EOL> """<STR_LIT>""" <EOL> site = <NUM_LIT:1> <EOL> number_start_plugins = CMSPlugin . objects . all ( ) . count ( ) <EOL> root_page = Page . objects . on_site ( site ) . get_home ( ) <EOL> create_title ( "<STR_LIT>" , "<STR_LIT>" , root_page ) <EOL> out = StringIO ( ) <EOL> management . call_command ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , interactive = False , stdout = out <EOL> ) <EOL> pages = Page . objects . on_site ( site ) . drafts ( ) <EOL> for page in pages : <EOL> self . assertEqual ( set ( ( u'<STR_LIT>' , u'<STR_LIT>' ) ) , set ( page . get_languages ( ) ) ) <EOL> self . assertEqual ( "<STR_LIT>" , Page . objects . on_site ( site ) . get_home ( ) . get_title ( "<STR_LIT>" ) ) <EOL> self . assertEqual ( CMSPlugin . objects . all ( ) . count ( ) , number_start_plugins * <NUM_LIT:2> ) <EOL> self . assertEqual ( CMSPlugin . objects . filter ( language = '<STR_LIT>' ) . count ( ) , number_start_plugins ) <EOL> self . assertEqual ( CMSPlugin . objects . filter ( language = '<STR_LIT>' ) . count ( ) , number_start_plugins ) <EOL> def test_copy_filled_placeholder ( self ) : <EOL> """<STR_LIT>""" <EOL> site = <NUM_LIT:1> <EOL> number_start_plugins = CMSPlugin . objects . all ( ) . count ( ) <EOL> root_page = Page . objects . on_site ( site ) . get_home ( ) <EOL> create_title ( "<STR_LIT>" , "<STR_LIT>" , root_page ) <EOL> ph = root_page . placeholders . get ( slot = "<STR_LIT:body>" ) <EOL> add_plugin ( ph , "<STR_LIT>" , "<STR_LIT>" , body = "<STR_LIT>" ) <EOL> out = StringIO ( ) <EOL> management . call_command ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , interactive = False , stdout = out <EOL> ) <EOL> self . assertEqual ( CMSPlugin . objects . filter ( language = '<STR_LIT>' ) . count ( ) , number_start_plugins ) <EOL> self . assertEqual ( CMSPlugin . objects . filter ( language = '<STR_LIT>' ) . count ( ) , number_start_plugins - <NUM_LIT:6> ) <EOL> def test_copy_filled_placeholder_force_copy ( self ) : <EOL> """<STR_LIT>""" <EOL> site = <NUM_LIT:1> <EOL> number_start_plugins = CMSPlugin . objects . all ( ) . count ( ) <EOL> root_page = Page . objects . on_site ( site ) . get_home ( ) <EOL> create_title ( "<STR_LIT>" , "<STR_LIT>" , root_page ) <EOL> ph = root_page . placeholders . get ( slot = "<STR_LIT:body>" ) <EOL> add_plugin ( ph , "<STR_LIT>" , "<STR_LIT>" , body = "<STR_LIT>" ) <EOL> root_plugins = CMSPlugin . objects . filter ( placeholder = ph ) <EOL> text_de_orig , _ = root_plugins . get ( language = '<STR_LIT>' , plugin_type = '<STR_LIT>' ) . get_plugin_instance ( ) <EOL> out = StringIO ( ) <EOL> management . call_command ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , interactive = False , <EOL> stdout = out <EOL> ) <EOL> CMSPlugin . objects . filter ( placeholder = root_page . placeholders . get ( slot = "<STR_LIT:body>" ) ) <EOL> self . assertEqual ( CMSPlugin . objects . filter ( language = '<STR_LIT>' ) . count ( ) , number_start_plugins ) <EOL> self . assertEqual ( CMSPlugin . objects . filter ( language = '<STR_LIT>' ) . count ( ) , number_start_plugins + <NUM_LIT:1> ) <EOL> def test_copy_from_non_existing_lang ( self ) : <EOL> """<STR_LIT>""" <EOL> site = <NUM_LIT:1> <EOL> out = StringIO ( ) <EOL> management . call_command ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , verbosity = <NUM_LIT:3> , <EOL> interactive = False , stdout = out <EOL> ) <EOL> text = out . getvalue ( ) <EOL> page_count = Page . objects . on_site ( site ) . drafts ( ) . count ( ) + <NUM_LIT:1> <EOL> for idx in range ( <NUM_LIT:1> , page_count ) : <EOL> self . assertTrue ( "<STR_LIT>" % idx in text ) <EOL> def test_copy_site_safe ( self ) : <EOL> """<STR_LIT>""" <EOL> site_other = <NUM_LIT:1> <EOL> site_active = <NUM_LIT:2> <EOL> origina_site1_langs = { } <EOL> number_start_plugins = CMSPlugin . objects . all ( ) . count ( ) <EOL> site_obj = Site . objects . create ( domain = "<STR_LIT>" , name = "<STR_LIT>" , pk = site_active ) <EOL> for page in Page . objects . on_site ( <NUM_LIT:1> ) . drafts ( ) : <EOL> origina_site1_langs [ page . pk ] = set ( page . get_languages ( ) ) <EOL> p1 = create_page ( '<STR_LIT>' , published = True , in_navigation = True , language = '<STR_LIT>' , template = '<STR_LIT>' , site = site_obj ) <EOL> create_page ( '<STR_LIT>' , published = True , in_navigation = True , language = '<STR_LIT>' , template = '<STR_LIT>' , site = site_obj ) <EOL> create_page ( '<STR_LIT>' , published = True , in_navigation = True , parent = p1 , language = '<STR_LIT>' , template = '<STR_LIT>' , site = site_obj ) <EOL> for page in Page . objects . on_site ( site_active ) . drafts ( ) : <EOL> self . _fill_page_body ( page , '<STR_LIT>' ) <EOL> number_site2_plugins = CMSPlugin . objects . all ( ) . count ( ) - number_start_plugins <EOL> out = StringIO ( ) <EOL> management . call_command ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' % site_active , <EOL> interactive = False , stdout = out <EOL> ) <EOL> for page in Page . objects . on_site ( site_other ) . drafts ( ) : <EOL> self . assertEqual ( origina_site1_langs [ page . pk ] , set ( page . get_languages ( ) ) ) <EOL> for page in Page . objects . on_site ( site_active ) . drafts ( ) : <EOL> self . assertEqual ( set ( ( '<STR_LIT>' , '<STR_LIT>' ) ) , set ( page . get_languages ( ) ) ) <EOL> self . assertEqual ( CMSPlugin . objects . filter ( language = '<STR_LIT>' ) . count ( ) , number_start_plugins ) <EOL> self . assertEqual ( CMSPlugin . objects . filter ( language = '<STR_LIT>' ) . count ( ) , number_site2_plugins ) <EOL> self . assertEqual ( CMSPlugin . objects . filter ( language = '<STR_LIT>' ) . count ( ) , number_site2_plugins ) <EOL> self . assertEqual ( CMSPlugin . objects . all ( ) . count ( ) , number_start_plugins + number_site2_plugins * <NUM_LIT:2> ) <EOL> def test_copy_bad_languages ( self ) : <EOL> out = StringIO ( ) <EOL> with self . assertRaises ( CommandError ) as command_error : <EOL> management . call_command ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , interactive = False , <EOL> stdout = out <EOL> ) <EOL> self . assertEqual ( str ( command_error . exception ) , '<STR_LIT>' ) </s>
