<s> from __future__ import absolute_import <EOL> import mock <EOL> import datetime <EOL> from contextlib import contextmanager <EOL> from unittest import skipUnless <EOL> import uuid <EOL> import django <EOL> from django . test import TestCase <EOL> from django . test . client import RequestFactory <EOL> from django . test . utils import override_settings <EOL> from django import forms <EOL> from django . conf import settings <EOL> from django . core . exceptions import PermissionDenied <EOL> from django . utils import timezone <EOL> from django . core import urlresolvers <EOL> from django . contrib . auth . models import Permission , AnonymousUser <EOL> from django . contrib . auth import get_user_model <EOL> from django . contrib . contenttypes . models import ContentType <EOL> from django . contrib import admin <EOL> from django . db . models . signals import post_save <EOL> from django . conf . urls import url , include <EOL> from django . core . urlresolvers import get_resolver <EOL> from mezzanine . core . models import ( CONTENT_STATUS_PUBLISHED , <EOL> CONTENT_STATUS_DRAFT ) <EOL> from mezzanine . pages . models import Page <EOL> from widgy . site import WidgySite <EOL> from widgy . contrib . widgy_mezzanine import get_widgypage_model <EOL> from widgy . contrib . widgy_mezzanine . views import ClonePageView , UnpublishView <EOL> from widgy . db . fields import get_site <EOL> from widgy . contrib . widgy_mezzanine . admin import WidgyPageAdmin <EOL> User = get_user_model ( ) <EOL> widgy_site = WidgySite ( ) <EOL> WidgyPage = get_widgypage_model ( ) <EOL> urlpatterns = get_resolver ( None ) . url_patterns <EOL> urlpatterns = urlpatterns + [ <EOL> url ( '<STR_LIT>' , include ( widgy_site . urls ) ) , <EOL> url ( '<STR_LIT>' , include ( '<STR_LIT>' ) ) , <EOL> ] <EOL> FORM_BUILDER_INSTALLED = '<STR_LIT>' in settings . INSTALLED_APPS <EOL> if FORM_BUILDER_INSTALLED : <EOL> from widgy . contrib . form_builder . models import Form , FormInput <EOL> from widgy . contrib . widgy_mezzanine . views import handle_form <EOL> PAGE_BUILDER_INSTALLED = '<STR_LIT>' in settings . INSTALLED_APPS <EOL> if PAGE_BUILDER_INSTALLED : <EOL> from widgy . contrib . page_builder . models import Button , DefaultLayout , MainContent <EOL> from widgy . contrib . widgy_mezzanine . views import PreviewView <EOL> REVIEW_QUEUE_INSTALLED = '<STR_LIT>' in settings . INSTALLED_APPS <EOL> if REVIEW_QUEUE_INSTALLED : <EOL> from widgy . contrib . review_queue . site import ReviewedWidgySite <EOL> reviewed_widgy_site = ReviewedWidgySite ( ) <EOL> urlpatterns += [ url ( '<STR_LIT>' , include ( reviewed_widgy_site . urls ) ) ] <EOL> def make_reviewed ( fn ) : <EOL> """<STR_LIT>""" <EOL> from widgy . contrib . widgy_mezzanine . admin import publish_page_on_approve <EOL> site = reviewed_widgy_site <EOL> rel = WidgyPage . _meta . get_field ( '<STR_LIT>' ) . rel <EOL> old_model = rel . model <EOL> dispatch_uid = str ( uuid . uuid4 ( ) ) <EOL> fn = override_settings ( WIDGY_MEZZANINE_SITE = site ) ( fn ) <EOL> fn = skipUnless ( REVIEW_QUEUE_INSTALLED , '<STR_LIT>' ) ( fn ) <EOL> def up ( ) : <EOL> if django . VERSION < ( <NUM_LIT:1> , <NUM_LIT:9> ) : <EOL> rel . to = site . get_version_tracker_model ( ) <EOL> else : <EOL> rel . model = site . get_version_tracker_model ( ) <EOL> post_save . connect ( publish_page_on_approve , <EOL> sender = site . get_version_tracker_model ( ) . commit_model , <EOL> dispatch_uid = dispatch_uid ) <EOL> def down ( ) : <EOL> if django . VERSION < ( <NUM_LIT:1> , <NUM_LIT:9> ) : <EOL> rel . to = old_model <EOL> else : <EOL> rel . model = old_model <EOL> post_save . disconnect ( dispatch_uid = dispatch_uid ) <EOL> if isinstance ( fn , type ) : <EOL> old_pre_setup = fn . _pre_setup <EOL> old_post_teardown = fn . _post_teardown <EOL> def _pre_setup ( self ) : <EOL> up ( ) <EOL> old_pre_setup ( self ) <EOL> def _post_teardown ( self ) : <EOL> old_post_teardown ( self ) <EOL> down ( ) <EOL> fn . _pre_setup = _pre_setup <EOL> fn . _post_teardown = _post_teardown <EOL> return fn <EOL> else : <EOL> def change_foreign_key ( * args , ** kwargs ) : <EOL> up ( ) <EOL> try : <EOL> return fn ( * args , ** kwargs ) <EOL> finally : <EOL> down ( ) <EOL> return change_foreign_key <EOL> @ skipUnless ( FORM_BUILDER_INSTALLED , '<STR_LIT>' ) <EOL> class TestFormHandler ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . factory = RequestFactory ( ) <EOL> self . form = Form . add_root ( widgy_site ) <EOL> def test_get ( self ) : <EOL> req = self . factory . get ( '<STR_LIT>' ) <EOL> resp = handle_form ( req , form_node_pk = self . form . node . pk ) <EOL> self . assertEqual ( resp [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def test_post ( self ) : <EOL> req = self . factory . post ( '<STR_LIT>' ) <EOL> with mock . patch . object ( Form , '<STR_LIT>' ) as form_execute : <EOL> form_execute . return_value = object ( ) <EOL> resp = handle_form ( req , form_node_pk = self . form . node . pk ) <EOL> args , kwargs = form_execute . call_args <EOL> self . assertIs ( args [ <NUM_LIT:0> ] , req ) <EOL> self . assertIsInstance ( args [ <NUM_LIT:1> ] , forms . BaseForm ) <EOL> self . assertIs ( resp , form_execute . return_value ) <EOL> def test_post_rerender ( self ) : <EOL> self . form . children [ '<STR_LIT>' ] . add_child ( widgy_site , FormInput , <EOL> label = '<STR_LIT:foo>' , <EOL> required = True , <EOL> type = '<STR_LIT:text>' , <EOL> ) <EOL> req = self . factory . post ( '<STR_LIT>' ) <EOL> req . user = User ( is_superuser = True ) <EOL> with mock . patch . object ( Form , '<STR_LIT>' ) as form_execute : <EOL> with mock . patch ( '<STR_LIT>' ) as page_view : <EOL> page_view . return_value = object ( ) <EOL> resp = handle_form ( req , form_node_pk = self . form . node . pk ) <EOL> form_execute . assert_not_called ( ) <EOL> self . assertIs ( resp , page_view . return_value ) <EOL> args , kwargs = page_view . call_args <EOL> self . assertIs ( args [ <NUM_LIT:0> ] , req ) <EOL> extra_context = kwargs [ '<STR_LIT>' ] <EOL> self . assertEqual ( extra_context [ '<STR_LIT>' ] , self . form . node ) <EOL> django_form = extra_context [ self . form . context_var ] <EOL> self . assertIsInstance ( django_form , forms . BaseForm ) <EOL> self . assertTrue ( django_form . errors ) <EOL> @ override_settings ( MIDDLEWARE_CLASSES = settings . MIDDLEWARE_CLASSES + ( <EOL> '<STR_LIT>' , <EOL> ) ) <EOL> def test_post_no_404 ( self ) : <EOL> """<STR_LIT>""" <EOL> from widgy . contrib . widgy_mezzanine . models import WidgyPage <EOL> page = WidgyPage . objects . create ( title = '<STR_LIT>' ) <EOL> self . form . children [ '<STR_LIT>' ] . add_child ( widgy_site , FormInput , <EOL> label = '<STR_LIT:foo>' , <EOL> required = True , <EOL> type = '<STR_LIT:text>' , <EOL> ) <EOL> req = self . factory . post ( '<STR_LIT>' ) <EOL> req . user = User ( is_superuser = True ) <EOL> resp = handle_form ( req , form_node_pk = self . form . node . pk , slug = page . slug ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> class UserSetup ( object ) : <EOL> def setUp ( self ) : <EOL> super ( UserSetup , self ) . setUp ( ) <EOL> self . superuser = User . objects . create_superuser ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:password>' ) <EOL> self . staffuser = User . objects . create_user ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:password>' ) <EOL> self . staffuser . is_staff = True <EOL> self . staffuser . save ( ) <EOL> self . staffuser . user_permissions = Permission . objects . filter ( <EOL> content_type__app_label__in = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) . exclude ( codename = '<STR_LIT>' ) <EOL> @ contextmanager <EOL> def as_user ( self , username ) : <EOL> self . client . login ( username = username , password = '<STR_LIT:password>' ) <EOL> yield <EOL> self . client . logout ( ) <EOL> @ skipUnless ( PAGE_BUILDER_INSTALLED , '<STR_LIT>' ) <EOL> @ override_settings ( MIDDLEWARE_CLASSES = settings . MIDDLEWARE_CLASSES + ( <EOL> '<STR_LIT>' , <EOL> ) ) <EOL> class TestPreviewView ( UserSetup , TestCase ) : <EOL> urls = '<STR_LIT>' <EOL> def setUp ( self ) : <EOL> super ( TestPreviewView , self ) . setUp ( ) <EOL> self . factory = RequestFactory ( ) <EOL> self . preview_view = PreviewView . as_view ( site = widgy_site ) <EOL> self . request = self . factory . get ( '<STR_LIT:/>' ) <EOL> self . request . user = User ( is_superuser = True , is_staff = True ) <EOL> def test_preview ( self ) : <EOL> page = WidgyPage . objects . create ( title = '<STR_LIT>' ) <EOL> root_node1 = Button . add_root ( widgy_site , text = '<STR_LIT>' ) <EOL> root_node2 = Button . add_root ( widgy_site , text = '<STR_LIT>' ) <EOL> resp1 = self . preview_view ( self . request , node_pk = root_node1 . node . pk , page_pk = page . pk ) <EOL> self . assertEqual ( resp1 . status_code , <NUM_LIT:200> ) <EOL> self . assertIn ( '<STR_LIT>' , resp1 . rendered_content ) <EOL> self . assertEqual ( resp1 . context_data [ '<STR_LIT>' ] . get_content_model ( ) , page ) <EOL> resp2 = self . preview_view ( self . request , node_pk = root_node2 . node . pk , page_pk = page . pk ) <EOL> self . assertEqual ( resp2 . status_code , <NUM_LIT:200> ) <EOL> self . assertIn ( '<STR_LIT>' , resp2 . rendered_content ) <EOL> def test_preview_without_page ( self ) : <EOL> button = Button . add_root ( widgy_site , text = '<STR_LIT>' ) <EOL> resp = self . preview_view ( self . request , node_pk = button . node . pk ) <EOL> self . assertIn ( button . text , resp . rendered_content ) <EOL> def test_legacy_url ( self ) : <EOL> page = WidgyPage . objects . create ( title = '<STR_LIT>' ) <EOL> root_node = Button . add_root ( widgy_site , text = '<STR_LIT>' ) . node <EOL> with self . as_user ( '<STR_LIT>' ) : <EOL> r = self . client . get ( urlresolvers . reverse ( <EOL> '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : page . slug , '<STR_LIT>' : root_node . pk } <EOL> ) ) <EOL> self . assertRedirects ( <EOL> response = r , <EOL> expected_url = urlresolvers . reverse ( <EOL> '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : page . pk , '<STR_LIT>' : root_node . pk } <EOL> ) , <EOL> status_code = <NUM_LIT> , <EOL> ) <EOL> def test_redirects_to_login ( self ) : <EOL> """<STR_LIT>""" <EOL> button = Button . add_root ( widgy_site , text = '<STR_LIT>' ) <EOL> request = self . factory . get ( '<STR_LIT:/>' ) <EOL> request . user = AnonymousUser ( ) <EOL> resp = self . preview_view ( request , node_pk = button . node . pk ) <EOL> self . assertEqual ( resp [ '<STR_LIT>' ] , urlresolvers . reverse ( '<STR_LIT>' ) + '<STR_LIT>' + request . get_full_path ( ) ) <EOL> @ skipUnless ( PAGE_BUILDER_INSTALLED , '<STR_LIT>' ) <EOL> class PageSetup ( object ) : <EOL> def setUp ( self ) : <EOL> super ( PageSetup , self ) . setUp ( ) <EOL> self . factory = RequestFactory ( ) <EOL> self . widgy_site = get_site ( getattr ( settings , '<STR_LIT>' , widgy_site ) ) <EOL> self . page = WidgyPage . objects . create ( <EOL> root_node = self . widgy_site . get_version_tracker_model ( ) . objects . create ( <EOL> working_copy = MainContent . add_root ( self . widgy_site ) . node , <EOL> ) , <EOL> title = '<STR_LIT>' , <EOL> slug = '<STR_LIT>' , <EOL> ) <EOL> class AdminView ( PageSetup ) : <EOL> def as_view ( self , ** kwargs ) : <EOL> kwargs . setdefault ( '<STR_LIT>' , lambda req : True ) <EOL> kwargs . setdefault ( '<STR_LIT>' , WidgyPage ) <EOL> return self . view_cls . as_view ( ** kwargs ) <EOL> def test_permissions ( self ) : <EOL> with self . assertRaises ( PermissionDenied ) : <EOL> forbid_everything = lambda req : False <EOL> req = self . factory . get ( '<STR_LIT:/>' ) <EOL> self . as_view ( has_permission = forbid_everything ) ( req , str ( self . page . pk ) ) <EOL> class TestClonePage ( AdminView , TestCase ) : <EOL> view_cls = ClonePageView <EOL> def test_get ( self ) : <EOL> view = self . as_view ( model = WidgyPage ) <EOL> resp = view ( self . factory . get ( '<STR_LIT:/>' ) , str ( self . page . pk ) ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertIn ( self . page . title , resp . rendered_content ) <EOL> self . assertNotIn ( self . page . slug , resp . rendered_content ) <EOL> def test_post ( self ) : <EOL> self . page . root_node . working_copy . content . add_child ( <EOL> self . widgy_site , Button , text = '<STR_LIT>' ) <EOL> view = self . as_view ( model = WidgyPage ) <EOL> with mock . patch ( '<STR_LIT>' ) as success_mock : <EOL> req = self . factory . post ( '<STR_LIT:/>' , { '<STR_LIT:title>' : '<STR_LIT>' } ) <EOL> view ( req , str ( self . page . pk ) ) <EOL> new_page = WidgyPage . objects . exclude ( pk = self . page . pk ) . get ( ) <EOL> success_mock . assert_called_with ( req , mock . ANY ) <EOL> success_message = success_mock . call_args [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] <EOL> self . assertIn ( self . page . title , success_message ) <EOL> self . assertIn ( new_page . title , success_message ) <EOL> self . assertNotEqual ( new_page . slug , self . page . slug ) <EOL> self . assertEqual ( new_page . title , '<STR_LIT>' ) <EOL> button = new_page . root_node . working_copy . content . get_children ( ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( button . text , '<STR_LIT>' ) <EOL> class TestUnpublish ( AdminView , TestCase ) : <EOL> view_cls = UnpublishView <EOL> def test_unpublish ( self ) : <EOL> self . assertEqual ( self . page . status , CONTENT_STATUS_PUBLISHED ) <EOL> view = self . as_view ( model = WidgyPage ) <EOL> resp = view ( self . factory . get ( '<STR_LIT:/>' ) , str ( self . page . pk ) ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertIn ( self . page . title , resp . rendered_content ) <EOL> with mock . patch ( '<STR_LIT>' ) as success_mock : <EOL> req = self . factory . post ( '<STR_LIT:/>' ) <EOL> resp = view ( req , str ( self . page . pk ) ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> success_mock . assert_called_with ( req , mock . ANY ) <EOL> self . page = WidgyPage . objects . get ( pk = self . page . pk ) <EOL> self . assertEqual ( self . page . status , CONTENT_STATUS_DRAFT ) <EOL> class AdminButtonsTestBase ( PageSetup , UserSetup ) : <EOL> urls = '<STR_LIT>' <EOL> def setUp ( self ) : <EOL> super ( AdminButtonsTestBase , self ) . setUp ( ) <EOL> self . model_admin = WidgyPageAdmin ( WidgyPage , admin . site ) <EOL> def test_save_and_commit_without_changes ( self ) : <EOL> req = self . factory . post ( '<STR_LIT:/>' ) <EOL> req . user = self . superuser <EOL> self . model_admin . _save_and_commit ( req , self . page ) <EOL> self . assertEqual ( self . page . root_node . commits . count ( ) , <NUM_LIT:1> ) <EOL> self . model_admin . _save_and_commit ( req , self . page ) <EOL> self . assertEqual ( self . page . root_node . commits . count ( ) , <NUM_LIT:1> ) <EOL> @ skipUnless ( PAGE_BUILDER_INSTALLED , '<STR_LIT>' ) <EOL> @ override_settings ( WIDGY_MEZZANINE_SITE = widgy_site ) <EOL> class TestAdminButtons ( AdminButtonsTestBase , TestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestAdminButtons , self ) . setUp ( ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT:password>' ) <EOL> def test_status_embryo ( self ) : <EOL> url = urlresolvers . reverse ( '<STR_LIT>' ) <EOL> response = self . client . get ( url ) <EOL> self . assertIn ( '<STR_LIT>' , response . rendered_content ) <EOL> def test_status_embryo_save ( self ) : <EOL> url = urlresolvers . reverse ( '<STR_LIT>' ) <EOL> response = self . client . get ( url ) <EOL> data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : ContentType . objects . get_for_model ( DefaultLayout ) . pk , <EOL> } <EOL> response = self . client . post ( url , data ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> page = WidgyPage . objects . get ( slug = '<STR_LIT>' ) <EOL> self . assertEqual ( page . status , CONTENT_STATUS_DRAFT ) <EOL> def test_save_and_commit ( self ) : <EOL> self . page . status = CONTENT_STATUS_DRAFT <EOL> self . page . save ( ) <EOL> req = self . factory . post ( '<STR_LIT:/>' ) <EOL> req . user = self . superuser <EOL> self . model_admin . _save_and_commit ( req , self . page ) <EOL> self . assertEqual ( self . page . status , CONTENT_STATUS_PUBLISHED ) <EOL> def test_save_and_commit_without_permission ( self ) : <EOL> self . model_admin = WidgyPageAdmin ( WidgyPage , admin . site ) <EOL> req = self . factory . post ( '<STR_LIT:/>' ) <EOL> req . user = self . staffuser <EOL> self . staffuser . user_permissions . filter ( codename = '<STR_LIT>' ) . delete ( ) <EOL> with mock . patch ( '<STR_LIT>' ) as error_mock : <EOL> self . model_admin . _save_and_commit ( req , self . page ) <EOL> error_mock . assert_called_with ( req , mock . ANY ) <EOL> self . assertEqual ( self . page . root_node . commits . count ( ) , <NUM_LIT:0> ) <EOL> def test_status_draft ( self ) : <EOL> self . page . status = CONTENT_STATUS_DRAFT <EOL> self . page . save ( ) <EOL> url = urlresolvers . reverse ( '<STR_LIT>' , args = ( self . page . pk , ) ) <EOL> response = self . client . get ( url ) <EOL> self . assertIn ( '<STR_LIT>' , response . rendered_content ) <EOL> self . assertIn ( '<STR_LIT>' , response . rendered_content ) <EOL> def test_status_published ( self ) : <EOL> url = urlresolvers . reverse ( '<STR_LIT>' , args = ( self . page . pk , ) ) <EOL> response = self . client . get ( url ) <EOL> self . assertIn ( '<STR_LIT>' , response . rendered_content ) <EOL> def test_delete_button ( self ) : <EOL> url = urlresolvers . reverse ( '<STR_LIT>' ) <EOL> response = self . client . get ( url ) <EOL> self . assertNotIn ( '<STR_LIT>' , response . rendered_content ) <EOL> url = urlresolvers . reverse ( '<STR_LIT>' , args = ( self . page . pk , ) ) <EOL> response = self . client . get ( url ) <EOL> self . assertIn ( '<STR_LIT>' , response . rendered_content ) <EOL> @ make_reviewed <EOL> class TestAdminButtonsWhenReviewed ( AdminButtonsTestBase , TestCase ) : <EOL> def test_save_and_commit ( self ) : <EOL> self . page . status = CONTENT_STATUS_DRAFT <EOL> self . page . save ( ) <EOL> req = self . factory . post ( '<STR_LIT:/>' ) <EOL> req . user = self . staffuser <EOL> self . model_admin . _save_and_commit ( req , self . page ) <EOL> self . assertEqual ( self . page . status , CONTENT_STATUS_DRAFT ) <EOL> self . assertEqual ( self . page . root_node . commits . count ( ) , <NUM_LIT:1> ) <EOL> commit = self . page . root_node . commits . get ( ) <EOL> self . assertFalse ( commit . reviewedversioncommit . is_approved ) <EOL> def test_save_and_approve ( self ) : <EOL> self . page . status = CONTENT_STATUS_DRAFT <EOL> self . page . save ( ) <EOL> req = self . factory . post ( '<STR_LIT:/>' ) <EOL> req . user = self . superuser <EOL> self . model_admin . _save_and_approve ( req , self . page ) <EOL> self . assertEqual ( self . page . status , CONTENT_STATUS_PUBLISHED ) <EOL> self . assertEqual ( self . page . root_node . commits . count ( ) , <NUM_LIT:1> ) <EOL> self . assertTrue ( self . page . root_node . head . reviewedversioncommit . is_approved ) <EOL> def test_save_and_approve_without_permission ( self ) : <EOL> req = self . factory . post ( '<STR_LIT:/>' ) <EOL> req . user = self . staffuser <EOL> with mock . patch ( '<STR_LIT>' ) as error_mock : <EOL> self . model_admin . _save_and_approve ( req , self . page ) <EOL> error_mock . assert_called_with ( req , mock . ANY ) <EOL> self . assertEqual ( self . page . root_node . commits . count ( ) , <NUM_LIT:0> ) <EOL> def test_save_and_approve_without_commit ( self ) : <EOL> commit = self . page . root_node . commit ( ) <EOL> req = self . factory . post ( '<STR_LIT:/>' ) <EOL> req . user = self . superuser <EOL> self . model_admin . _save_and_approve ( req , self . page ) <EOL> self . assertTrue ( refetch ( commit ) . reviewedversioncommit . is_approved ) <EOL> self . assertEqual ( self . page . root_node . commits . count ( ) , <NUM_LIT:1> ) <EOL> def test_save_and_commit_without_changes ( self ) : <EOL> with mock . patch ( '<STR_LIT>' ) as warning_mock : <EOL> super ( TestAdminButtonsWhenReviewed , self ) . test_save_and_commit_without_changes ( ) <EOL> warning_mock . assert_called_with ( mock . ANY , mock . ANY ) <EOL> def test_status_embryo ( self ) : <EOL> url = urlresolvers . reverse ( '<STR_LIT>' ) <EOL> with self . as_user ( '<STR_LIT>' ) : <EOL> response = self . client . get ( url ) <EOL> self . assertIn ( '<STR_LIT>' , response . rendered_content ) <EOL> def test_status_draft ( self ) : <EOL> self . page . status = CONTENT_STATUS_DRAFT <EOL> self . page . save ( ) <EOL> url = urlresolvers . reverse ( '<STR_LIT>' , args = ( self . page . pk , ) ) <EOL> with self . as_user ( '<STR_LIT>' ) : <EOL> response = self . client . get ( url ) <EOL> self . assertIn ( '<STR_LIT>' , response . rendered_content ) <EOL> self . assertIn ( '<STR_LIT>' , response . rendered_content ) <EOL> self . assertNotIn ( '<STR_LIT>' , response . rendered_content ) <EOL> with self . as_user ( '<STR_LIT>' ) : <EOL> response = self . client . get ( url ) <EOL> self . assertIn ( '<STR_LIT>' , response . rendered_content ) <EOL> self . assertIn ( '<STR_LIT>' , response . rendered_content ) <EOL> self . assertIn ( '<STR_LIT>' , response . rendered_content ) <EOL> def test_status_published ( self ) : <EOL> url = urlresolvers . reverse ( '<STR_LIT>' , args = ( self . page . pk , ) ) <EOL> with self . as_user ( '<STR_LIT>' ) : <EOL> response = self . client . get ( url ) <EOL> self . assertNotIn ( '<STR_LIT>' , response . rendered_content ) <EOL> self . assertIn ( '<STR_LIT>' , response . rendered_content ) <EOL> self . assertNotIn ( '<STR_LIT>' , response . rendered_content ) <EOL> with self . as_user ( '<STR_LIT>' ) : <EOL> response = self . client . get ( url ) <EOL> self . assertNotIn ( '<STR_LIT>' , response . rendered_content ) <EOL> self . assertIn ( '<STR_LIT>' , response . rendered_content ) <EOL> class TestAdminMessages ( PageSetup , TestCase ) : <EOL> urls = '<STR_LIT>' <EOL> def setUp ( self ) : <EOL> super ( TestAdminMessages , self ) . setUp ( ) <EOL> self . user = User . objects . create_superuser ( '<STR_LIT:test>' , '<STR_LIT>' , '<STR_LIT:password>' ) <EOL> self . client . login ( username = '<STR_LIT:test>' , password = '<STR_LIT:password>' ) <EOL> def test_future_schedule_message ( self ) : <EOL> url = urlresolvers . reverse ( '<STR_LIT>' , args = ( self . page . pk , ) ) <EOL> self . page . root_node . commit ( publish_at = timezone . now ( ) + datetime . timedelta ( days = <NUM_LIT:1> ) ) <EOL> response = self . client . get ( url ) <EOL> self . assertIn ( '<STR_LIT>' , response . rendered_content ) <EOL> self . page . root_node . commit ( ) <EOL> response = self . client . get ( url ) <EOL> self . assertNotIn ( '<STR_LIT>' , response . rendered_content ) <EOL> @ make_reviewed <EOL> def test_unapproved_commit_message ( self ) : <EOL> self . page = refetch ( self . page ) <EOL> url = urlresolvers . reverse ( '<STR_LIT>' , args = ( self . page . pk , ) ) <EOL> self . page . root_node . commit ( ) <EOL> response = self . client . get ( url ) <EOL> self . assertIn ( '<STR_LIT>' , response . rendered_content ) <EOL> new_commit = self . page . root_node . commit ( ) <EOL> new_commit . approve ( user = self . user ) <EOL> response = self . client . get ( url ) <EOL> self . assertNotIn ( '<STR_LIT>' , response . rendered_content ) <EOL> def refetch ( obj ) : <EOL> return obj . __class__ . objects . get ( pk = obj . pk ) <EOL> @ make_reviewed <EOL> class TestPublicationCommitHandling ( PageSetup , TestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestPublicationCommitHandling , self ) . setUp ( ) <EOL> self . user = User . objects . create_superuser ( <EOL> username = '<STR_LIT>' , password = '<STR_LIT>' , email = '<STR_LIT>' , <EOL> ) <EOL> self . vt = self . page . root_node <EOL> def test_publish_on_commit ( self ) : <EOL> self . page . status = CONTENT_STATUS_DRAFT <EOL> self . page . save ( ) <EOL> commit = self . vt . commit ( ) <EOL> commit . publish_at = timezone . now ( ) + datetime . timedelta ( days = <NUM_LIT:1> ) <EOL> self . assertEqual ( refetch ( self . page ) . status , CONTENT_STATUS_DRAFT ) <EOL> commit . approve ( self . user ) <EOL> self . assertEqual ( refetch ( self . page ) . status , CONTENT_STATUS_PUBLISHED ) <EOL> self . assertEqual ( refetch ( self . page ) . publish_date , refetch ( commit ) . publish_at ) <EOL> def test_committing_again_does_nothing ( self ) : <EOL> self . page . status = CONTENT_STATUS_DRAFT <EOL> self . page . save ( ) <EOL> commit = self . vt . commit ( ) <EOL> commit . approve ( self . user ) <EOL> original_publish_date = refetch ( self . page ) . publish_date <EOL> self . assertEqual ( refetch ( self . page ) . status , CONTENT_STATUS_PUBLISHED ) <EOL> self . vt . commit ( publish_at = timezone . now ( ) + datetime . timedelta ( days = <NUM_LIT:1> ) ) <EOL> self . assertEqual ( refetch ( self . page ) . status , CONTENT_STATUS_PUBLISHED ) <EOL> self . assertEqual ( refetch ( self . page ) . publish_date , original_publish_date ) <EOL> def test_publish_commit_moves_publish_date_up ( self ) : <EOL> self . page . publish_date = timezone . now ( ) + datetime . timedelta ( days = <NUM_LIT:1> ) <EOL> self . page . save ( ) <EOL> commit = self . vt . commit ( ) <EOL> commit . approve ( self . user ) <EOL> self . assertEqual ( refetch ( self . page ) . publish_date , refetch ( commit ) . publish_at ) <EOL> def test_unapprove_commit_unpublishes_page_when_there_are_no_other_published_commits ( self ) : <EOL> commit = self . vt . commit ( ) <EOL> commit . approve ( self . user ) <EOL> self . assertEqual ( refetch ( self . page ) . status , CONTENT_STATUS_PUBLISHED ) <EOL> commit . unapprove ( self . user ) <EOL> self . assertEqual ( refetch ( self . page ) . status , CONTENT_STATUS_DRAFT ) <EOL> def test_unapprove_commit_corrects_publish_date_there_is_another_commit ( self ) : <EOL> c1 = self . vt . commit ( ) <EOL> c1 . approve ( self . user ) <EOL> c2 = self . vt . commit ( publish_at = timezone . now ( ) + datetime . timedelta ( days = <NUM_LIT:1> ) ) <EOL> c2 . approve ( self . user ) <EOL> self . assertEqual ( refetch ( self . page ) . status , CONTENT_STATUS_PUBLISHED ) <EOL> c1 . unapprove ( self . user ) <EOL> self . assertEqual ( refetch ( self . page ) . status , CONTENT_STATUS_PUBLISHED ) <EOL> self . assertEqual ( refetch ( self . page ) . publish_date , refetch ( c2 ) . publish_at ) <EOL> class TestSelectRelated ( PageSetup , TestCase ) : <EOL> def test_default_manager_selects_related ( self ) : <EOL> p = Page . objects . get ( pk = self . page . pk ) . widgypage <EOL> with self . assertNumQueries ( <NUM_LIT:1> ) : <EOL> p . widgypage . root_node . head </s>
