def post(self): """Handles POST requests.""" new_collection_id = collection_services.get_new_collection_id() collection = collection_domain.Collection.create_default_collection( new_collection_id) collection_services.save_new_collection(self.user_id, collection) self.render_json({COLLECTION_ID_KEY: new_collection_id})
def post(self): """Handles POST requests.""" new_collection_id = collection_services.get_new_collection_id() collection = collection_domain.Collection.create_default_collection( new_collection_id) collection_services.save_new_collection(self.user_id, collection) self.render_json({ COLLECTION_ID_KEY: new_collection_id })
def test_can_not_unpublish_collection_with_invalid_payload_version(self): self.set_collection_editors([self.OWNER_USERNAME]) # Login as owner and publish a collection with a public exploration. self.login(self.OWNER_EMAIL) collection_id = collection_services.get_new_collection_id() exploration_id = exp_services.get_new_exploration_id() self.save_new_valid_exploration(exploration_id, self.owner_id) self.save_new_valid_collection(collection_id, self.owner_id, exploration_id=exploration_id) rights_manager.publish_exploration(self.owner, exploration_id) collection = collection_services.get_collection_by_id(collection_id) response = self.get_html_response( '%s/%s' % (feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID)) csrf_token = self.get_csrf_token_from_response(response) response_dict = self.put_json('/collection_editor_handler/publish/%s' % collection_id, {'version': collection.version}, csrf_token=csrf_token) self.assertFalse(response_dict['is_private']) self.logout() # Login as admin and try to unpublish the collection. self.login(self.ADMIN_EMAIL) response = self.get_html_response( '%s/%s' % (feconf.COLLECTION_URL_PREFIX, self.COLLECTION_ID)) csrf_token = self.get_csrf_token_from_response(response) # Raises error as version is None. response_dict = self.put_json( '/collection_editor_handler/unpublish/%s' % collection_id, {'version': None}, csrf_token=csrf_token, expected_status_int=400) self.assertEqual(response_dict['error'], 'Invalid POST request: a version must be specified.') # Raises error as version from payload does not match the collection # version. response_dict = self.put_json( '/collection_editor_handler/unpublish/%s' % collection_id, {'version': 2}, csrf_token=csrf_token, expected_status_int=400) self.assertEqual( response_dict['error'], 'Trying to update version 1 of collection from version 2, ' 'which is too old. Please reload the page and try again.') self.logout()
def post(self): """Handles POST requests.""" title = self.payload.get('title') category = self.payload.get('category') objective = self.payload.get('objective') # TODO(bhenning): Implement support for language codes in collections. if not title: raise self.InvalidInputException('No title supplied.') if not category: raise self.InvalidInputException('No category chosen.') new_collection_id = collection_services.get_new_collection_id() collection = collection_domain.Collection.create_default_collection( new_collection_id, title, category, objective=objective) collection_services.save_new_collection(self.user_id, collection) self.render_json({COLLECTION_ID_KEY: new_collection_id})
def post(self): """Handles POST requests.""" title = self.payload.get('title') category = self.payload.get('category') objective = self.payload.get('objective') # TODO(bhenning): Implement support for language codes in collections. if not title: raise self.InvalidInputException('No title supplied.') if not category: raise self.InvalidInputException('No category chosen.') new_collection_id = collection_services.get_new_collection_id() collection = collection_domain.Collection.create_default_collection( new_collection_id, title, category, objective=objective) collection_services.save_new_collection(self.user_id, collection) self.render_json({ COLLECTION_ID_KEY: new_collection_id })
def test_can_not_publish_collection_with_invalid_payload_version(self): self.set_collection_editors([self.OWNER_USERNAME]) # Login as owner and try to publish a collection with a public # exploration. self.login(self.OWNER_EMAIL) collection_id = collection_services.get_new_collection_id() exploration_id = exp_fetchers.get_new_exploration_id() self.save_new_valid_exploration(exploration_id, self.owner_id) self.save_new_valid_collection(collection_id, self.owner_id, exploration_id=exploration_id) rights_manager.publish_exploration(self.owner, exploration_id) csrf_token = self.get_new_csrf_token() # Raises error as version is None. response_dict = self.put_json('/collection_editor_handler/publish/%s' % collection_id, {'version': None}, csrf_token=csrf_token, expected_status_int=400) self.assertEqual(response_dict['error'], 'Invalid POST request: a version must be specified.') # Raises error as version from payload does not match the collection # version. response_dict = self.put_json('/collection_editor_handler/publish/%s' % collection_id, {'version': 2}, csrf_token=csrf_token, expected_status_int=400) self.assertEqual( response_dict['error'], 'Trying to update version 1 of collection from version 2, ' 'which is too old. Please reload the page and try again.') self.logout()