<s> """<STR_LIT>""" <EOL> import os <EOL> from core . domain import exp_domain <EOL> from core . domain import exp_services <EOL> from core . domain import param_domain <EOL> from core . tests import test_utils <EOL> import feconf <EOL> import utils <EOL> SAMPLE_YAML_CONTENT = ( """<STR_LIT>""" ) % ( <EOL> feconf . DEFAULT_INIT_STATE_NAME , <EOL> exp_domain . Exploration . CURRENT_EXP_SCHEMA_VERSION , <EOL> feconf . DEFAULT_INIT_STATE_NAME , <EOL> feconf . DEFAULT_INIT_STATE_NAME , <EOL> feconf . CURRENT_EXPLORATION_STATES_SCHEMA_VERSION ) <EOL> SAMPLE_UNTITLED_YAML_CONTENT = ( """<STR_LIT>""" ) % ( <EOL> feconf . DEFAULT_INIT_STATE_NAME , <EOL> exp_domain . Exploration . LAST_UNTITLED_SCHEMA_VERSION , <EOL> feconf . DEFAULT_INIT_STATE_NAME , <EOL> feconf . DEFAULT_INIT_STATE_NAME , <EOL> feconf . CURRENT_EXPLORATION_STATES_SCHEMA_VERSION ) <EOL> SAMPLE_YAML_CONTENT_WITH_GADGETS = ( """<STR_LIT>""" ) % ( <EOL> feconf . DEFAULT_INIT_STATE_NAME , <EOL> exp_domain . Exploration . CURRENT_EXP_SCHEMA_VERSION , <EOL> feconf . DEFAULT_INIT_STATE_NAME , <EOL> feconf . DEFAULT_INIT_STATE_NAME , <EOL> feconf . CURRENT_EXPLORATION_STATES_SCHEMA_VERSION ) <EOL> TEST_GADGETS = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : os . path . join ( feconf . GADGETS_DIR , '<STR_LIT>' ) <EOL> } <EOL> } <EOL> TEST_GADGET_CUSTOMIZATION_ARGS = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:value>' : [ { <EOL> '<STR_LIT>' : '<STR_LIT:b>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ] <EOL> } <EOL> } <EOL> TEST_GADGET_DICT = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : TEST_GADGET_CUSTOMIZATION_ARGS , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] <EOL> } <EOL> class ExplorationDomainUnitTests ( test_utils . GenericTestBase ) : <EOL> """<STR_LIT>""" <EOL> def test_validation ( self ) : <EOL> """<STR_LIT>""" <EOL> exploration = exp_domain . Exploration . create_default_exploration ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> exploration . init_state_name = '<STR_LIT>' <EOL> exploration . states = { } <EOL> self . _assert_validation_error ( <EOL> exploration , '<STR_LIT>' ) <EOL> exploration . title = '<STR_LIT>' <EOL> self . _assert_validation_error ( exploration , '<STR_LIT>' ) <EOL> exploration . title = '<STR_LIT>' <EOL> self . _assert_validation_error ( <EOL> exploration , '<STR_LIT>' ) <EOL> exploration . category = '<STR_LIT>' <EOL> bad_state = exp_domain . State . create_default_state ( '<STR_LIT:/>' ) <EOL> exploration . states = { '<STR_LIT:/>' : bad_state } <EOL> self . _assert_validation_error ( <EOL> exploration , '<STR_LIT>' ) <EOL> new_state = exp_domain . State . create_default_state ( '<STR_LIT>' ) <EOL> new_state . update_interaction_id ( '<STR_LIT>' ) <EOL> exploration . states = { } <EOL> self . _assert_validation_error ( <EOL> exploration , '<STR_LIT>' ) <EOL> exploration . states = { '<STR_LIT>' : new_state } <EOL> self . _assert_validation_error ( <EOL> exploration , '<STR_LIT>' ) <EOL> exploration . states = { '<STR_LIT>' : new_state } <EOL> self . _assert_validation_error ( <EOL> exploration , '<STR_LIT>' ) <EOL> exploration . states = { '<STR_LIT>' : new_state } <EOL> self . _assert_validation_error ( <EOL> exploration , '<STR_LIT>' ) <EOL> exploration . init_state_name = '<STR_LIT>' <EOL> self . _assert_validation_error ( <EOL> exploration , <EOL> r'<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> exploration . states = { exploration . init_state_name : new_state } <EOL> self . _assert_validation_error ( <EOL> exploration , '<STR_LIT>' ) <EOL> init_state = exploration . states [ exploration . init_state_name ] <EOL> default_outcome = init_state . interaction . default_outcome <EOL> default_outcome . dest = exploration . init_state_name <EOL> exploration . validate ( ) <EOL> init_state . interaction . answer_groups . append ( <EOL> exp_domain . AnswerGroup . from_dict ( { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : exploration . init_state_name , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ ] , <EOL> } , <EOL> '<STR_LIT>' : [ { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] <EOL> } , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } , { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] <EOL> } , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ] <EOL> } ) <EOL> ) <EOL> self . _assert_validation_error ( <EOL> exploration , '<STR_LIT>' ) <EOL> init_state . interaction . answer_groups . pop ( ) <EOL> exploration . validate ( ) <EOL> init_state = exploration . states [ exploration . init_state_name ] <EOL> default_outcome = init_state . interaction . default_outcome <EOL> default_outcome . dest = exploration . init_state_name <EOL> init_state . interaction . answer_groups . append ( <EOL> exp_domain . AnswerGroup . from_dict ( { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : exploration . init_state_name , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ ] , <EOL> } , <EOL> '<STR_LIT>' : [ { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:x>' : '<STR_LIT>' <EOL> } , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ] <EOL> } ) <EOL> ) <EOL> exploration . validate ( ) <EOL> interaction = init_state . interaction <EOL> answer_groups = interaction . answer_groups <EOL> answer_group = answer_groups [ <NUM_LIT:0> ] <EOL> answer_group . outcome . dest = '<STR_LIT>' <EOL> self . _assert_validation_error ( <EOL> exploration , '<STR_LIT>' ) <EOL> exploration . states [ exploration . init_state_name ] . update_interaction_id ( <EOL> '<STR_LIT>' ) <EOL> answer_group . outcome . dest = exploration . init_state_name <EOL> exploration . validate ( ) <EOL> rule_spec = answer_group . rule_specs [ <NUM_LIT:0> ] <EOL> rule_spec . inputs = { } <EOL> self . _assert_validation_error ( <EOL> exploration , '<STR_LIT>' ) <EOL> rule_spec . inputs = '<STR_LIT>' <EOL> self . _assert_validation_error ( <EOL> exploration , '<STR_LIT>' ) <EOL> rule_spec . inputs = { '<STR_LIT:x>' : '<STR_LIT>' } <EOL> rule_spec . rule_type = '<STR_LIT>' <EOL> self . _assert_validation_error ( exploration , '<STR_LIT>' ) <EOL> rule_spec . inputs = { '<STR_LIT:x>' : <NUM_LIT:15> } <EOL> rule_spec . rule_type = '<STR_LIT>' <EOL> with self . assertRaisesRegexp ( <EOL> Exception , '<STR_LIT>' <EOL> ) : <EOL> exploration . validate ( ) <EOL> rule_spec . inputs = { '<STR_LIT:x>' : '<STR_LIT>' } <EOL> self . _assert_validation_error ( <EOL> exploration , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> exploration . param_specs [ '<STR_LIT>' ] = param_domain . ParamSpec ( <EOL> '<STR_LIT>' ) <EOL> exploration . validate ( ) <EOL> outcome = answer_group . outcome <EOL> destination = exploration . init_state_name <EOL> outcome . dest = None <EOL> self . _assert_validation_error ( <EOL> exploration , '<STR_LIT>' ) <EOL> outcome . dest = <NUM_LIT:15> <EOL> self . _assert_validation_error ( <EOL> exploration , '<STR_LIT>' ) <EOL> outcome . dest = destination <EOL> outcome . feedback = '<STR_LIT>' <EOL> self . _assert_validation_error ( <EOL> exploration , '<STR_LIT>' ) <EOL> outcome . feedback = [ <NUM_LIT:15> ] <EOL> self . _assert_validation_error ( <EOL> exploration , '<STR_LIT>' ) <EOL> outcome . feedback = [ '<STR_LIT>' ] <EOL> exploration . validate ( ) <EOL> outcome . param_changes = '<STR_LIT>' <EOL> self . _assert_validation_error ( <EOL> exploration , '<STR_LIT>' ) <EOL> outcome . param_changes = [ ] <EOL> exploration . validate ( ) <EOL> interaction . id = <NUM_LIT:15> <EOL> self . _assert_validation_error ( <EOL> exploration , '<STR_LIT>' ) <EOL> interaction . id = '<STR_LIT>' <EOL> self . _assert_validation_error ( exploration , '<STR_LIT>' ) <EOL> interaction . id = '<STR_LIT>' <EOL> exploration . validate ( ) <EOL> interaction . customization_args = [ ] <EOL> self . _assert_validation_error ( <EOL> exploration , '<STR_LIT>' ) <EOL> interaction . customization_args = { <NUM_LIT:15> : '<STR_LIT>' } <EOL> self . _assert_validation_error ( <EOL> exploration , '<STR_LIT>' ) <EOL> interaction . customization_args = { '<STR_LIT>' : '<STR_LIT>' } <EOL> exploration . validate ( ) <EOL> interaction . answer_groups = { } <EOL> self . _assert_validation_error ( <EOL> exploration , '<STR_LIT>' ) <EOL> interaction . answer_groups = answer_groups <EOL> interaction . id = '<STR_LIT>' <EOL> self . _assert_validation_error ( <EOL> exploration , <EOL> '<STR_LIT>' ) <EOL> interaction . id = '<STR_LIT>' <EOL> interaction . default_outcome = None <EOL> self . _assert_validation_error ( <EOL> exploration , <EOL> '<STR_LIT>' ) <EOL> interaction . id = '<STR_LIT>' <EOL> self . _assert_validation_error ( <EOL> exploration , <EOL> '<STR_LIT>' ) <EOL> interaction . answer_groups = [ ] <EOL> exploration . validate ( ) <EOL> interaction . fallbacks = { } <EOL> self . _assert_validation_error ( <EOL> exploration , '<STR_LIT>' ) <EOL> interaction . id = '<STR_LIT>' <EOL> interaction . answer_groups = answer_groups <EOL> interaction . default_outcome = default_outcome <EOL> interaction . fallbacks = [ ] <EOL> exploration . validate ( ) <EOL> answer_group . rule_specs = { } <EOL> self . _assert_validation_error ( <EOL> exploration , '<STR_LIT>' ) <EOL> answer_group . rule_specs = [ ] <EOL> self . _assert_validation_error ( <EOL> exploration , <EOL> '<STR_LIT>' ) <EOL> exploration . states = { <EOL> exploration . init_state_name : exp_domain . State . create_default_state ( <EOL> exploration . init_state_name ) <EOL> } <EOL> exploration . states [ exploration . init_state_name ] . update_interaction_id ( <EOL> '<STR_LIT>' ) <EOL> exploration . validate ( ) <EOL> exploration . language_code = '<STR_LIT>' <EOL> self . _assert_validation_error ( exploration , '<STR_LIT>' ) <EOL> exploration . language_code = '<STR_LIT>' <EOL> self . _assert_validation_error ( exploration , '<STR_LIT>' ) <EOL> exploration . language_code = '<STR_LIT>' <EOL> exploration . validate ( ) <EOL> exploration . param_specs = '<STR_LIT>' <EOL> self . _assert_validation_error ( exploration , '<STR_LIT>' ) <EOL> exploration . param_specs = { <EOL> '<STR_LIT:@>' : param_domain . ParamSpec . from_dict ( { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ) <EOL> } <EOL> self . _assert_validation_error ( <EOL> exploration , '<STR_LIT>' ) <EOL> exploration . param_specs = { <EOL> '<STR_LIT>' : param_domain . ParamSpec . from_dict ( <EOL> { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> } <EOL> exploration . validate ( ) <EOL> def test_fallbacks_validation ( self ) : <EOL> """<STR_LIT>""" <EOL> exploration = exp_domain . Exploration . create_default_exploration ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> exploration . objective = '<STR_LIT>' <EOL> init_state = exploration . states [ exploration . init_state_name ] <EOL> init_state . update_interaction_id ( '<STR_LIT>' ) <EOL> exploration . validate ( ) <EOL> base_outcome = { <EOL> '<STR_LIT>' : exploration . init_state_name , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> } <EOL> init_state . update_interaction_fallbacks ( [ { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:value>' : <NUM_LIT> , <EOL> } , <EOL> } , <EOL> } , <EOL> '<STR_LIT>' : base_outcome , <EOL> } ] ) <EOL> self . _assert_validation_error ( exploration , '<STR_LIT>' ) <EOL> with self . assertRaises ( KeyError ) : <EOL> init_state . update_interaction_fallbacks ( [ { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:value>' : <NUM_LIT> , <EOL> } , <EOL> } , <EOL> } , <EOL> '<STR_LIT>' : { } , <EOL> } ] ) <EOL> init_state . update_interaction_fallbacks ( [ { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { } , <EOL> } , <EOL> '<STR_LIT>' : base_outcome , <EOL> } ] ) <EOL> exploration . validate ( ) <EOL> self . assertEqual ( len ( init_state . interaction . fallbacks ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( <EOL> init_state . interaction . fallbacks [ <NUM_LIT:0> ] . trigger . customization_args , <EOL> { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:value>' : <NUM_LIT:3> , <EOL> } <EOL> } ) <EOL> init_state . update_interaction_fallbacks ( [ { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:value>' : <NUM_LIT> , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:value>' : '<STR_LIT>' , <EOL> } <EOL> } , <EOL> } , <EOL> '<STR_LIT>' : base_outcome , <EOL> } ] ) <EOL> exploration . validate ( ) <EOL> self . assertEqual ( len ( init_state . interaction . fallbacks ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( <EOL> init_state . interaction . fallbacks [ <NUM_LIT:0> ] . trigger . customization_args , <EOL> { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:value>' : <NUM_LIT> , <EOL> } <EOL> } ) <EOL> init_state . update_interaction_fallbacks ( [ { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:value>' : <NUM_LIT:2> , <EOL> } , <EOL> } , <EOL> } , <EOL> '<STR_LIT>' : base_outcome , <EOL> } ] ) <EOL> exploration . validate ( ) <EOL> def test_tag_validation ( self ) : <EOL> """<STR_LIT>""" <EOL> exploration = exp_domain . Exploration . create_default_exploration ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> exploration . objective = '<STR_LIT>' <EOL> init_state = exploration . states [ exploration . init_state_name ] <EOL> init_state . update_interaction_id ( '<STR_LIT>' ) <EOL> init_state . interaction . default_outcome = None <EOL> exploration . validate ( ) <EOL> exploration . tags = '<STR_LIT>' <EOL> self . _assert_validation_error ( <EOL> exploration , '<STR_LIT>' ) <EOL> exploration . tags = [ <NUM_LIT> ] <EOL> self . _assert_validation_error ( exploration , '<STR_LIT>' ) <EOL> exploration . tags = [ '<STR_LIT:abc>' , <NUM_LIT> ] <EOL> self . _assert_validation_error ( exploration , '<STR_LIT>' ) <EOL> exploration . tags = [ '<STR_LIT>' ] <EOL> self . _assert_validation_error ( exploration , '<STR_LIT>' ) <EOL> exploration . tags = [ '<STR_LIT>' ] <EOL> self . _assert_validation_error ( <EOL> exploration , '<STR_LIT>' ) <EOL> exploration . tags = [ '<STR_LIT>' ] <EOL> self . _assert_validation_error ( <EOL> exploration , '<STR_LIT>' ) <EOL> exploration . tags = [ '<STR_LIT>' ] <EOL> self . _assert_validation_error ( <EOL> exploration , '<STR_LIT>' ) <EOL> exploration . tags = [ '<STR_LIT>' ] <EOL> self . _assert_validation_error ( <EOL> exploration , '<STR_LIT>' ) <EOL> exploration . tags = [ '<STR_LIT>' ] <EOL> self . _assert_validation_error ( <EOL> exploration , '<STR_LIT>' ) <EOL> exploration . tags = [ '<STR_LIT:abc>' , '<STR_LIT:abc>' ] <EOL> self . _assert_validation_error ( <EOL> exploration , '<STR_LIT>' ) <EOL> exploration . tags = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> exploration . validate ( ) <EOL> def test_exploration_skin_and_gadget_validation ( self ) : <EOL> """<STR_LIT>""" <EOL> exploration = exp_domain . Exploration . from_yaml ( <EOL> '<STR_LIT>' , SAMPLE_YAML_CONTENT_WITH_GADGETS ) <EOL> invalid_gadget_instance = exp_domain . GadgetInstance ( <EOL> '<STR_LIT>' , '<STR_LIT>' , [ ] , { } ) <EOL> with self . assertRaisesRegexp ( <EOL> utils . ValidationError , <EOL> '<STR_LIT>' <EOL> ) : <EOL> invalid_gadget_instance . validate ( ) <EOL> with self . swap ( feconf , '<STR_LIT>' , TEST_GADGETS ) : <EOL> gadget_instance = exploration . skin_instance . panel_contents_dict [ <EOL> '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> gadget_instance . visible_in_states . extend ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . _assert_validation_error ( <EOL> exploration , '<STR_LIT>' ) <EOL> def_state = exp_domain . State . create_default_state ( '<STR_LIT>' ) <EOL> def_state . update_interaction_id ( '<STR_LIT>' ) <EOL> exploration . states [ '<STR_LIT>' ] = def_state <EOL> self . _assert_validation_error ( <EOL> exploration , '<STR_LIT>' ) <EOL> ghi_state = exp_domain . State . create_default_state ( '<STR_LIT>' ) <EOL> ghi_state . update_interaction_id ( '<STR_LIT>' ) <EOL> exploration . states [ '<STR_LIT>' ] = ghi_state <EOL> exploration . validate ( ) <EOL> gadget_instance . visible_in_states = [ '<STR_LIT>' ] <EOL> exploration . add_gadget ( TEST_GADGET_DICT , '<STR_LIT>' ) <EOL> exploration . skin_instance . panel_contents_dict [ <EOL> '<STR_LIT>' ] [ <NUM_LIT:1> ] . visible_in_states = [ '<STR_LIT>' ] <EOL> self . _assert_validation_error ( <EOL> exploration , <EOL> '<STR_LIT>' ) <EOL> exploration . skin_instance . panel_contents_dict [ '<STR_LIT>' ] . pop ( ) <EOL> gadget_instance . visible_in_states . extend ( [ '<STR_LIT>' ] ) <EOL> self . _assert_validation_error ( <EOL> exploration , <EOL> '<STR_LIT>' ) <EOL> gadget_instance . visible_in_states . pop ( ) <EOL> exploration . skin_instance . panel_contents_dict [ <EOL> '<STR_LIT>' ] = [ ] <EOL> self . _assert_validation_error ( <EOL> exploration , <EOL> '<STR_LIT>' ) <EOL> def test_gadget_name_validation ( self ) : <EOL> """<STR_LIT>""" <EOL> exploration = exp_domain . Exploration . from_yaml ( <EOL> '<STR_LIT>' , SAMPLE_YAML_CONTENT_WITH_GADGETS ) <EOL> with self . swap ( feconf , '<STR_LIT>' , TEST_GADGETS ) : <EOL> gadget_instance = exploration . skin_instance . panel_contents_dict [ <EOL> '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> gadget_instance . validate ( ) <EOL> gadget_instance . name = '<STR_LIT>' <EOL> self . _assert_validation_error ( <EOL> gadget_instance , '<STR_LIT>' ) <EOL> gadget_instance . name = <NUM_LIT:0> <EOL> self . _assert_validation_error ( <EOL> gadget_instance , <EOL> '<STR_LIT>' ) <EOL> gadget_instance . name = '<STR_LIT>' <EOL> max_length = exp_domain . GadgetInstance . _MAX_GADGET_NAME_LENGTH <EOL> self . _assert_validation_error ( <EOL> gadget_instance , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % max_length ) <EOL> gadget_instance . name = '<STR_LIT>' <EOL> self . _assert_validation_error ( <EOL> gadget_instance , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> gadget_instance . name = '<STR_LIT>' <EOL> self . _assert_validation_error ( <EOL> gadget_instance , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> gadget_instance . name = '<STR_LIT>' <EOL> self . _assert_validation_error ( <EOL> gadget_instance , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> gadget_instance . name = '<STR_LIT>' <EOL> self . _assert_validation_error ( <EOL> gadget_instance , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> gadget_instance . name = '<STR_LIT>' <EOL> self . _assert_validation_error ( <EOL> gadget_instance , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> gadget_instance . name = '<STR_LIT>' <EOL> gadget_instance . validate ( ) <EOL> def test_exploration_get_gadget_types ( self ) : <EOL> """<STR_LIT>""" <EOL> exploration_without_gadgets = exp_domain . Exploration . from_yaml ( <EOL> '<STR_LIT>' , SAMPLE_YAML_CONTENT ) <EOL> self . assertEqual ( exploration_without_gadgets . get_gadget_types ( ) , [ ] ) <EOL> exploration_with_gadgets = exp_domain . Exploration . from_yaml ( <EOL> '<STR_LIT>' , SAMPLE_YAML_CONTENT_WITH_GADGETS ) <EOL> self . assertEqual ( <EOL> exploration_with_gadgets . get_gadget_types ( ) , [ '<STR_LIT>' ] ) <EOL> another_gadget = exp_domain . GadgetInstance ( <EOL> '<STR_LIT>' , '<STR_LIT>' , [ ] , { } <EOL> ) <EOL> exploration_with_gadgets . skin_instance . panel_contents_dict [ <EOL> '<STR_LIT>' ] . append ( another_gadget ) <EOL> self . assertEqual ( <EOL> exploration_with_gadgets . get_gadget_types ( ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> def test_objective_validation ( self ) : <EOL> """<STR_LIT>""" <EOL> self . save_new_valid_exploration ( <EOL> '<STR_LIT>' , '<STR_LIT>' , title = '<STR_LIT>' , category = '<STR_LIT>' , <EOL> objective = '<STR_LIT>' , end_state_name = '<STR_LIT>' ) <EOL> exploration = exp_services . get_exploration_by_id ( '<STR_LIT>' ) <EOL> exploration . validate ( ) <EOL> with self . assertRaisesRegexp ( <EOL> utils . ValidationError , '<STR_LIT>' <EOL> ) : <EOL> exploration . validate ( strict = True ) <EOL> exploration . objective = '<STR_LIT>' <EOL> exploration . validate ( strict = True ) <EOL> def test_is_demo_property ( self ) : <EOL> """<STR_LIT>""" <EOL> demo = exp_domain . Exploration . create_default_exploration ( <EOL> '<STR_LIT:0>' , '<STR_LIT:title>' , '<STR_LIT>' ) <EOL> self . assertEqual ( demo . is_demo , True ) <EOL> notdemo1 = exp_domain . Exploration . create_default_exploration ( <EOL> '<STR_LIT:a>' , '<STR_LIT:title>' , '<STR_LIT>' ) <EOL> self . assertEqual ( notdemo1 . is_demo , False ) <EOL> notdemo2 = exp_domain . Exploration . create_default_exploration ( <EOL> '<STR_LIT>' , '<STR_LIT:title>' , '<STR_LIT>' ) <EOL> self . assertEqual ( notdemo2 . is_demo , False ) <EOL> def test_exploration_export_import ( self ) : <EOL> """<STR_LIT>""" <EOL> demo = exp_domain . Exploration . create_default_exploration ( <EOL> '<STR_LIT:0>' , '<STR_LIT:title>' , '<STR_LIT>' ) <EOL> demo_dict = demo . to_dict ( ) <EOL> exp_from_dict = exp_domain . Exploration . from_dict ( demo_dict ) <EOL> self . assertEqual ( exp_from_dict . to_dict ( ) , demo_dict ) <EOL> def test_interaction_with_none_id_is_not_terminal ( self ) : <EOL> """<STR_LIT>""" <EOL> demo = exp_domain . Exploration . create_default_exploration ( <EOL> '<STR_LIT:0>' , '<STR_LIT:title>' , '<STR_LIT>' ) <EOL> init_state = demo . states [ feconf . DEFAULT_INIT_STATE_NAME ] <EOL> self . assertFalse ( init_state . interaction . is_terminal ) <EOL> class StateExportUnitTests ( test_utils . GenericTestBase ) : <EOL> """<STR_LIT>""" <EOL> def test_export_state_to_dict ( self ) : <EOL> """<STR_LIT>""" <EOL> exploration = exp_domain . Exploration . create_default_exploration ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> exploration . add_states ( [ '<STR_LIT>' ] ) <EOL> state_dict = exploration . states [ '<STR_LIT>' ] . to_dict ( ) <EOL> expected_dict = { <EOL> '<STR_LIT:content>' : [ { <EOL> '<STR_LIT:type>' : '<STR_LIT:text>' , <EOL> '<STR_LIT:value>' : u'<STR_LIT>' <EOL> } ] , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> } , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT:id>' : None , <EOL> } , <EOL> '<STR_LIT>' : [ ] , <EOL> } <EOL> self . assertEqual ( expected_dict , state_dict ) <EOL> class YamlCreationUnitTests ( test_utils . GenericTestBase ) : <EOL> """<STR_LIT>""" <EOL> EXP_ID = '<STR_LIT>' <EOL> def test_yaml_import_and_export ( self ) : <EOL> """<STR_LIT>""" <EOL> exploration = exp_domain . Exploration . create_default_exploration ( <EOL> self . EXP_ID , '<STR_LIT>' , '<STR_LIT>' ) <EOL> exploration . add_states ( [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( len ( exploration . states ) , <NUM_LIT:2> ) <EOL> exploration . states [ '<STR_LIT>' ] . update_interaction_fallbacks ( [ { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:value>' : <NUM_LIT> , <EOL> } , <EOL> } , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> } , <EOL> } ] ) <EOL> exploration . validate ( ) <EOL> yaml_content = exploration . to_yaml ( ) <EOL> self . assertEqual ( yaml_content , SAMPLE_YAML_CONTENT ) <EOL> exploration2 = exp_domain . Exploration . from_yaml ( '<STR_LIT>' , yaml_content ) <EOL> self . assertEqual ( len ( exploration2 . states ) , <NUM_LIT:2> ) <EOL> yaml_content_2 = exploration2 . to_yaml ( ) <EOL> self . assertEqual ( yaml_content_2 , yaml_content ) <EOL> with self . assertRaises ( Exception ) : <EOL> exp_domain . Exploration . from_yaml ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> with self . assertRaises ( Exception ) : <EOL> exp_domain . Exploration . from_yaml ( <EOL> '<STR_LIT>' , '<STR_LIT>' ) <EOL> with self . assertRaises ( Exception ) : <EOL> exp_domain . Exploration . from_yaml ( <EOL> '<STR_LIT>' , '<STR_LIT>' ) <EOL> with self . assertRaisesRegexp ( <EOL> Exception , '<STR_LIT>' <EOL> ) : <EOL> exp_domain . Exploration . from_yaml ( <EOL> '<STR_LIT>' , SAMPLE_UNTITLED_YAML_CONTENT ) <EOL> with self . assertRaisesRegexp ( <EOL> Exception , '<STR_LIT>' <EOL> ) : <EOL> exp_domain . Exploration . from_untitled_yaml ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , SAMPLE_YAML_CONTENT ) <EOL> def test_yaml_import_and_export_without_gadgets ( self ) : <EOL> """<STR_LIT>""" <EOL> exploration_without_gadgets = exp_domain . Exploration . from_yaml ( <EOL> self . EXP_ID , SAMPLE_YAML_CONTENT ) <EOL> yaml_content = exploration_without_gadgets . to_yaml ( ) <EOL> self . assertEqual ( yaml_content , SAMPLE_YAML_CONTENT ) <EOL> def test_yaml_import_and_export_with_gadgets ( self ) : <EOL> """<STR_LIT>""" <EOL> exploration_with_gadgets = exp_domain . Exploration . from_yaml ( <EOL> self . EXP_ID , SAMPLE_YAML_CONTENT_WITH_GADGETS ) <EOL> with self . swap ( feconf , '<STR_LIT>' , TEST_GADGETS ) : <EOL> generated_yaml = exploration_with_gadgets . to_yaml ( ) <EOL> generated_yaml_as_dict = utils . dict_from_yaml ( generated_yaml ) <EOL> sample_yaml_as_dict = utils . dict_from_yaml ( <EOL> SAMPLE_YAML_CONTENT_WITH_GADGETS ) <EOL> self . assertEqual ( generated_yaml_as_dict , sample_yaml_as_dict ) <EOL> class SchemaMigrationMethodsUnitTests ( test_utils . GenericTestBase ) : <EOL> """<STR_LIT>""" <EOL> def test_correct_states_schema_conversion_methods_exist ( self ) : <EOL> """<STR_LIT>""" <EOL> current_states_schema_version = ( <EOL> feconf . CURRENT_EXPLORATION_STATES_SCHEMA_VERSION ) <EOL> for version_num in range ( current_states_schema_version ) : <EOL> self . assertTrue ( hasattr ( <EOL> exp_domain . Exploration , <EOL> '<STR_LIT>' % ( <EOL> version_num , version_num + <NUM_LIT:1> ) ) ) <EOL> self . assertFalse ( hasattr ( <EOL> exp_domain . Exploration , <EOL> '<STR_LIT>' % ( <EOL> current_states_schema_version , <EOL> current_states_schema_version + <NUM_LIT:1> ) ) ) <EOL> def test_correct_exploration_schema_conversion_methods_exist ( self ) : <EOL> """<STR_LIT>""" <EOL> current_exp_schema_version = ( <EOL> exp_domain . Exploration . CURRENT_EXP_SCHEMA_VERSION ) <EOL> for version_num in range ( <NUM_LIT:1> , current_exp_schema_version ) : <EOL> self . assertTrue ( hasattr ( <EOL> exp_domain . Exploration , <EOL> '<STR_LIT>' % ( <EOL> version_num , version_num + <NUM_LIT:1> ) ) ) <EOL> self . assertFalse ( hasattr ( <EOL> exp_domain . Exploration , <EOL> '<STR_LIT>' % ( <EOL> current_exp_schema_version , current_exp_schema_version + <NUM_LIT:1> ) ) ) <EOL> class SchemaMigrationUnitTests ( test_utils . GenericTestBase ) : <EOL> """<STR_LIT>""" <EOL> YAML_CONTENT_V1 = ( """<STR_LIT>""" ) <EOL> YAML_CONTENT_V2 = ( """<STR_LIT>""" ) <EOL> YAML_CONTENT_V3 = ( """<STR_LIT>""" ) <EOL> YAML_CONTENT_V4 = ( """<STR_LIT>""" ) <EOL> YAML_CONTENT_V5 = ( """<STR_LIT>""" ) <EOL> YAML_CONTENT_V6 = ( """<STR_LIT>""" ) <EOL> YAML_CONTENT_V7 = ( """<STR_LIT>""" ) <EOL> YAML_CONTENT_V8 = ( """<STR_LIT>""" ) <EOL> YAML_CONTENT_V9 = ( """<STR_LIT>""" ) <EOL> YAML_CONTENT_V10 = ( """<STR_LIT>""" ) <EOL> _LATEST_YAML_CONTENT = YAML_CONTENT_V10 <EOL> def test_load_from_v1 ( self ) : <EOL> """<STR_LIT>""" <EOL> exploration = exp_domain . Exploration . from_untitled_yaml ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , self . YAML_CONTENT_V1 ) <EOL> self . assertEqual ( exploration . to_yaml ( ) , self . _LATEST_YAML_CONTENT ) <EOL> def test_load_from_v2 ( self ) : <EOL> """<STR_LIT>""" <EOL> exploration = exp_domain . Exploration . from_untitled_yaml ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , self . YAML_CONTENT_V2 ) <EOL> self . assertEqual ( exploration . to_yaml ( ) , self . _LATEST_YAML_CONTENT ) <EOL> def test_load_from_v3 ( self ) : <EOL> """<STR_LIT>""" <EOL> exploration = exp_domain . Exploration . from_untitled_yaml ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , self . YAML_CONTENT_V3 ) <EOL> self . assertEqual ( exploration . to_yaml ( ) , self . _LATEST_YAML_CONTENT ) <EOL> def test_load_from_v4 ( self ) : <EOL> """<STR_LIT>""" <EOL> exploration = exp_domain . Exploration . from_untitled_yaml ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , self . YAML_CONTENT_V4 ) <EOL> self . assertEqual ( exploration . to_yaml ( ) , self . _LATEST_YAML_CONTENT ) <EOL> def test_load_from_v5 ( self ) : <EOL> """<STR_LIT>""" <EOL> exploration = exp_domain . Exploration . from_untitled_yaml ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , self . YAML_CONTENT_V5 ) <EOL> self . assertEqual ( exploration . to_yaml ( ) , self . _LATEST_YAML_CONTENT ) <EOL> def test_load_from_v6 ( self ) : <EOL> """<STR_LIT>""" <EOL> exploration = exp_domain . Exploration . from_untitled_yaml ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , self . YAML_CONTENT_V6 ) <EOL> self . assertEqual ( exploration . to_yaml ( ) , self . _LATEST_YAML_CONTENT ) <EOL> def test_load_from_v7 ( self ) : <EOL> """<STR_LIT>""" <EOL> exploration = exp_domain . Exploration . from_untitled_yaml ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , self . YAML_CONTENT_V7 ) <EOL> self . assertEqual ( exploration . to_yaml ( ) , self . _LATEST_YAML_CONTENT ) <EOL> def test_load_from_v8 ( self ) : <EOL> """<STR_LIT>""" <EOL> exploration = exp_domain . Exploration . from_untitled_yaml ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , self . YAML_CONTENT_V8 ) <EOL> self . assertEqual ( exploration . to_yaml ( ) , self . _LATEST_YAML_CONTENT ) <EOL> def test_load_from_v9 ( self ) : <EOL> """<STR_LIT>""" <EOL> exploration = exp_domain . Exploration . from_untitled_yaml ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , self . YAML_CONTENT_V9 ) <EOL> self . assertEqual ( exploration . to_yaml ( ) , self . _LATEST_YAML_CONTENT ) <EOL> def test_load_from_v10 ( self ) : <EOL> """<STR_LIT>""" <EOL> exploration = exp_domain . Exploration . from_yaml ( <EOL> '<STR_LIT>' , self . YAML_CONTENT_V10 ) <EOL> self . assertEqual ( exploration . to_yaml ( ) , self . _LATEST_YAML_CONTENT ) <EOL> class ConversionUnitTests ( test_utils . GenericTestBase ) : <EOL> """<STR_LIT>""" <EOL> def test_convert_exploration_to_player_dict ( self ) : <EOL> exp_title = '<STR_LIT>' <EOL> second_state_name = '<STR_LIT>' <EOL> exploration = exp_domain . Exploration . create_default_exploration ( <EOL> '<STR_LIT>' , exp_title , '<STR_LIT>' ) <EOL> exploration . add_states ( [ second_state_name ] ) <EOL> def _get_default_state_dict ( content_str , dest_name ) : <EOL> return { <EOL> '<STR_LIT:content>' : [ { <EOL> '<STR_LIT:type>' : '<STR_LIT:text>' , <EOL> '<STR_LIT:value>' : content_str , <EOL> } ] , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : dest_name , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> } , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT:id>' : None , <EOL> } , <EOL> '<STR_LIT>' : [ ] , <EOL> } <EOL> self . assertEqual ( exploration . to_player_dict ( ) , { <EOL> '<STR_LIT>' : feconf . DEFAULT_INIT_STATE_NAME , <EOL> '<STR_LIT:title>' : exp_title , <EOL> '<STR_LIT>' : { <EOL> feconf . DEFAULT_INIT_STATE_NAME : _get_default_state_dict ( <EOL> feconf . DEFAULT_INIT_STATE_CONTENT_STR , <EOL> feconf . DEFAULT_INIT_STATE_NAME ) , <EOL> second_state_name : _get_default_state_dict ( <EOL> '<STR_LIT>' , second_state_name ) , <EOL> } , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT>' : ( <EOL> exp_domain . SkinInstance . _get_default_skin_customizations ( ) <EOL> ) , <EOL> } ) <EOL> class StateOperationsUnitTests ( test_utils . GenericTestBase ) : <EOL> """<STR_LIT>""" <EOL> def test_delete_state ( self ) : <EOL> """<STR_LIT>""" <EOL> exploration = exp_domain . Exploration . create_default_exploration ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> exploration . add_states ( [ '<STR_LIT>' ] ) <EOL> with self . assertRaisesRegexp ( <EOL> ValueError , '<STR_LIT>' <EOL> ) : <EOL> exploration . delete_state ( exploration . init_state_name ) <EOL> exploration . add_states ( [ '<STR_LIT>' ] ) <EOL> exploration . delete_state ( '<STR_LIT>' ) <EOL> with self . assertRaisesRegexp ( ValueError , '<STR_LIT>' ) : <EOL> exploration . delete_state ( '<STR_LIT>' ) <EOL> def test_state_operations ( self ) : <EOL> """<STR_LIT>""" <EOL> exploration = exp_domain . Exploration . create_default_exploration ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertNotIn ( '<STR_LIT>' , exploration . states ) <EOL> self . assertEqual ( len ( exploration . states ) , <NUM_LIT:1> ) <EOL> default_state_name = exploration . init_state_name <EOL> exploration . rename_state ( default_state_name , '<STR_LIT>' ) <EOL> self . assertEqual ( len ( exploration . states ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( exploration . init_state_name , '<STR_LIT>' ) <EOL> exploration . add_states ( [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( len ( exploration . states ) , <NUM_LIT:2> ) <EOL> exploration . rename_state ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> with self . assertRaisesRegexp ( ValueError , '<STR_LIT>' ) : <EOL> exploration . add_states ( [ '<STR_LIT>' ] ) <EOL> with self . assertRaisesRegexp ( ValueError , '<STR_LIT>' ) : <EOL> exploration . rename_state ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> exploration . rename_state ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> exploration . rename_state ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertNotIn ( default_state_name , exploration . states ) <EOL> self . assertIn ( '<STR_LIT>' , exploration . states ) <EOL> self . assertIn ( '<STR_LIT>' , exploration . states ) <EOL> exploration . add_states ( [ '<STR_LIT>' ] ) <EOL> with self . assertRaisesRegexp ( ValueError , '<STR_LIT>' ) : <EOL> exploration . rename_state ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> exploration . states [ <EOL> '<STR_LIT>' ] . interaction . default_outcome . dest = '<STR_LIT>' <EOL> exploration . states [ '<STR_LIT>' ] . interaction . default_outcome . dest = '<STR_LIT>' <EOL> exploration . states [ '<STR_LIT>' ] . update_interaction_id ( '<STR_LIT>' ) <EOL> exploration . states [ '<STR_LIT>' ] . update_interaction_id ( '<STR_LIT>' ) <EOL> exploration . objective = '<STR_LIT>' <EOL> with self . assertRaises ( Exception ) : <EOL> exploration . validate ( strict = True ) <EOL> exploration . rename_state ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> another_end_state = exploration . states [ '<STR_LIT>' ] <EOL> another_end_state . update_interaction_id ( '<STR_LIT>' ) <EOL> another_end_state . interaction . default_outcome = None <EOL> exploration . validate ( strict = True ) <EOL> exploration . rename_state ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> exploration . delete_state ( '<STR_LIT>' ) <EOL> self . assertNotIn ( '<STR_LIT>' , exploration . states ) <EOL> class GadgetOperationsUnitTests ( test_utils . GenericTestBase ) : <EOL> """<STR_LIT>""" <EOL> def test_gadget_operations ( self ) : <EOL> """<STR_LIT>""" <EOL> exploration = exp_domain . Exploration . create_default_exploration ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> with self . swap ( feconf , '<STR_LIT>' , TEST_GADGETS ) : <EOL> exploration . add_gadget ( TEST_GADGET_DICT , '<STR_LIT>' ) <EOL> self . assertEqual ( exploration . skin_instance . panel_contents_dict [ <EOL> '<STR_LIT>' ] [ <NUM_LIT:0> ] . type , TEST_GADGET_DICT [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( exploration . skin_instance . panel_contents_dict [ <EOL> '<STR_LIT>' ] [ <NUM_LIT:0> ] . name , TEST_GADGET_DICT [ '<STR_LIT>' ] ) <EOL> with self . assertRaisesRegexp ( <EOL> ValueError , '<STR_LIT>' <EOL> ) : <EOL> exploration . rename_gadget ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> exploration . rename_gadget ( <EOL> TEST_GADGET_DICT [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( exploration . skin_instance . panel_contents_dict [ <EOL> '<STR_LIT>' ] [ <NUM_LIT:0> ] . name , '<STR_LIT>' ) <EOL> with self . swap ( feconf , '<STR_LIT>' , TEST_GADGETS ) : <EOL> exploration . add_gadget ( TEST_GADGET_DICT , '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> exploration . get_all_gadget_names ( ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> with self . assertRaisesRegexp ( <EOL> ValueError , '<STR_LIT>' <EOL> ) : <EOL> exploration . rename_gadget ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> gadget_instance = exploration . get_gadget_instance_by_name ( <EOL> '<STR_LIT>' ) <EOL> self . assertIs ( <EOL> exploration . skin_instance . panel_contents_dict [ '<STR_LIT>' ] [ <NUM_LIT:0> ] , <EOL> gadget_instance <EOL> ) <EOL> panel = exploration . _get_panel_for_gadget ( '<STR_LIT>' ) <EOL> self . assertEqual ( panel , '<STR_LIT>' ) <EOL> exploration . delete_gadget ( '<STR_LIT>' ) <EOL> exploration . delete_gadget ( '<STR_LIT>' ) <EOL> self . assertEqual ( exploration . skin_instance . panel_contents_dict [ <EOL> '<STR_LIT>' ] , [ ] ) <EOL> with self . assertRaisesRegexp ( <EOL> ValueError , '<STR_LIT>' <EOL> ) : <EOL> exploration . delete_gadget ( '<STR_LIT>' ) <EOL> class SkinInstanceUnitTests ( test_utils . GenericTestBase ) : <EOL> """<STR_LIT>""" <EOL> _SAMPLE_SKIN_INSTANCE_DICT = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ <EOL> { <EOL> '<STR_LIT>' : TEST_GADGET_CUSTOMIZATION_ARGS , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> } <EOL> ] <EOL> } <EOL> } <EOL> } <EOL> def test_get_state_names_required_by_gadgets ( self ) : <EOL> """<STR_LIT>""" <EOL> skin_instance = exp_domain . SkinInstance ( <EOL> '<STR_LIT>' , <EOL> self . _SAMPLE_SKIN_INSTANCE_DICT [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( <EOL> skin_instance . get_state_names_required_by_gadgets ( ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_generation_of_get_default_skin_customizations ( self ) : <EOL> """<STR_LIT>""" <EOL> skin_instance = exp_domain . SkinInstance ( feconf . DEFAULT_SKIN_ID , None ) <EOL> self . assertEqual ( <EOL> skin_instance . panel_contents_dict , <EOL> { '<STR_LIT>' : [ ] } <EOL> ) <EOL> def test_conversion_of_skin_to_and_from_dict ( self ) : <EOL> """<STR_LIT>""" <EOL> exploration = exp_domain . Exploration . from_yaml ( <EOL> '<STR_LIT>' , SAMPLE_YAML_CONTENT_WITH_GADGETS ) <EOL> skin_instance = exploration . skin_instance <EOL> skin_instance_as_dict = skin_instance . to_dict ( ) <EOL> self . assertEqual ( <EOL> skin_instance_as_dict , <EOL> self . _SAMPLE_SKIN_INSTANCE_DICT ) <EOL> skin_instance_as_instance = exp_domain . SkinInstance . from_dict ( <EOL> skin_instance_as_dict ) <EOL> self . assertEqual ( skin_instance_as_instance . skin_id , '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> sorted ( skin_instance_as_instance . panel_contents_dict . keys ( ) ) , <EOL> [ '<STR_LIT>' ] ) <EOL> class GadgetInstanceUnitTests ( test_utils . GenericTestBase ) : <EOL> """<STR_LIT>""" <EOL> def test_gadget_instantiation ( self ) : <EOL> """<STR_LIT>""" <EOL> exploration = exp_domain . Exploration . from_yaml ( <EOL> '<STR_LIT>' , SAMPLE_YAML_CONTENT_WITH_GADGETS ) <EOL> self . assertEqual ( len ( exploration . skin_instance . panel_contents_dict [ <EOL> '<STR_LIT>' ] ) , <NUM_LIT:1> ) <EOL> def test_gadget_instance_properties ( self ) : <EOL> """<STR_LIT>""" <EOL> exploration = exp_domain . Exploration . from_yaml ( <EOL> '<STR_LIT>' , SAMPLE_YAML_CONTENT_WITH_GADGETS ) <EOL> panel_contents_dict = exploration . skin_instance . panel_contents_dict <EOL> with self . swap ( feconf , '<STR_LIT>' , TEST_GADGETS ) : <EOL> test_gadget_instance = panel_contents_dict [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> self . assertEqual ( test_gadget_instance . height , <NUM_LIT:50> ) <EOL> self . assertEqual ( test_gadget_instance . width , <NUM_LIT> ) <EOL> self . assertIn ( '<STR_LIT>' , test_gadget_instance . visible_in_states ) <EOL> def test_gadget_instance_validation ( self ) : <EOL> """<STR_LIT>""" <EOL> exploration = exp_domain . Exploration . from_yaml ( <EOL> '<STR_LIT>' , SAMPLE_YAML_CONTENT_WITH_GADGETS ) <EOL> panel_contents_dict = exploration . skin_instance . panel_contents_dict <EOL> with self . swap ( feconf , '<STR_LIT>' , TEST_GADGETS ) : <EOL> test_gadget_instance = panel_contents_dict [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> exploration . validate ( ) <EOL> with self . swap ( <EOL> test_gadget_instance . gadget , <EOL> '<STR_LIT>' , <EOL> <NUM_LIT> ) : <EOL> self . _assert_validation_error ( <EOL> exploration , <EOL> '<STR_LIT>' ) <EOL> test_gadget_instance . customization_args [ <EOL> '<STR_LIT>' ] [ '<STR_LIT:value>' ] . extend ( <EOL> [ <EOL> { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } , <EOL> { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } , <EOL> { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> ] <EOL> ) <EOL> with self . assertRaisesRegexp ( <EOL> utils . ValidationError , <EOL> '<STR_LIT>' <EOL> ) : <EOL> test_gadget_instance . validate ( ) <EOL> test_gadget_instance . customization_args [ <EOL> '<STR_LIT>' ] [ '<STR_LIT:value>' ] . pop ( ) <EOL> panel_contents_dict [ '<STR_LIT>' ] . append ( test_gadget_instance ) <EOL> with self . assertRaisesRegexp ( <EOL> utils . ValidationError , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) : <EOL> exploration . validate ( ) <EOL> test_gadget_instance . visible_in_states = [ ] <EOL> with self . assertRaisesRegexp ( <EOL> utils . ValidationError , <EOL> '<STR_LIT>' ) : <EOL> test_gadget_instance . validate ( ) <EOL> def test_conversion_of_gadget_instance_to_and_from_dict ( self ) : <EOL> """<STR_LIT>""" <EOL> exploration = exp_domain . Exploration . from_yaml ( <EOL> '<STR_LIT>' , SAMPLE_YAML_CONTENT_WITH_GADGETS ) <EOL> panel_contents_dict = exploration . skin_instance . panel_contents_dict <EOL> test_gadget_instance = panel_contents_dict [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> test_gadget_as_dict = test_gadget_instance . to_dict ( ) <EOL> self . assertEqual ( <EOL> test_gadget_as_dict , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : TEST_GADGET_CUSTOMIZATION_ARGS <EOL> } <EOL> ) <EOL> test_gadget_as_instance = exp_domain . GadgetInstance . from_dict ( <EOL> test_gadget_as_dict ) <EOL> self . assertEqual ( test_gadget_as_instance . width , <NUM_LIT> ) <EOL> self . assertEqual ( test_gadget_as_instance . height , <NUM_LIT:50> ) <EOL> class GadgetVisibilityInStatesUnitTests ( test_utils . GenericTestBase ) : <EOL> """<STR_LIT>""" <EOL> def test_retrieving_affected_gadgets ( self ) : <EOL> """<STR_LIT>""" <EOL> exploration = exp_domain . Exploration . from_yaml ( <EOL> '<STR_LIT>' , SAMPLE_YAML_CONTENT_WITH_GADGETS ) <EOL> affected_gadget_instances = ( <EOL> exploration . _get_gadget_instances_visible_in_state ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( len ( affected_gadget_instances ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( affected_gadget_instances [ <NUM_LIT:0> ] . name , '<STR_LIT>' ) </s>
