def test_migration_job_migrates_collection_nodes(self): """Tests that the collection migration job migrates content from nodes to collection_contents if collection_contents is empty. """ # Create an exploration to put in the collection. self.save_new_default_exploration(self.EXP_ID, self.albert_id) node = collection_domain.CollectionNode.create_default_node( self.EXP_ID) # Create a collection directly using the model, so that the collection # nodes are stored in the 'nodes' property rather than the # 'collection_contents' property. collection_title = 'A title' collection_category = 'A category' rights_manager.create_new_collection_rights(self.COLLECTION_ID, self.albert_id) model = collection_models.CollectionModel( id=self.COLLECTION_ID, category=collection_category, title=collection_title, objective='An objective', tags=[], schema_version=2, nodes=[{ 'exploration_id': self.EXP_ID, 'prerequisite_skills': [], 'acquired_skills': [] }], ) model.commit(self.albert_id, 'Made a new collection!', [{ 'cmd': collection_services.CMD_CREATE_NEW, 'title': collection_title, 'category': collection_category, }]) # Save a collection summary object for indexing. The explicit commit # does not create a summary object, which is needed for the # job to update the index after updating the collection. collection_summary = collection_services.compute_summary_of_collection( model, self.albert_id) collection_services.save_collection_summary(collection_summary) # Check that collection_contents is empty. self.assertEqual(model.collection_contents, {}) # Run the job. This should populate collection_contents. job_id = (collection_jobs_one_off.CollectionMigrationJob.create_new()) collection_jobs_one_off.CollectionMigrationJob.enqueue(job_id) self.process_and_flush_pending_tasks() new_model = collection_models.CollectionModel.get(self.COLLECTION_ID) self.assertEqual(new_model.collection_contents, { 'nodes': [node.to_dict()], 'skills': {}, 'next_skill_index': 0 })
def map(model): if model.deleted: return if isinstance(model, collection_models.CollectionModel): summary = collection_services.get_collection_summary_by_id(model.id) summary.contributors_summary = ( collection_services.compute_collection_contributors_summary( model.id)) summary.contributor_ids = list(summary.contributors_summary) collection_services.save_collection_summary(summary) else: summary = exp_fetchers.get_exploration_summary_by_id(model.id) summary.contributors_summary = ( exp_services.compute_exploration_contributors_summary(model.id)) summary.contributor_ids = list(summary.contributors_summary) exp_services.save_exploration_summary(summary) yield ('SUCCESS', model.id)
def test_migrate_colections_failing_strict_validation(self): """Tests that the collection migration job migrates collections which do not pass strict validation. """ # Save a collection without an objective or explorations in version 1. collection_title = 'A title' collection_category = 'A category' rights_manager.create_new_collection_rights(self.COLLECTION_ID, self.albert_id) model = collection_models.CollectionModel( id=self.COLLECTION_ID, category=collection_title, title=collection_category, objective='', tags=[], schema_version=2, ) model.commit(self.albert_id, 'Made a new collection!', [{ 'cmd': collection_services.CMD_CREATE_NEW, 'title': collection_title, 'category': collection_category, }]) # Save a collection summary object for indexing. The explicit commit # does not create a summary object, which is needed for the # job to update the index after updating the collection. collection_summary = collection_services.compute_summary_of_collection( model, self.albert_id) collection_services.save_collection_summary(collection_summary) # Start migration job on sample collection. job_id = ( collection_jobs_one_off.CollectionMigrationOneOffJob.create_new()) collection_jobs_one_off.CollectionMigrationOneOffJob.enqueue(job_id) # This running without errors indicates the collection is migrated. self.process_and_flush_pending_tasks() # Check the version number of the new model. new_model = collection_models.CollectionModel.get(self.COLLECTION_ID) self.assertEqual(new_model.schema_version, feconf.CURRENT_COLLECTION_SCHEMA_VERSION)