<s> """<STR_LIT>""" <EOL> from core . domain import collection_services <EOL> from core . domain import collection_domain <EOL> from core . domain import config_domain <EOL> from core . domain import rights_manager <EOL> from core . tests import test_utils <EOL> import feconf <EOL> class BaseCollectionEditorControllerTest ( test_utils . GenericTestBase ) : <EOL> CAN_EDIT_STR = '<STR_LIT>' <EOL> CANNOT_EDIT_STR = '<STR_LIT>' <EOL> def setUp ( self ) : <EOL> """<STR_LIT>""" <EOL> super ( BaseCollectionEditorControllerTest , self ) . setUp ( ) <EOL> self . signup ( self . EDITOR_EMAIL , self . EDITOR_USERNAME ) <EOL> self . signup ( self . ADMIN_EMAIL , self . ADMIN_USERNAME ) <EOL> self . signup ( self . OWNER_EMAIL , self . OWNER_USERNAME ) <EOL> self . signup ( self . VIEWER_EMAIL , self . VIEWER_USERNAME ) <EOL> self . owner_id = self . get_user_id_from_email ( self . OWNER_EMAIL ) <EOL> self . editor_id = self . get_user_id_from_email ( self . EDITOR_EMAIL ) <EOL> self . viewer_id = self . get_user_id_from_email ( self . VIEWER_EMAIL ) <EOL> self . admin_id = self . get_user_id_from_email ( self . ADMIN_EMAIL ) <EOL> self . set_admins ( [ self . ADMIN_USERNAME ] ) <EOL> def assert_can_edit ( self , response_body ) : <EOL> """<STR_LIT>""" <EOL> self . assertIn ( self . CAN_EDIT_STR , response_body ) <EOL> self . assertNotIn ( self . CANNOT_EDIT_STR , response_body ) <EOL> def assert_cannot_edit ( self , response_body ) : <EOL> """<STR_LIT>""" <EOL> self . assertIn ( self . CANNOT_EDIT_STR , response_body ) <EOL> self . assertNotIn ( self . CAN_EDIT_STR , response_body ) <EOL> class CollectionEditorTest ( BaseCollectionEditorControllerTest ) : <EOL> COLLECTION_ID = '<STR_LIT:0>' <EOL> def setUp ( self ) : <EOL> super ( CollectionEditorTest , self ) . setUp ( ) <EOL> collection_services . load_demo ( self . COLLECTION_ID ) <EOL> rights_manager . release_ownership_of_collection ( <EOL> feconf . SYSTEM_COMMITTER_ID , self . COLLECTION_ID ) <EOL> def test_access_collection_editor_page ( self ) : <EOL> """<STR_LIT>""" <EOL> whitelisted_usernames = [ self . EDITOR_USERNAME ] <EOL> self . set_config_property ( <EOL> config_domain . WHITELISTED_COLLECTION_EDITOR_USERNAMES , <EOL> whitelisted_usernames ) <EOL> response = self . testapp . get ( <EOL> '<STR_LIT>' % ( feconf . COLLECTION_DATA_URL_PREFIX , <EOL> self . COLLECTION_ID ) ) <EOL> self . assertEqual ( response . status_int , <NUM_LIT:200> ) <EOL> self . assertIn ( '<STR_LIT>' , response . body ) <EOL> response = self . testapp . get ( <EOL> '<STR_LIT>' % ( feconf . COLLECTION_EDITOR_URL_PREFIX , <EOL> self . COLLECTION_ID ) ) <EOL> self . assertEqual ( response . status_int , <NUM_LIT> ) <EOL> self . login ( self . EDITOR_EMAIL ) <EOL> response = self . testapp . get ( <EOL> '<STR_LIT>' % ( feconf . COLLECTION_EDITOR_URL_PREFIX , <EOL> self . COLLECTION_ID ) ) <EOL> self . assertEqual ( response . status_int , <NUM_LIT:200> ) <EOL> self . assertIn ( '<STR_LIT>' , response . body ) <EOL> self . assert_can_edit ( response . body ) <EOL> self . logout ( ) <EOL> def test_collection_rights_handler ( self ) : <EOL> collection_id = '<STR_LIT>' <EOL> collection = collection_domain . Collection . create_default_collection ( <EOL> collection_id , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> collection_services . save_new_collection ( self . owner_id , collection ) <EOL> rights_manager . assign_role_for_collection ( <EOL> self . owner_id , collection_id , self . editor_id , <EOL> rights_manager . ROLE_EDITOR ) <EOL> rights_manager . publish_collection ( self . owner_id , collection_id ) <EOL> with self . assertRaisesRegexp ( <EOL> Exception , '<STR_LIT>' ) : <EOL> rights_manager . unpublish_collection ( self . owner_id , collection_id ) <EOL> collection_rights = rights_manager . get_collection_rights ( collection_id ) <EOL> self . assertEqual ( collection_rights . status , <EOL> rights_manager . ACTIVITY_STATUS_PUBLIC ) <EOL> rights_manager . unpublish_collection ( self . admin_id , collection_id ) <EOL> collection_rights = rights_manager . get_collection_rights ( collection_id ) <EOL> self . assertEqual ( collection_rights . status , <EOL> rights_manager . ACTIVITY_STATUS_PRIVATE ) </s>
