def test_set_display_name_user_template_as_anonymous_raises_access_control_error( self, ): mock_request = create_mock_request(user=self.anonymous_user) with self.assertRaises(AccessControlError): template_api.set_display_name(self.fixture.user1_template, "new_name", request=mock_request)
def insert(template_version_manager, template): """Add a version to a template version manager. Args: template_version_manager: template: Returns: """ # save the template in database template_api.upsert(template) try: # insert the initial template in the version manager version_manager_api.insert_version(template_version_manager, template) # insert the version manager in database version_manager_api.upsert(template_version_manager) # get template display name display_name = get_latest_version_name(template_version_manager) # update saved template template_api.set_display_name(template, display_name) # return version manager return template_version_manager except Exception, e: template_api.delete(template) raise e
def test_set_display_name_other_users_template_as_staff_raises_access_control_error( self, ): mock_request = create_mock_request(user=self.staff_user1) with self.assertRaises(AccessControlError): template_api.set_display_name(self.fixture.user2_template, "new_name", request=mock_request)
def insert(type_version_manager, type_object, request, list_bucket_ids=None): """Add a version to a type version manager. Args: type_version_manager: type_object: request: list_bucket_ids: Returns: """ # save the type in database type_api.upsert(type_object, request=request) try: # insert the initial template in the version manager version_manager_api.insert_version( type_version_manager, type_object, request=request ) # insert the version manager in database version_manager_api.upsert(type_version_manager, request=request) # Add to the selected buckets bucket_api.add_type_to_buckets(type_version_manager, list_bucket_ids) # get type display name display_name = get_latest_version_name(type_version_manager) # update saved template template_api.set_display_name(type_object, display_name, request=request) # update saved type return type_version_manager except Exception as e: type_api.delete(type_object, request=request) raise e
def update_templates_display_name(template_version_manager): """Update templates display name. Args: template_version_manager: Returns: """ # Iterate versions for i in range(0, len(template_version_manager.versions)): # get template id from list of versions template_id = template_version_manager.versions[i] # get template from template id template = template_api.get(template_id) # get display name for the template display_name = get_version_name(template_version_manager.title, i + 1) # update template's display name template_api.set_display_name(template, display_name)
def test_set_display_name_global_template_as_superuser_saves(self): mock_request = create_mock_request(user=self.superuser1) template_api.set_display_name(self.fixture.global_template, "new_name", request=mock_request)
def test_set_display_name_own_template_as_staff_saves(self): mock_request = create_mock_request(user=self.staff_user1) template_api.set_display_name(self.fixture.user1_template, "new_name", request=mock_request)