<s> """<STR_LIT>""" <EOL> from core . domain import collection_domain <EOL> from core . domain import collection_services <EOL> from core . tests import test_utils <EOL> import feconf <EOL> import utils <EOL> SAMPLE_YAML_CONTENT = ( """<STR_LIT>""" ) % ( feconf . CURRENT_COLLECTION_SCHEMA_VERSION ) <EOL> class CollectionDomainUnitTests ( test_utils . GenericTestBase ) : <EOL> """<STR_LIT>""" <EOL> COLLECTION_ID = '<STR_LIT>' <EOL> EXPLORATION_ID = '<STR_LIT>' <EOL> def setUp ( self ) : <EOL> super ( CollectionDomainUnitTests , self ) . setUp ( ) <EOL> self . save_new_valid_collection ( <EOL> self . COLLECTION_ID , '<STR_LIT>' , title = '<STR_LIT>' , <EOL> category = '<STR_LIT>' , objective = '<STR_LIT>' , <EOL> exploration_id = self . EXPLORATION_ID ) <EOL> self . collection = collection_services . get_collection_by_id ( <EOL> self . COLLECTION_ID ) <EOL> def _assert_validation_error ( self , expected_error_substring ) : <EOL> """<STR_LIT>""" <EOL> with self . assertRaisesRegexp ( <EOL> utils . ValidationError , expected_error_substring ) : <EOL> self . collection . validate ( ) <EOL> def test_initial_validation ( self ) : <EOL> """<STR_LIT>""" <EOL> self . collection . validate ( ) <EOL> def test_title_validation ( self ) : <EOL> self . collection . title = <NUM_LIT:0> <EOL> self . _assert_validation_error ( '<STR_LIT>' ) <EOL> def test_category_validation ( self ) : <EOL> self . collection . category = <NUM_LIT:0> <EOL> self . _assert_validation_error ( '<STR_LIT>' ) <EOL> def test_objective_validation ( self ) : <EOL> self . collection . objective = '<STR_LIT>' <EOL> self . _assert_validation_error ( '<STR_LIT>' ) <EOL> self . collection . objective = <NUM_LIT:0> <EOL> self . _assert_validation_error ( '<STR_LIT>' ) <EOL> def test_schema_version_validation ( self ) : <EOL> self . collection . schema_version = '<STR_LIT>' <EOL> self . _assert_validation_error ( '<STR_LIT>' ) <EOL> self . collection . schema_version = <NUM_LIT:100> <EOL> self . _assert_validation_error ( <EOL> '<STR_LIT>' % <EOL> feconf . CURRENT_COLLECTION_SCHEMA_VERSION ) <EOL> def test_nodes_validation ( self ) : <EOL> self . collection . nodes = { } <EOL> self . _assert_validation_error ( '<STR_LIT>' ) <EOL> self . collection . nodes = [ <EOL> collection_domain . CollectionNode . from_dict ( { <EOL> '<STR_LIT>' : '<STR_LIT:0>' , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] <EOL> } ) , <EOL> collection_domain . CollectionNode . from_dict ( { <EOL> '<STR_LIT>' : '<STR_LIT:0>' , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] <EOL> } ) <EOL> ] <EOL> self . _assert_validation_error ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def test_initial_explorations_validation ( self ) : <EOL> self . collection . nodes = [ ] <EOL> self . collection . validate ( strict = False ) <EOL> self . _assert_validation_error ( <EOL> '<STR_LIT>' ) <EOL> self . collection . add_node ( '<STR_LIT>' ) <EOL> self . save_new_valid_exploration ( <EOL> '<STR_LIT>' , '<STR_LIT>' , end_state_name = '<STR_LIT>' ) <EOL> collection_node1 = self . collection . get_node ( '<STR_LIT>' ) <EOL> collection_node1 . update_prerequisite_skills ( [ '<STR_LIT>' ] ) <EOL> self . _assert_validation_error ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def test_collection_completability_validation ( self ) : <EOL> self . collection . add_node ( '<STR_LIT>' ) <EOL> collection_node1 = self . collection . get_node ( '<STR_LIT>' ) <EOL> collection_node1 . update_prerequisite_skills ( [ '<STR_LIT>' ] ) <EOL> self . _assert_validation_error ( <EOL> '<STR_LIT>' ) <EOL> collection_node0 = self . collection . get_node ( '<STR_LIT>' ) <EOL> collection_node0 . update_acquired_skills ( [ '<STR_LIT>' ] ) <EOL> self . collection . validate ( ) <EOL> def test_collection_node_exploration_id_validation ( self ) : <EOL> collection_node0 = self . collection . get_node ( '<STR_LIT>' ) <EOL> collection_node0 . exploration_id = <NUM_LIT:2> <EOL> self . _assert_validation_error ( '<STR_LIT>' ) <EOL> def test_collection_node_prerequisite_skills_validation ( self ) : <EOL> collection_node0 = self . collection . get_node ( '<STR_LIT>' ) <EOL> collection_node0 . prerequisite_skills = { } <EOL> self . _assert_validation_error ( <EOL> '<STR_LIT>' ) <EOL> collection_node0 . prerequisite_skills = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . _assert_validation_error ( <EOL> '<STR_LIT>' ) <EOL> collection_node0 . prerequisite_skills = [ '<STR_LIT>' , <NUM_LIT:2> ] <EOL> self . _assert_validation_error ( <EOL> '<STR_LIT>' ) <EOL> def test_collection_node_acquired_skills_validation ( self ) : <EOL> collection_node0 = self . collection . get_node ( '<STR_LIT>' ) <EOL> collection_node0 . acquired_skills = { } <EOL> self . _assert_validation_error ( '<STR_LIT>' ) <EOL> collection_node0 . acquired_skills = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . _assert_validation_error ( <EOL> '<STR_LIT>' ) <EOL> collection_node0 . acquired_skills = [ '<STR_LIT>' , <NUM_LIT:2> ] <EOL> self . _assert_validation_error ( <EOL> '<STR_LIT>' ) <EOL> def test_collection_node_skills_validation ( self ) : <EOL> collection_node0 = self . collection . get_node ( '<STR_LIT>' ) <EOL> collection_node0 . prerequisite_skills = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> collection_node0 . acquired_skills = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . _assert_validation_error ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def test_is_demo_property ( self ) : <EOL> """<STR_LIT>""" <EOL> demo = collection_domain . Collection . create_default_collection ( <EOL> '<STR_LIT:0>' , '<STR_LIT:title>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( demo . is_demo , True ) <EOL> notdemo1 = collection_domain . Collection . create_default_collection ( <EOL> '<STR_LIT:a>' , '<STR_LIT:title>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( notdemo1 . is_demo , False ) <EOL> notdemo2 = collection_domain . Collection . create_default_collection ( <EOL> '<STR_LIT>' , '<STR_LIT:title>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( notdemo2 . is_demo , False ) <EOL> def test_collection_export_import ( self ) : <EOL> """<STR_LIT>""" <EOL> self . save_new_valid_exploration ( <EOL> '<STR_LIT:0>' , '<STR_LIT>' , end_state_name = '<STR_LIT>' ) <EOL> collection = collection_domain . Collection . create_default_collection ( <EOL> '<STR_LIT:0>' , '<STR_LIT:title>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> collection_dict = collection . to_dict ( ) <EOL> collection_from_dict = collection_domain . Collection . from_dict ( <EOL> collection_dict ) <EOL> self . assertEqual ( collection_from_dict . to_dict ( ) , collection_dict ) <EOL> def test_add_delete_node ( self ) : <EOL> """<STR_LIT>""" <EOL> collection = collection_domain . Collection . create_default_collection ( <EOL> '<STR_LIT:0>' , '<STR_LIT:title>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( len ( collection . nodes ) , <NUM_LIT:0> ) <EOL> collection . add_node ( '<STR_LIT>' ) <EOL> self . assertEqual ( len ( collection . nodes ) , <NUM_LIT:1> ) <EOL> with self . assertRaisesRegexp ( <EOL> ValueError , <EOL> '<STR_LIT>' <EOL> ) : <EOL> collection . add_node ( '<STR_LIT>' ) <EOL> collection . add_node ( '<STR_LIT>' ) <EOL> self . assertEqual ( len ( collection . nodes ) , <NUM_LIT:2> ) <EOL> collection . delete_node ( '<STR_LIT>' ) <EOL> self . assertEqual ( len ( collection . nodes ) , <NUM_LIT:1> ) <EOL> with self . assertRaisesRegexp ( <EOL> ValueError , <EOL> '<STR_LIT>' <EOL> ) : <EOL> collection . delete_node ( '<STR_LIT>' ) <EOL> collection . delete_node ( '<STR_LIT>' ) <EOL> self . assertEqual ( len ( collection . nodes ) , <NUM_LIT:0> ) <EOL> def test_skills_property ( self ) : <EOL> collection = collection_domain . Collection . create_default_collection ( <EOL> '<STR_LIT:0>' , '<STR_LIT:title>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( collection . skills , [ ] ) <EOL> collection . add_node ( '<STR_LIT>' ) <EOL> collection . add_node ( '<STR_LIT>' ) <EOL> collection . get_node ( '<STR_LIT>' ) . update_acquired_skills ( <EOL> [ '<STR_LIT>' ] ) <EOL> collection . get_node ( '<STR_LIT>' ) . update_prerequisite_skills ( <EOL> [ '<STR_LIT>' ] ) <EOL> collection . get_node ( '<STR_LIT>' ) . update_acquired_skills ( <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( collection . skills , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> collection . add_node ( '<STR_LIT>' ) <EOL> collection . get_node ( '<STR_LIT>' ) . update_acquired_skills ( <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( collection . skills , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> class ExplorationGraphUnitTests ( test_utils . GenericTestBase ) : <EOL> """<STR_LIT>""" <EOL> def test_initial_explorations ( self ) : <EOL> """<STR_LIT>""" <EOL> collection = collection_domain . Collection . create_default_collection ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( collection . nodes , [ ] ) <EOL> self . assertEqual ( collection . init_exploration_ids , [ ] ) <EOL> collection . add_node ( '<STR_LIT>' ) <EOL> self . assertEqual ( collection . init_exploration_ids , [ '<STR_LIT>' ] ) <EOL> collection . add_node ( '<STR_LIT>' ) <EOL> self . assertEqual ( len ( collection . nodes ) , <NUM_LIT:2> ) <EOL> collection . get_node ( '<STR_LIT>' ) . update_prerequisite_skills ( <EOL> [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( collection . init_exploration_ids , [ '<STR_LIT>' ] ) <EOL> collection . add_node ( '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> collection . init_exploration_ids , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_next_explorations ( self ) : <EOL> """<STR_LIT>""" <EOL> collection = collection_domain . Collection . create_default_collection ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( collection . get_next_exploration_ids ( [ ] ) , [ ] ) <EOL> collection . add_node ( '<STR_LIT>' ) <EOL> self . assertEqual ( collection . get_next_exploration_ids ( [ ] ) , [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( <EOL> collection . init_exploration_ids , <EOL> collection . get_next_exploration_ids ( [ ] ) ) <EOL> self . assertEqual ( collection . get_next_exploration_ids ( [ '<STR_LIT>' ] ) , [ ] ) <EOL> collection_node1 = collection . get_node ( '<STR_LIT>' ) <EOL> collection_node1 . update_prerequisite_skills ( [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( collection . get_next_exploration_ids ( [ ] ) , [ ] ) <EOL> collection . add_node ( '<STR_LIT>' ) <EOL> collection_node2 = collection . get_node ( '<STR_LIT>' ) <EOL> collection_node1 . update_acquired_skills ( [ '<STR_LIT>' ] ) <EOL> collection_node2 . update_prerequisite_skills ( [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( collection . get_next_exploration_ids ( [ ] ) , [ ] ) <EOL> self . assertEqual ( collection . get_next_exploration_ids ( <EOL> [ '<STR_LIT>' ] ) , [ '<STR_LIT>' ] ) <EOL> collection . add_node ( '<STR_LIT>' ) <EOL> collection_node0 = collection . get_node ( '<STR_LIT>' ) <EOL> collection_node0 . update_acquired_skills ( [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( <EOL> collection . get_next_exploration_ids ( [ ] ) , [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( <EOL> collection . get_next_exploration_ids ( [ '<STR_LIT>' ] ) , [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( <EOL> collection . get_next_exploration_ids ( [ '<STR_LIT>' , '<STR_LIT>' ] ) , <EOL> [ '<STR_LIT>' ] ) <EOL> collection . add_node ( '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> collection . get_next_exploration_ids ( [ ] ) , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> collection_node3 = collection . get_node ( '<STR_LIT>' ) <EOL> collection_node3 . update_prerequisite_skills ( [ '<STR_LIT>' ] ) <EOL> collection_node0 . update_acquired_skills ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( <EOL> collection . get_next_exploration_ids ( [ ] ) , [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( <EOL> collection . get_next_exploration_ids ( [ '<STR_LIT>' ] ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( <EOL> collection . get_next_exploration_ids ( [ '<STR_LIT>' , '<STR_LIT>' ] ) , <EOL> [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( <EOL> collection . get_next_exploration_ids ( [ '<STR_LIT>' , '<STR_LIT>' ] ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( <EOL> collection . get_next_exploration_ids ( <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) , [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( <EOL> collection . get_next_exploration_ids ( <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) , [ ] ) <EOL> def test_next_explorations_with_invalid_exploration_ids ( self ) : <EOL> collection = collection_domain . Collection . create_default_collection ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> collection . add_node ( '<STR_LIT>' ) <EOL> self . assertEqual ( collection . get_next_exploration_ids ( [ ] ) , [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( <EOL> collection . get_next_exploration_ids ( [ '<STR_LIT>' ] ) , [ '<STR_LIT>' ] ) <EOL> class YamlCreationUnitTests ( test_utils . GenericTestBase ) : <EOL> """<STR_LIT>""" <EOL> COLLECTION_ID = '<STR_LIT>' <EOL> EXPLORATION_ID = '<STR_LIT>' <EOL> def test_yaml_import_and_export ( self ) : <EOL> """<STR_LIT>""" <EOL> self . save_new_valid_exploration ( <EOL> self . EXPLORATION_ID , '<STR_LIT>' , end_state_name = '<STR_LIT>' ) <EOL> collection = collection_domain . Collection . create_default_collection ( <EOL> self . COLLECTION_ID , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> collection . add_node ( self . EXPLORATION_ID ) <EOL> self . assertEqual ( len ( collection . nodes ) , <NUM_LIT:1> ) <EOL> collection_node = collection . get_node ( self . EXPLORATION_ID ) <EOL> collection_node . update_acquired_skills ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> collection . validate ( ) <EOL> yaml_content = collection . to_yaml ( ) <EOL> self . assertEqual ( yaml_content , SAMPLE_YAML_CONTENT ) <EOL> collection2 = collection_domain . Collection . from_yaml ( <EOL> '<STR_LIT>' , yaml_content ) <EOL> self . assertEqual ( len ( collection2 . nodes ) , <NUM_LIT:1> ) <EOL> yaml_content_2 = collection2 . to_yaml ( ) <EOL> self . assertEqual ( yaml_content_2 , yaml_content ) <EOL> with self . assertRaises ( Exception ) : <EOL> collection_domain . Collection . from_yaml ( '<STR_LIT>' , None ) <EOL> class SchemaMigrationUnitTests ( test_utils . GenericTestBase ) : <EOL> """<STR_LIT>""" <EOL> YAML_CONTENT_V1 = ( """<STR_LIT>""" ) <EOL> _LATEST_YAML_CONTENT = YAML_CONTENT_V1 <EOL> def test_load_from_v1 ( self ) : <EOL> """<STR_LIT>""" <EOL> self . save_new_valid_exploration ( <EOL> '<STR_LIT>' , '<STR_LIT>' , end_state_name = '<STR_LIT>' ) <EOL> collection = collection_domain . Collection . from_yaml ( <EOL> '<STR_LIT>' , self . YAML_CONTENT_V1 ) <EOL> self . assertEqual ( collection . to_yaml ( ) , self . _LATEST_YAML_CONTENT ) </s>
