<s> from djangocms_text_ckeditor . models import Text <EOL> from django . contrib . auth import get_user_model <EOL> from django . contrib . sites . models import Site <EOL> from django . core . cache import cache <EOL> from django . core . management . base import CommandError <EOL> from django . core . management import call_command <EOL> from django . core . urlresolvers import reverse <EOL> from cms . api import create_page , add_plugin , create_title <EOL> from cms . constants import PUBLISHER_STATE_PENDING , PUBLISHER_STATE_DEFAULT , PUBLISHER_STATE_DIRTY <EOL> from cms . management . commands . subcommands . publisher_publish import PublishCommand <EOL> from cms . models import CMSPlugin , Title <EOL> from cms . models . pagemodel import Page <EOL> from cms . plugin_pool import plugin_pool <EOL> from cms . test_utils . testcases import CMSTestCase as TestCase <EOL> from cms . test_utils . util . context_managers import StdoutOverride <EOL> from cms . test_utils . util . fuzzy_int import FuzzyInt <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> class PublisherCommandTests ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_command_line_should_raise_without_superuser ( self ) : <EOL> with self . assertRaises ( CommandError ) : <EOL> com = PublishCommand ( ) <EOL> com . handle ( ) <EOL> def test_command_line_publishes_zero_pages_on_empty_db ( self ) : <EOL> get_user_model ( ) . objects . create_superuser ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> pages_from_output = <NUM_LIT:0> <EOL> published_from_output = <NUM_LIT:0> <EOL> with StdoutOverride ( ) as buffer : <EOL> call_command ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> lines = buffer . getvalue ( ) . split ( '<STR_LIT:\n>' ) <EOL> for line in lines : <EOL> if '<STR_LIT>' in line : <EOL> pages_from_output = int ( line . split ( '<STR_LIT::>' ) [ <NUM_LIT:1> ] ) <EOL> elif '<STR_LIT>' in line : <EOL> published_from_output = int ( line . split ( '<STR_LIT::>' ) [ <NUM_LIT:1> ] ) <EOL> self . assertEqual ( pages_from_output , <NUM_LIT:0> ) <EOL> self . assertEqual ( published_from_output , <NUM_LIT:0> ) <EOL> def test_command_line_ignores_draft_page ( self ) : <EOL> get_user_model ( ) . objects . create_superuser ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> create_page ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , published = False ) <EOL> pages_from_output = <NUM_LIT:0> <EOL> published_from_output = <NUM_LIT:0> <EOL> with StdoutOverride ( ) as buffer : <EOL> call_command ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> lines = buffer . getvalue ( ) . split ( '<STR_LIT:\n>' ) <EOL> for line in lines : <EOL> if '<STR_LIT>' in line : <EOL> pages_from_output = int ( line . split ( '<STR_LIT::>' ) [ <NUM_LIT:1> ] ) <EOL> elif '<STR_LIT>' in line : <EOL> published_from_output = int ( line . split ( '<STR_LIT::>' ) [ <NUM_LIT:1> ] ) <EOL> self . assertEqual ( pages_from_output , <NUM_LIT:0> ) <EOL> self . assertEqual ( published_from_output , <NUM_LIT:0> ) <EOL> self . assertEqual ( Page . objects . public ( ) . count ( ) , <NUM_LIT:0> ) <EOL> def test_command_line_publishes_draft_page ( self ) : <EOL> get_user_model ( ) . objects . create_superuser ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> create_page ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , published = False ) <EOL> pages_from_output = <NUM_LIT:0> <EOL> published_from_output = <NUM_LIT:0> <EOL> with StdoutOverride ( ) as buffer : <EOL> call_command ( '<STR_LIT>' , '<STR_LIT>' , include_unpublished = True ) <EOL> lines = buffer . getvalue ( ) . split ( '<STR_LIT:\n>' ) <EOL> for line in lines : <EOL> if '<STR_LIT>' in line : <EOL> pages_from_output = int ( line . split ( '<STR_LIT::>' ) [ <NUM_LIT:1> ] ) <EOL> elif '<STR_LIT>' in line : <EOL> published_from_output = int ( line . split ( '<STR_LIT::>' ) [ <NUM_LIT:1> ] ) <EOL> self . assertEqual ( pages_from_output , <NUM_LIT:1> ) <EOL> self . assertEqual ( published_from_output , <NUM_LIT:1> ) <EOL> self . assertEqual ( Page . objects . public ( ) . count ( ) , <NUM_LIT:1> ) <EOL> def test_command_line_publishes_selected_language ( self ) : <EOL> get_user_model ( ) . objects . create_superuser ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> page = create_page ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> title = create_title ( '<STR_LIT>' , '<STR_LIT>' , page ) <EOL> title . published = True <EOL> title . save ( ) <EOL> title = create_title ( '<STR_LIT>' , '<STR_LIT>' , page ) <EOL> title . published = True <EOL> title . save ( ) <EOL> pages_from_output = <NUM_LIT:0> <EOL> published_from_output = <NUM_LIT:0> <EOL> with StdoutOverride ( ) as buffer : <EOL> call_command ( '<STR_LIT>' , '<STR_LIT>' , language = '<STR_LIT>' ) <EOL> lines = buffer . getvalue ( ) . split ( '<STR_LIT:\n>' ) <EOL> for line in lines : <EOL> if '<STR_LIT>' in line : <EOL> pages_from_output = int ( line . split ( '<STR_LIT::>' ) [ <NUM_LIT:1> ] ) <EOL> elif '<STR_LIT>' in line : <EOL> published_from_output = int ( line . split ( '<STR_LIT::>' ) [ <NUM_LIT:1> ] ) <EOL> self . assertEqual ( pages_from_output , <NUM_LIT:1> ) <EOL> self . assertEqual ( published_from_output , <NUM_LIT:1> ) <EOL> self . assertEqual ( Page . objects . public ( ) . count ( ) , <NUM_LIT:1> ) <EOL> public = Page . objects . public ( ) [ <NUM_LIT:0> ] <EOL> languages = sorted ( public . title_set . values_list ( '<STR_LIT>' , flat = True ) ) <EOL> self . assertEqual ( languages , [ '<STR_LIT>' ] ) <EOL> def test_command_line_publishes_selected_language_drafts ( self ) : <EOL> get_user_model ( ) . objects . create_superuser ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> page = create_page ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> title = create_title ( '<STR_LIT>' , '<STR_LIT>' , page ) <EOL> title . published = False <EOL> title . save ( ) <EOL> title = create_title ( '<STR_LIT>' , '<STR_LIT>' , page ) <EOL> title . published = False <EOL> title . save ( ) <EOL> pages_from_output = <NUM_LIT:0> <EOL> published_from_output = <NUM_LIT:0> <EOL> with StdoutOverride ( ) as buffer : <EOL> call_command ( '<STR_LIT>' , '<STR_LIT>' , language = '<STR_LIT>' , include_unpublished = True ) <EOL> lines = buffer . getvalue ( ) . split ( '<STR_LIT:\n>' ) <EOL> for line in lines : <EOL> if '<STR_LIT>' in line : <EOL> pages_from_output = int ( line . split ( '<STR_LIT::>' ) [ <NUM_LIT:1> ] ) <EOL> elif '<STR_LIT>' in line : <EOL> published_from_output = int ( line . split ( '<STR_LIT::>' ) [ <NUM_LIT:1> ] ) <EOL> self . assertEqual ( pages_from_output , <NUM_LIT:1> ) <EOL> self . assertEqual ( published_from_output , <NUM_LIT:1> ) <EOL> self . assertEqual ( Page . objects . public ( ) . count ( ) , <NUM_LIT:1> ) <EOL> public = Page . objects . public ( ) [ <NUM_LIT:0> ] <EOL> languages = sorted ( public . title_set . values_list ( '<STR_LIT>' , flat = True ) ) <EOL> self . assertEqual ( languages , [ '<STR_LIT>' ] ) <EOL> def test_table_name_patching ( self ) : <EOL> """<STR_LIT>""" <EOL> User = get_user_model ( ) <EOL> User . objects . create_superuser ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> create_page ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , published = True ) <EOL> draft = Page . objects . drafts ( ) [ <NUM_LIT:0> ] <EOL> draft . reverse_id = '<STR_LIT>' <EOL> draft . save ( ) <EOL> add_plugin ( draft . placeholders . get ( slot = u"<STR_LIT:body>" ) , <EOL> u"<STR_LIT>" , u"<STR_LIT>" , body = "<STR_LIT>" ) <EOL> draft . publish ( '<STR_LIT>' ) <EOL> add_plugin ( draft . placeholders . get ( slot = u"<STR_LIT:body>" ) , <EOL> u"<STR_LIT>" , u"<STR_LIT>" , body = "<STR_LIT>" ) <EOL> Text . _meta . db_table = '<STR_LIT>' <EOL> plugin_pool . patched = False <EOL> with StdoutOverride ( ) : <EOL> call_command ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> not_drafts = len ( Page . objects . filter ( publisher_is_draft = False ) ) <EOL> drafts = len ( Page . objects . filter ( publisher_is_draft = True ) ) <EOL> self . assertEqual ( not_drafts , <NUM_LIT:1> ) <EOL> self . assertEqual ( drafts , <NUM_LIT:1> ) <EOL> def test_command_line_publishes_one_page ( self ) : <EOL> """<STR_LIT>""" <EOL> get_user_model ( ) . objects . create_superuser ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> create_page ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , published = True ) <EOL> draft = Page . objects . drafts ( ) [ <NUM_LIT:0> ] <EOL> draft . reverse_id = '<STR_LIT>' <EOL> draft . save ( ) <EOL> pages_from_output = <NUM_LIT:0> <EOL> published_from_output = <NUM_LIT:0> <EOL> with StdoutOverride ( ) as buffer : <EOL> call_command ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> lines = buffer . getvalue ( ) . split ( '<STR_LIT:\n>' ) <EOL> for line in lines : <EOL> if '<STR_LIT>' in line : <EOL> pages_from_output = int ( line . split ( '<STR_LIT::>' ) [ <NUM_LIT:1> ] ) <EOL> elif '<STR_LIT>' in line : <EOL> published_from_output = int ( line . split ( '<STR_LIT::>' ) [ <NUM_LIT:1> ] ) <EOL> self . assertEqual ( pages_from_output , <NUM_LIT:1> ) <EOL> self . assertEqual ( published_from_output , <NUM_LIT:1> ) <EOL> not_drafts = len ( Page . objects . filter ( publisher_is_draft = False ) ) <EOL> drafts = len ( Page . objects . filter ( publisher_is_draft = True ) ) <EOL> self . assertEqual ( not_drafts , <NUM_LIT:1> ) <EOL> self . assertEqual ( drafts , <NUM_LIT:1> ) <EOL> non_draft = Page . objects . public ( ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( non_draft . reverse_id , '<STR_LIT>' ) <EOL> def test_command_line_publish_multiple_languages ( self ) : <EOL> get_user_model ( ) . objects . create_superuser ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> page = create_page ( u"<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , published = False ) <EOL> title = create_title ( '<STR_LIT>' , '<STR_LIT>' , page ) <EOL> title . published = True <EOL> title . save ( ) <EOL> title = create_title ( '<STR_LIT>' , '<STR_LIT>' , page ) <EOL> title . published = True <EOL> title . save ( ) <EOL> with StdoutOverride ( ) : <EOL> call_command ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> public = Page . objects . public ( ) [ <NUM_LIT:0> ] <EOL> languages = sorted ( public . title_set . values_list ( '<STR_LIT>' , flat = True ) ) <EOL> self . assertEqual ( languages , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_command_line_publish_one_site ( self ) : <EOL> get_user_model ( ) . objects . create_superuser ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> siteA = Site . objects . create ( domain = '<STR_LIT>' , name = '<STR_LIT>' ) <EOL> siteB = Site . objects . create ( domain = '<STR_LIT>' , name = '<STR_LIT>' ) <EOL> create_page ( u"<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , published = True ) <EOL> create_page ( u"<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , site = siteA , published = True ) <EOL> create_page ( u"<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , site = siteB , published = True ) <EOL> create_page ( u"<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , site = siteB , published = True ) <EOL> with StdoutOverride ( ) as buffer : <EOL> call_command ( '<STR_LIT>' , '<STR_LIT>' , site = siteB . id ) <EOL> lines = buffer . getvalue ( ) . split ( '<STR_LIT:\n>' ) <EOL> for line in lines : <EOL> if '<STR_LIT>' in line : <EOL> pages_from_output = int ( line . split ( '<STR_LIT::>' ) [ <NUM_LIT:1> ] ) <EOL> elif '<STR_LIT>' in line : <EOL> published_from_output = int ( line . split ( '<STR_LIT::>' ) [ <NUM_LIT:1> ] ) <EOL> self . assertEqual ( pages_from_output , <NUM_LIT:2> ) <EOL> self . assertEqual ( published_from_output , <NUM_LIT:2> ) <EOL> def test_command_line_publish_multiple_languages_check_count ( self ) : <EOL> """<STR_LIT>""" <EOL> get_user_model ( ) . objects . create_superuser ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> page = create_page ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , published = True ) <EOL> create_title ( "<STR_LIT>" , "<STR_LIT>" , page ) <EOL> page . publish ( "<STR_LIT>" ) <EOL> pages_from_output = <NUM_LIT:0> <EOL> published_from_output = <NUM_LIT:0> <EOL> with StdoutOverride ( ) as buffer : <EOL> call_command ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> lines = buffer . getvalue ( ) . split ( '<STR_LIT:\n>' ) <EOL> for line in lines : <EOL> if '<STR_LIT>' in line : <EOL> pages_from_output = int ( line . split ( '<STR_LIT::>' ) [ <NUM_LIT:1> ] ) <EOL> elif '<STR_LIT>' in line : <EOL> published_from_output = int ( line . split ( '<STR_LIT::>' ) [ <NUM_LIT:1> ] ) <EOL> self . assertEqual ( pages_from_output , <NUM_LIT:1> ) <EOL> self . assertEqual ( published_from_output , <NUM_LIT:1> ) <EOL> def tearDown ( self ) : <EOL> plugin_pool . patched = False <EOL> plugin_pool . set_plugin_meta ( ) <EOL> class PublishingTests ( TestCase ) : <EOL> def create_page ( self , title = None , ** kwargs ) : <EOL> return create_page ( title or self . _testMethodName , <EOL> "<STR_LIT>" , "<STR_LIT>" , ** kwargs ) <EOL> def test_publish_home ( self ) : <EOL> name = self . _testMethodName <EOL> page = self . create_page ( name , published = False ) <EOL> self . assertFalse ( page . publisher_public_id ) <EOL> self . assertEqual ( Page . objects . all ( ) . count ( ) , <NUM_LIT:1> ) <EOL> superuser = self . get_superuser ( ) <EOL> with self . login_user_context ( superuser ) : <EOL> response = self . client . post ( admin_reverse ( "<STR_LIT>" , args = [ page . pk , '<STR_LIT>' ] ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . assertTrue ( response [ '<STR_LIT>' ] . endswith ( "<STR_LIT>" % get_cms_setting ( '<STR_LIT>' ) ) ) <EOL> def test_publish_single ( self ) : <EOL> name = self . _testMethodName <EOL> page = self . create_page ( name , published = False ) <EOL> self . assertFalse ( page . is_published ( '<STR_LIT>' ) ) <EOL> drafts = Page . objects . drafts ( ) <EOL> public = Page . objects . public ( ) <EOL> published = Page . objects . public ( ) . published ( "<STR_LIT>" ) <EOL> self . assertObjectExist ( drafts , title_set__title = name ) <EOL> self . assertObjectDoesNotExist ( public , title_set__title = name ) <EOL> self . assertObjectDoesNotExist ( published , title_set__title = name ) <EOL> page . publish ( "<STR_LIT>" ) <EOL> drafts = Page . objects . drafts ( ) <EOL> public = Page . objects . public ( ) <EOL> published = Page . objects . public ( ) . published ( "<STR_LIT>" ) <EOL> self . assertTrue ( page . is_published ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( page . get_publisher_state ( "<STR_LIT>" ) , PUBLISHER_STATE_DEFAULT ) <EOL> self . assertIsNotNone ( page . publisher_public ) <EOL> self . assertTrue ( page . publisher_public_id ) <EOL> self . assertObjectExist ( drafts , title_set__title = name ) <EOL> self . assertObjectExist ( public , title_set__title = name ) <EOL> self . assertObjectExist ( published , title_set__title = name ) <EOL> page = Page . objects . get ( pk = page . pk ) <EOL> self . assertEqual ( page . get_publisher_state ( "<STR_LIT>" ) , <NUM_LIT:0> ) <EOL> def test_publish_admin ( self ) : <EOL> page = self . create_page ( "<STR_LIT>" , published = False ) <EOL> superuser = self . get_superuser ( ) <EOL> with self . login_user_context ( superuser ) : <EOL> response = self . client . post ( admin_reverse ( "<STR_LIT>" , args = [ page . pk , '<STR_LIT>' ] ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> page = Page . objects . get ( pk = page . pk ) <EOL> self . assertEqual ( page . get_publisher_state ( '<STR_LIT>' ) , <NUM_LIT:0> ) <EOL> def test_publish_wrong_lang ( self ) : <EOL> page = self . create_page ( "<STR_LIT>" , published = False ) <EOL> superuser = self . get_superuser ( ) <EOL> with self . settings ( <EOL> LANGUAGES = ( ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) ) , <EOL> CMS_LANGUAGES = { <NUM_LIT:1> : [ { '<STR_LIT:code>' : '<STR_LIT>' , '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] , '<STR_LIT>' : True } ] } <EOL> ) : <EOL> with self . login_user_context ( superuser ) : <EOL> with force_language ( '<STR_LIT>' ) : <EOL> response = self . client . post ( admin_reverse ( "<STR_LIT>" , args = [ page . pk , '<STR_LIT>' ] ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> page = Page . objects . get ( pk = page . pk ) <EOL> def test_publish_missing_page ( self ) : <EOL> superuser = self . get_superuser ( ) <EOL> with self . login_user_context ( superuser ) : <EOL> response = self . client . post ( admin_reverse ( "<STR_LIT>" , args = [ <NUM_LIT> , '<STR_LIT>' ] ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_publish_child_first ( self ) : <EOL> parent = self . create_page ( '<STR_LIT>' , published = False ) <EOL> child = self . create_page ( '<STR_LIT>' , published = False , parent = parent ) <EOL> parent = parent . reload ( ) <EOL> self . assertFalse ( parent . is_published ( '<STR_LIT>' ) ) <EOL> self . assertFalse ( child . is_published ( '<STR_LIT>' ) ) <EOL> drafts = Page . objects . drafts ( ) <EOL> public = Page . objects . public ( ) <EOL> published = Page . objects . public ( ) . published ( '<STR_LIT>' ) <EOL> for name in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> self . assertObjectExist ( drafts , title_set__title = name ) <EOL> self . assertObjectDoesNotExist ( public , title_set__title = name ) <EOL> self . assertObjectDoesNotExist ( published , title_set__title = name ) <EOL> child . publish ( "<STR_LIT>" ) <EOL> child = child . reload ( ) <EOL> self . assertTrue ( child . is_published ( "<STR_LIT>" ) ) <EOL> self . assertEqual ( child . get_publisher_state ( '<STR_LIT>' ) , PUBLISHER_STATE_PENDING ) <EOL> self . assertIsNone ( child . publisher_public ) <EOL> for name in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> self . assertObjectExist ( drafts , title_set__title = name ) <EOL> self . assertObjectDoesNotExist ( public , title_set__title = name ) <EOL> self . assertObjectDoesNotExist ( published , title_set__title = name ) <EOL> parent . publish ( "<STR_LIT>" ) <EOL> drafts = Page . objects . drafts ( ) <EOL> public = Page . objects . public ( ) <EOL> published = Page . objects . public ( ) . published ( '<STR_LIT>' ) <EOL> for name in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> self . assertObjectExist ( drafts , title_set__title = name ) <EOL> page = drafts . get ( title_set__title = name ) <EOL> self . assertTrue ( page . is_published ( "<STR_LIT>" ) , name ) <EOL> self . assertEqual ( page . get_publisher_state ( '<STR_LIT>' ) , PUBLISHER_STATE_DEFAULT , name ) <EOL> self . assertIsNotNone ( page . publisher_public , name ) <EOL> self . assertTrue ( page . publisher_public . is_published ( '<STR_LIT>' ) , name ) <EOL> self . assertObjectExist ( public , title_set__title = name ) <EOL> self . assertObjectExist ( published , title_set__title = name ) <EOL> def test_simple_publisher ( self ) : <EOL> """<STR_LIT>""" <EOL> pageA = create_page ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> published = True ) <EOL> pageB = create_page ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , parent = pageA , <EOL> published = True ) <EOL> pageC = create_page ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , parent = pageA , <EOL> published = False ) <EOL> self . assertTrue ( pageA . publisher_public_id ) <EOL> self . assertTrue ( pageB . publisher_public_id ) <EOL> self . assertTrue ( not pageC . publisher_public_id ) <EOL> self . assertEqual ( len ( Page . objects . public ( ) . published ( "<STR_LIT>" ) ) , <NUM_LIT:2> ) <EOL> pageC . publish ( "<STR_LIT>" ) <EOL> self . assertTrue ( pageA . publisher_public_id ) <EOL> self . assertTrue ( pageB . publisher_public_id ) <EOL> self . assertTrue ( pageC . publisher_public_id ) <EOL> self . assertEqual ( len ( Page . objects . public ( ) . published ( "<STR_LIT>" ) ) , <NUM_LIT:3> ) <EOL> def test_i18n_publishing ( self ) : <EOL> page = self . create_page ( '<STR_LIT>' , published = True ) <EOL> self . assertEqual ( Title . objects . all ( ) . count ( ) , <NUM_LIT:2> ) <EOL> create_title ( "<STR_LIT>" , "<STR_LIT>" , page ) <EOL> self . assertEqual ( Title . objects . all ( ) . count ( ) , <NUM_LIT:3> ) <EOL> self . assertEqual ( Title . objects . filter ( published = True ) . count ( ) , <NUM_LIT:2> ) <EOL> page . publish ( '<STR_LIT>' ) <EOL> self . assertEqual ( Title . objects . all ( ) . count ( ) , <NUM_LIT:4> ) <EOL> self . assertEqual ( Title . objects . filter ( published = True ) . count ( ) , <NUM_LIT:4> ) <EOL> def test_publish_ordering ( self ) : <EOL> page = self . create_page ( '<STR_LIT>' , published = True ) <EOL> pageA = self . create_page ( '<STR_LIT>' , parent = page , published = True ) <EOL> pageC = self . create_page ( '<STR_LIT>' , parent = page , published = True ) <EOL> pageB = self . create_page ( '<STR_LIT>' , parent = page , published = True ) <EOL> page = page . reload ( ) <EOL> pageB . move_page ( pageA , '<STR_LIT:right>' ) <EOL> pageB . publish ( "<STR_LIT>" ) <EOL> pageC . reload ( ) . publish ( "<STR_LIT>" ) <EOL> pageA . publish ( '<STR_LIT>' ) <EOL> drafts = Page . objects . drafts ( ) . order_by ( '<STR_LIT:path>' ) <EOL> draft_titles = [ ( p . get_title ( '<STR_LIT>' ) , p . path ) for p in drafts ] <EOL> self . assertEqual ( [ ( '<STR_LIT>' , "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , "<STR_LIT>" ) ] , draft_titles ) <EOL> public = Page . objects . public ( ) . order_by ( '<STR_LIT:path>' ) <EOL> public_titles = [ ( p . get_title ( '<STR_LIT>' ) , p . path ) for p in public ] <EOL> self . assertEqual ( [ ( '<STR_LIT>' , "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , "<STR_LIT>" ) ] , public_titles ) <EOL> page . publish ( '<STR_LIT>' ) <EOL> drafts = Page . objects . drafts ( ) . order_by ( '<STR_LIT:path>' ) <EOL> draft_titles = [ ( p . get_title ( '<STR_LIT>' ) , p . path ) for p in drafts ] <EOL> self . assertEqual ( [ ( '<STR_LIT>' , "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , "<STR_LIT>" ) ] , draft_titles ) <EOL> public = Page . objects . public ( ) . order_by ( '<STR_LIT:path>' ) <EOL> public_titles = [ ( p . get_title ( '<STR_LIT>' ) , p . path ) for p in public ] <EOL> self . assertEqual ( [ ( '<STR_LIT>' , "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , "<STR_LIT>" ) ] , public_titles ) <EOL> def test_publish_ordering2 ( self ) : <EOL> page = self . create_page ( '<STR_LIT>' , published = False ) <EOL> pageA = self . create_page ( '<STR_LIT>' , published = False ) <EOL> pageC = self . create_page ( '<STR_LIT>' , published = False , parent = pageA ) <EOL> pageB = self . create_page ( '<STR_LIT>' , published = False , parent = pageA ) <EOL> page = page . reload ( ) <EOL> pageA = pageA . reload ( ) <EOL> pageB = pageB . reload ( ) <EOL> pageC = pageC . reload ( ) <EOL> pageA . publish ( '<STR_LIT>' ) <EOL> page = page . reload ( ) <EOL> pageB = pageB . reload ( ) <EOL> pageC = pageC . reload ( ) <EOL> pageB . publish ( '<STR_LIT>' ) <EOL> page = page . reload ( ) <EOL> pageC = pageC . reload ( ) <EOL> pageC . publish ( '<STR_LIT>' ) <EOL> page = page . reload ( ) <EOL> page . publish ( '<STR_LIT>' ) <EOL> drafts = Page . objects . filter ( publisher_is_draft = True ) . order_by ( '<STR_LIT:path>' ) <EOL> publics = Page . objects . filter ( publisher_is_draft = False ) . order_by ( '<STR_LIT:path>' ) <EOL> x = <NUM_LIT:0> <EOL> for draft in drafts : <EOL> self . assertEqual ( draft . publisher_public_id , publics [ x ] . pk ) <EOL> x += <NUM_LIT:1> <EOL> def test_unpublish_unpublish ( self ) : <EOL> name = self . _testMethodName <EOL> page = self . create_page ( name , published = True ) <EOL> drafts = Page . objects . drafts ( ) <EOL> published = Page . objects . public ( ) . published ( "<STR_LIT>" ) <EOL> self . assertObjectExist ( drafts , title_set__title = name ) <EOL> self . assertObjectExist ( published , title_set__title = name ) <EOL> page . unpublish ( '<STR_LIT>' ) <EOL> self . assertFalse ( page . is_published ( '<STR_LIT>' ) ) <EOL> self . assertObjectExist ( drafts , title_set__title = name ) <EOL> self . assertObjectDoesNotExist ( published , title_set__title = name ) <EOL> page . publish ( '<STR_LIT>' ) <EOL> self . assertTrue ( page . publisher_public_id ) <EOL> self . assertObjectExist ( drafts , title_set__title = name ) <EOL> self . assertObjectExist ( published , title_set__title = name ) <EOL> def test_delete_title_unpublish ( self ) : <EOL> page = self . create_page ( '<STR_LIT:test>' , published = True ) <EOL> sub_page = self . create_page ( '<STR_LIT>' , published = True , parent = page ) <EOL> self . assertTrue ( sub_page . publisher_public . is_published ( '<STR_LIT>' ) ) <EOL> page . title_set . all ( ) . delete ( ) <EOL> self . assertFalse ( sub_page . publisher_public . is_published ( '<STR_LIT>' , force_reload = True ) ) <EOL> def test_modify_child_while_pending ( self ) : <EOL> home = self . create_page ( "<STR_LIT>" , published = True , in_navigation = True ) <EOL> child = self . create_page ( "<STR_LIT>" , published = True , parent = home , <EOL> in_navigation = False ) <EOL> home = home . reload ( ) <EOL> home . unpublish ( '<STR_LIT>' ) <EOL> self . assertEqual ( Title . objects . count ( ) , <NUM_LIT:4> ) <EOL> child = child . reload ( ) <EOL> self . assertFalse ( child . publisher_public . is_published ( '<STR_LIT>' ) ) <EOL> self . assertFalse ( child . in_navigation ) <EOL> self . assertFalse ( child . publisher_public . in_navigation ) <EOL> child . in_navigation = True <EOL> child . save ( ) <EOL> child . publish ( '<STR_LIT>' ) <EOL> child = self . reload ( child ) <EOL> self . assertEqual ( Title . objects . count ( ) , <NUM_LIT:4> ) <EOL> self . assertTrue ( child . is_published ( '<STR_LIT>' ) ) <EOL> self . assertFalse ( child . publisher_public . is_published ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( child . in_navigation ) <EOL> self . assertTrue ( child . publisher_public . in_navigation ) <EOL> self . assertEqual ( child . get_publisher_state ( '<STR_LIT>' ) , PUBLISHER_STATE_PENDING ) <EOL> home . publish ( '<STR_LIT>' ) <EOL> child = self . reload ( child ) <EOL> self . assertTrue ( child . is_published ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( child . publisher_public_id ) <EOL> self . assertTrue ( child . publisher_public . in_navigation ) <EOL> self . assertEqual ( child . get_publisher_state ( '<STR_LIT>' ) , PUBLISHER_STATE_DEFAULT ) <EOL> def test_republish_with_descendants ( self ) : <EOL> home = self . create_page ( "<STR_LIT>" , published = True ) <EOL> child = self . create_page ( "<STR_LIT>" , published = True , parent = home ) <EOL> gc = self . create_page ( "<STR_LIT>" , published = True , parent = child ) <EOL> self . assertTrue ( child . is_published ( "<STR_LIT>" ) ) <EOL> self . assertTrue ( gc . is_published ( '<STR_LIT>' ) ) <EOL> home = home . reload ( ) <EOL> home . unpublish ( '<STR_LIT>' ) <EOL> child = self . reload ( child ) <EOL> gc = self . reload ( gc ) <EOL> self . assertTrue ( child . is_published ( "<STR_LIT>" ) ) <EOL> self . assertTrue ( gc . is_published ( "<STR_LIT>" ) ) <EOL> self . assertFalse ( child . publisher_public . is_published ( "<STR_LIT>" ) ) <EOL> self . assertFalse ( gc . publisher_public . is_published ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( child . get_publisher_state ( '<STR_LIT>' ) , PUBLISHER_STATE_PENDING ) <EOL> self . assertEqual ( gc . get_publisher_state ( '<STR_LIT>' ) , PUBLISHER_STATE_PENDING ) <EOL> home . publish ( '<STR_LIT>' ) <EOL> child = self . reload ( child ) <EOL> gc = self . reload ( gc ) <EOL> self . assertTrue ( child . publisher_public_id ) <EOL> self . assertTrue ( gc . is_published ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( child . is_published ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( gc . publisher_public_id ) <EOL> self . assertEqual ( child . get_publisher_state ( '<STR_LIT>' ) , PUBLISHER_STATE_DEFAULT ) <EOL> self . assertEqual ( gc . get_publisher_state ( '<STR_LIT>' ) , PUBLISHER_STATE_DEFAULT ) <EOL> def test_republish_with_dirty_children ( self ) : <EOL> home = self . create_page ( "<STR_LIT>" , published = True ) <EOL> dirty1 = self . create_page ( "<STR_LIT>" , published = True , parent = home ) <EOL> dirty2 = self . create_page ( "<STR_LIT>" , published = True , parent = home ) <EOL> home = self . reload ( home ) <EOL> dirty1 = self . reload ( dirty1 ) <EOL> dirty2 = self . reload ( dirty2 ) <EOL> dirty1 . in_navigation = True <EOL> dirty1 . save ( ) <EOL> home . unpublish ( '<STR_LIT>' ) <EOL> dirty2 . in_navigation = True <EOL> dirty2 . save ( ) <EOL> dirty1 = self . reload ( dirty1 ) <EOL> dirty2 = self . reload ( dirty2 ) <EOL> self . assertTrue ( dirty1 . is_published ) <EOL> self . assertTrue ( dirty2 . publisher_public_id ) <EOL> self . assertEqual ( dirty1 . get_publisher_state ( "<STR_LIT>" ) , PUBLISHER_STATE_DIRTY ) <EOL> self . assertEqual ( dirty2 . get_publisher_state ( "<STR_LIT>" ) , PUBLISHER_STATE_DIRTY ) <EOL> home = self . reload ( home ) <EOL> with self . assertNumQueries ( FuzzyInt ( <NUM_LIT:0> , <NUM_LIT:100> ) ) : <EOL> home . publish ( '<STR_LIT>' ) <EOL> dirty1 = self . reload ( dirty1 ) <EOL> dirty2 = self . reload ( dirty2 ) <EOL> self . assertTrue ( dirty1 . is_published ( "<STR_LIT>" ) ) <EOL> self . assertTrue ( dirty2 . is_published ( "<STR_LIT>" ) ) <EOL> self . assertTrue ( dirty1 . publisher_public . is_published ( "<STR_LIT>" ) ) <EOL> self . assertTrue ( dirty2 . publisher_public . is_published ( "<STR_LIT>" ) ) <EOL> self . assertEqual ( dirty1 . get_publisher_state ( "<STR_LIT>" ) , PUBLISHER_STATE_DIRTY ) <EOL> self . assertEqual ( dirty2 . get_publisher_state ( "<STR_LIT>" ) , PUBLISHER_STATE_DIRTY ) <EOL> def test_republish_with_unpublished_child ( self ) : <EOL> """<STR_LIT>""" <EOL> home = self . create_page ( "<STR_LIT>" , published = True ) <EOL> unpub1 = self . create_page ( "<STR_LIT>" , published = False , parent = home ) <EOL> unpub2 = self . create_page ( "<STR_LIT>" , published = True , parent = home ) <EOL> gc1 = self . create_page ( "<STR_LIT>" , published = True , parent = unpub1 ) <EOL> gc2 = self . create_page ( "<STR_LIT>" , published = True , parent = unpub2 ) <EOL> self . assertFalse ( gc1 . publisher_public_id ) <EOL> self . assertFalse ( gc1 . publisher_public_id ) <EOL> self . assertTrue ( gc1 . is_published ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( gc2 . is_published ( '<STR_LIT>' ) ) <EOL> home . unpublish ( '<STR_LIT>' ) <EOL> unpub1 = self . reload ( unpub1 ) <EOL> unpub2 . unpublish ( '<STR_LIT>' ) <EOL> for page in ( unpub1 , unpub2 ) : <EOL> self . assertFalse ( page . is_published ( '<STR_LIT>' ) , page ) <EOL> self . assertEqual ( page . get_publisher_state ( "<STR_LIT>" ) , PUBLISHER_STATE_DIRTY ) <EOL> self . assertIsNone ( unpub1 . publisher_public ) <EOL> self . assertIsNotNone ( unpub2 . publisher_public ) <EOL> self . assertFalse ( unpub2 . publisher_public . is_published ( '<STR_LIT>' ) ) <EOL> gc1 = self . reload ( gc1 ) <EOL> gc2 = self . reload ( gc2 ) <EOL> for page in ( gc1 , gc2 ) : <EOL> self . assertTrue ( page . is_published ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( page . get_publisher_state ( '<STR_LIT>' ) , PUBLISHER_STATE_PENDING ) <EOL> self . assertIsNone ( gc1 . publisher_public ) <EOL> self . assertIsNotNone ( gc2 . publisher_public ) <EOL> self . assertFalse ( gc2 . publisher_public . is_published ( '<STR_LIT>' ) ) <EOL> def test_unpublish_with_descendants ( self ) : <EOL> page = self . create_page ( "<STR_LIT>" , published = True ) <EOL> child = self . create_page ( "<STR_LIT>" , parent = page , published = True ) <EOL> self . create_page ( "<STR_LIT>" , parent = child , published = True ) <EOL> page = page . reload ( ) <EOL> child . reload ( ) <EOL> drafts = Page . objects . drafts ( ) <EOL> public = Page . objects . public ( ) <EOL> published = Page . objects . public ( ) . published ( "<STR_LIT>" ) <EOL> self . assertEqual ( published . count ( ) , <NUM_LIT:3> ) <EOL> self . assertEqual ( page . get_descendant_count ( ) , <NUM_LIT:2> ) <EOL> base = reverse ( '<STR_LIT>' ) <EOL> for url in ( base , base + '<STR_LIT>' , base + '<STR_LIT>' ) : <EOL> response = self . client . get ( url ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> , url ) <EOL> for title in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> self . assertObjectExist ( drafts , title_set__title = title ) <EOL> self . assertObjectExist ( public , title_set__title = title ) <EOL> self . assertObjectExist ( published , title_set__title = title ) <EOL> item = drafts . get ( title_set__title = title ) <EOL> self . assertTrue ( item . publisher_public_id ) <EOL> self . assertEqual ( item . get_publisher_state ( '<STR_LIT>' ) , PUBLISHER_STATE_DEFAULT ) <EOL> self . assertTrue ( page . unpublish ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> self . assertFalse ( page . is_published ( '<STR_LIT>' ) ) <EOL> cache . clear ( ) <EOL> for url in ( base , base + '<STR_LIT>' , base + '<STR_LIT>' ) : <EOL> response = self . client . get ( url ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> for title in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> self . assertObjectExist ( drafts , title_set__title = title ) <EOL> self . assertObjectExist ( public , title_set__title = title ) <EOL> self . assertObjectDoesNotExist ( published , title_set__title = title ) <EOL> item = drafts . get ( title_set__title = title ) <EOL> if title == '<STR_LIT>' : <EOL> self . assertFalse ( item . is_published ( "<STR_LIT>" ) ) <EOL> self . assertFalse ( item . publisher_public . is_published ( "<STR_LIT>" ) ) <EOL> self . assertTrue ( page . is_dirty ( '<STR_LIT>' ) ) <EOL> else : <EOL> self . assertTrue ( item . is_published ( '<STR_LIT>' ) , title ) <EOL> self . assertFalse ( item . publisher_public . is_published ( '<STR_LIT>' ) , title ) <EOL> self . assertEqual ( item . get_publisher_state ( '<STR_LIT>' ) , PUBLISHER_STATE_PENDING , <EOL> title ) <EOL> self . assertTrue ( item . is_dirty ( '<STR_LIT>' ) , title ) <EOL> def test_unpublish_with_dirty_descendants ( self ) : <EOL> page = self . create_page ( "<STR_LIT>" , published = True ) <EOL> child = self . create_page ( "<STR_LIT>" , parent = page , published = True ) <EOL> gchild = self . create_page ( "<STR_LIT>" , parent = child , published = True ) <EOL> child . in_navigation = True <EOL> child . save ( ) <EOL> self . assertTrue ( child . is_dirty ( "<STR_LIT>" ) ) <EOL> self . assertFalse ( gchild . is_dirty ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( child . publisher_public . is_published ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( gchild . publisher_public . is_published ( '<STR_LIT>' ) ) <EOL> page . unpublish ( '<STR_LIT>' ) <EOL> child = self . reload ( child ) <EOL> gchild = self . reload ( gchild ) <EOL> self . assertTrue ( child . is_dirty ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( gchild . is_dirty ( '<STR_LIT>' ) ) <EOL> self . assertFalse ( child . publisher_public . is_published ( '<STR_LIT>' ) ) <EOL> self . assertFalse ( gchild . publisher_public . is_published ( '<STR_LIT>' ) ) <EOL> def test_prepublish_descendants ( self ) : <EOL> page = self . create_page ( "<STR_LIT>" , published = True ) <EOL> child_1 = self . create_page ( "<STR_LIT>" , parent = page , published = False ) <EOL> child_1_2 = self . create_page ( "<STR_LIT>" , parent = child_1 , published = False ) <EOL> self . create_page ( "<STR_LIT>" , parent = child_1 , published = True ) <EOL> child_1 = child_1 . reload ( ) <EOL> child_1_1 = self . create_page ( "<STR_LIT>" , published = True ) <EOL> child_1_1 . move_page ( target = child_1 , position = '<STR_LIT>' ) <EOL> child_1_1 . publish ( '<STR_LIT>' ) <EOL> self . assertFalse ( child_1 . is_published ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( child_1_1 . is_published ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( child_1_1 . get_publisher_state ( '<STR_LIT>' ) , PUBLISHER_STATE_PENDING ) <EOL> child_1 . publish ( '<STR_LIT>' ) <EOL> child_1_2 . publish ( '<STR_LIT>' ) <EOL> self . assertTrue ( child_1 . is_published ( "<STR_LIT>" ) ) <EOL> self . assertTrue ( child_1_1 . is_published ( "<STR_LIT>" ) ) <EOL> self . assertEqual ( child_1_1 . get_publisher_state ( '<STR_LIT>' , force_reload = True ) , PUBLISHER_STATE_DEFAULT ) <EOL> self . assertEqual ( child_1_1 . path [ <NUM_LIT:4> : ] , child_1_1 . publisher_public . path [ <NUM_LIT:4> : ] ) <EOL> self . assertEqual ( child_1_1 . depth , child_1_1 . publisher_public . depth ) <EOL> def test_republish_multiple_root ( self ) : <EOL> home = self . create_page ( "<STR_LIT>" , published = True ) <EOL> other = self . create_page ( "<STR_LIT>" , published = True ) <EOL> child = self . create_page ( "<STR_LIT>" , published = True , parent = home ) <EOL> child2 = self . create_page ( "<STR_LIT>" , published = True , parent = other ) <EOL> self . assertTrue ( Page . objects . filter ( is_home = True ) . count ( ) , <NUM_LIT:2> ) <EOL> self . assertTrue ( home . is_home ) <EOL> home = home . reload ( ) <EOL> self . assertTrue ( home . publisher_public . is_home ) <EOL> root = reverse ( '<STR_LIT>' ) <EOL> self . assertEqual ( home . get_absolute_url ( ) , root ) <EOL> self . assertEqual ( home . get_public_object ( ) . get_absolute_url ( ) , root ) <EOL> self . assertEqual ( child . get_absolute_url ( ) , root + '<STR_LIT>' ) <EOL> self . assertEqual ( child . get_public_object ( ) . get_absolute_url ( ) , root + '<STR_LIT>' ) <EOL> self . assertEqual ( other . get_absolute_url ( ) , root + '<STR_LIT>' ) <EOL> self . assertEqual ( other . get_public_object ( ) . get_absolute_url ( ) , root + '<STR_LIT>' ) <EOL> self . assertEqual ( child2 . get_absolute_url ( ) , root + '<STR_LIT>' ) <EOL> self . assertEqual ( child2 . get_public_object ( ) . get_absolute_url ( ) , root + '<STR_LIT>' ) <EOL> home = self . reload ( home ) <EOL> home . unpublish ( '<STR_LIT>' ) <EOL> home = self . reload ( home ) <EOL> other = self . reload ( other ) <EOL> child = self . reload ( child ) <EOL> child2 = self . reload ( child2 ) <EOL> self . assertFalse ( home . is_home ) <EOL> self . assertFalse ( home . publisher_public . is_home ) <EOL> self . assertTrue ( other . is_home ) <EOL> self . assertTrue ( other . publisher_public . is_home ) <EOL> self . assertEqual ( other . get_absolute_url ( ) , root ) <EOL> self . assertEqual ( other . get_public_object ( ) . get_absolute_url ( ) , root ) <EOL> self . assertEqual ( home . get_absolute_url ( ) , root + '<STR_LIT>' ) <EOL> self . assertEqual ( home . get_public_object ( ) . get_absolute_url ( ) , root + '<STR_LIT>' ) <EOL> self . assertEqual ( child . get_absolute_url ( ) , root + '<STR_LIT>' ) <EOL> self . assertEqual ( child . get_public_object ( ) . get_absolute_url ( ) , root + '<STR_LIT>' ) <EOL> self . assertEqual ( child2 . get_absolute_url ( ) , root + '<STR_LIT>' ) <EOL> self . assertEqual ( child2 . get_public_object ( ) . get_absolute_url ( ) , root + '<STR_LIT>' ) <EOL> home . publish ( '<STR_LIT>' ) <EOL> home = self . reload ( home ) <EOL> other = self . reload ( other ) <EOL> child = self . reload ( child ) <EOL> child2 = self . reload ( child2 ) <EOL> self . assertTrue ( home . is_home ) <EOL> self . assertTrue ( home . publisher_public . is_home ) <EOL> self . assertEqual ( home . get_absolute_url ( ) , root ) <EOL> self . assertEqual ( home . get_public_object ( ) . get_absolute_url ( ) , root ) <EOL> self . assertEqual ( child . get_absolute_url ( ) , root + '<STR_LIT>' ) <EOL> self . assertEqual ( child . get_public_object ( ) . get_absolute_url ( ) , root + '<STR_LIT>' ) <EOL> self . assertEqual ( other . get_absolute_url ( ) , root + '<STR_LIT>' ) <EOL> self . assertEqual ( other . get_public_object ( ) . get_absolute_url ( ) , root + '<STR_LIT>' ) <EOL> self . assertEqual ( child2 . get_absolute_url ( ) , root + '<STR_LIT>' ) <EOL> self . assertEqual ( child2 . get_public_object ( ) . get_absolute_url ( ) , root + '<STR_LIT>' ) <EOL> def test_revert_contents ( self ) : <EOL> user = self . get_superuser ( ) <EOL> page = create_page ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , published = True , <EOL> created_by = user ) <EOL> placeholder = page . placeholders . get ( slot = u"<STR_LIT:body>" ) <EOL> deleted_plugin = add_plugin ( placeholder , u"<STR_LIT>" , u"<STR_LIT>" , body = "<STR_LIT>" ) <EOL> text_plugin = add_plugin ( placeholder , u"<STR_LIT>" , u"<STR_LIT>" , body = "<STR_LIT>" ) <EOL> page . publish ( '<STR_LIT>' ) <EOL> text_plugin . body = "<STR_LIT>" <EOL> text_plugin . save ( ) <EOL> deleted_plugin . delete ( ) <EOL> self . assertEqual ( CMSPlugin . objects . count ( ) , <NUM_LIT:3> ) <EOL> page . revert ( '<STR_LIT>' ) <EOL> self . assertEqual ( page . get_publisher_state ( "<STR_LIT>" ) , PUBLISHER_STATE_DEFAULT ) <EOL> self . assertEqual ( CMSPlugin . objects . count ( ) , <NUM_LIT:4> ) <EOL> plugins = CMSPlugin . objects . filter ( placeholder__page = page ) <EOL> self . assertEqual ( plugins . count ( ) , <NUM_LIT:2> ) <EOL> plugins = [ plugin . get_plugin_instance ( ) [ <NUM_LIT:0> ] for plugin in plugins ] <EOL> self . assertEqual ( plugins [ <NUM_LIT:0> ] . body , "<STR_LIT>" ) <EOL> self . assertEqual ( plugins [ <NUM_LIT:1> ] . body , "<STR_LIT>" ) <EOL> def test_revert_move ( self ) : <EOL> parent = create_page ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , published = True ) <EOL> parent_url = parent . get_absolute_url ( ) <EOL> page = create_page ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , published = True , <EOL> parent = parent ) <EOL> other = create_page ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , published = True ) <EOL> other_url = other . get_absolute_url ( ) <EOL> child = create_page ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , published = True , <EOL> parent = page ) <EOL> parent = parent . reload ( ) <EOL> page = page . reload ( ) <EOL> self . assertEqual ( page . get_absolute_url ( ) , parent_url + "<STR_LIT>" ) <EOL> self . assertEqual ( child . get_absolute_url ( ) , parent_url + "<STR_LIT>" ) <EOL> page . move_page ( other ) <EOL> page = self . reload ( page ) <EOL> child = self . reload ( child ) <EOL> self . assertEqual ( page . get_absolute_url ( ) , other_url + "<STR_LIT>" ) <EOL> self . assertEqual ( child . get_absolute_url ( ) , other_url + "<STR_LIT>" ) <EOL> self . assertEqual ( page . publisher_public . get_absolute_url ( ) , other_url + "<STR_LIT>" ) <EOL> self . assertEqual ( child . publisher_public . get_absolute_url ( ) , other_url + "<STR_LIT>" ) <EOL> def test_publish_works_with_descendants ( self ) : <EOL> """<STR_LIT>""" <EOL> home_page = create_page ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> published = True , in_navigation = False ) <EOL> create_page ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , parent = home_page , <EOL> published = True ) <EOL> item2 = create_page ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , parent = home_page , <EOL> published = True ) <EOL> create_page ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , parent = item2 , <EOL> published = True ) <EOL> create_page ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , parent = item2 , <EOL> published = True ) <EOL> item2 = item2 . reload ( ) <EOL> not_drafts = list ( Page . objects . filter ( publisher_is_draft = False ) . order_by ( '<STR_LIT:path>' ) ) <EOL> drafts = list ( Page . objects . filter ( publisher_is_draft = True ) . order_by ( '<STR_LIT:path>' ) ) <EOL> self . assertEqual ( len ( not_drafts ) , <NUM_LIT:5> ) <EOL> self . assertEqual ( len ( drafts ) , <NUM_LIT:5> ) <EOL> for idx , draft in enumerate ( drafts ) : <EOL> public = not_drafts [ idx ] <EOL> self . assertEqual ( bool ( public . parent_id ) , bool ( draft . parent_id ) ) <EOL> if public . parent : <EOL> self . assertEqual ( public . path [ <NUM_LIT:0> : <NUM_LIT:4> ] , public . parent . path [ <NUM_LIT:0> : <NUM_LIT:4> ] ) <EOL> self . assertTrue ( public . parent in public . get_ancestors ( ) ) <EOL> self . assertTrue ( public in public . parent . get_descendants ( ) ) <EOL> self . assertTrue ( public in public . parent . get_children ( ) ) <EOL> if draft . parent : <EOL> self . assertEqual ( draft . path [ <NUM_LIT:0> : <NUM_LIT:4> ] , draft . parent . path [ <NUM_LIT:0> : <NUM_LIT:4> ] ) <EOL> self . assertTrue ( draft . parent in draft . get_ancestors ( ) ) <EOL> self . assertTrue ( draft in draft . parent . get_descendants ( ) ) <EOL> self . assertTrue ( draft in draft . parent . get_children ( ) ) <EOL> item2 . publish ( '<STR_LIT>' ) <EOL> not_drafts = list ( Page . objects . filter ( publisher_is_draft = False ) . order_by ( '<STR_LIT:path>' ) ) <EOL> drafts = list ( Page . objects . filter ( publisher_is_draft = True ) . order_by ( '<STR_LIT:path>' ) ) <EOL> self . assertEqual ( len ( not_drafts ) , <NUM_LIT:5> ) <EOL> self . assertEqual ( len ( drafts ) , <NUM_LIT:5> ) <EOL> for idx , draft in enumerate ( drafts ) : <EOL> public = not_drafts [ idx ] <EOL> self . assertEqual ( bool ( public . parent_id ) , bool ( draft . parent_id ) ) <EOL> self . assertEqual ( public . numchild , draft . numchild ) <EOL> if public . parent : <EOL> self . assertEqual ( public . path [ <NUM_LIT:0> : <NUM_LIT:4> ] , public . parent . path [ <NUM_LIT:0> : <NUM_LIT:4> ] ) <EOL> self . assertTrue ( public . parent in public . get_ancestors ( ) ) <EOL> self . assertTrue ( public in public . parent . get_descendants ( ) ) <EOL> self . assertTrue ( public in public . parent . get_children ( ) ) <EOL> if draft . parent : <EOL> self . assertEqual ( draft . path [ <NUM_LIT:0> : <NUM_LIT:4> ] , draft . parent . path [ <NUM_LIT:0> : <NUM_LIT:4> ] ) <EOL> self . assertTrue ( draft . parent in draft . get_ancestors ( ) ) <EOL> self . assertTrue ( draft in draft . parent . get_descendants ( ) ) <EOL> self . assertTrue ( draft in draft . parent . get_children ( ) ) </s>
