Skip to content

Commit

Permalink
Adds functionality to internally manage to add and delete content ids…
Browse files Browse the repository at this point in the history
… into assets dict. (oppia#6171)
  • Loading branch information
DubeySandeep authored Feb 3, 2019
1 parent 6168048 commit 06f91ed
Show file tree
Hide file tree
Showing 40 changed files with 485 additions and 491 deletions.
63 changes: 32 additions & 31 deletions core/domain/exp_domain_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,35 +246,31 @@ def test_validation(self):
init_state = exploration.states[exploration.init_state_name]
default_outcome = init_state.interaction.default_outcome
default_outcome.dest = exploration.init_state_name
init_state.interaction.answer_groups.append(
state_domain.AnswerGroup.from_dict({
'outcome': {
'dest': exploration.init_state_name,
'feedback': {
'content_id': 'feedback_1',
'html': 'Feedback'
},
'labelled_as_correct': False,
'param_changes': [],
'refresher_exploration_id': None,
'missing_prerequisite_skill_id': None
old_answer_groups = copy.deepcopy(init_state.interaction.answer_groups)
old_answer_groups.append({
'outcome': {
'dest': exploration.init_state_name,
'feedback': {
'content_id': 'feedback_1',
'html': 'Feedback'
},
'rule_specs': [{
'inputs': {
'x': 'Test'
},
'rule_type': 'Contains'
}],
'training_data': [],
'tagged_misconception_id': None
})
)

init_state.update_content_ids_to_audio_translations({
'content': {},
'default_outcome': {},
'feedback_1': {}
'labelled_as_correct': False,
'param_changes': [],
'refresher_exploration_id': None,
'missing_prerequisite_skill_id': None
},
'rule_specs': [{
'inputs': {
'x': 'Test'
},
'rule_type': 'Contains'
}],
'training_data': [],
'tagged_misconception_id': None
})

init_state.update_interaction_answer_groups(old_answer_groups)

exploration.validate()

interaction = init_state.interaction
Expand Down Expand Up @@ -595,11 +591,17 @@ def test_content_ids_to_audio_translations_validation(self):
})
init_state.update_interaction_hints(hints_list)

# Changing content id directly for testing validation error.
init_state.interaction.hints[0].hint_content.content_id = 'hint_2'

self._assert_validation_error(
exploration,
r'Expected state content_ids_to_audio_translations to have all '
r'of the listed content ids \[\'content\', \'default_outcome\', '
r'\'hint_1\'\]')
r'\'hint_2\'\]')

# Undo above changes.
init_state.interaction.hints[0].hint_content.content_id = 'hint_1'

hints_list.append({
'hint_content': {
Expand All @@ -612,9 +614,8 @@ def test_content_ids_to_audio_translations_validation(self):
self._assert_validation_error(
exploration, 'Found a duplicate content id hint_1')

init_state.interaction.hints[1].hint_content.content_id = 'hint_2'
init_state.content_ids_to_audio_translations['hint_1'] = {}
init_state.content_ids_to_audio_translations['hint_2'] = {}
hints_list[1]['hint_content']['content_id'] = 'hint_2'
init_state.update_interaction_hints(hints_list)
exploration.validate()

def test_get_trainable_states_dict(self):
Expand Down
99 changes: 48 additions & 51 deletions core/domain/exp_services_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,6 @@ def test_reverting_an_exploration_maintains_classifier_models(self):
'property_name': (
exp_domain.STATE_PROPERTY_INTERACTION_ANSWER_GROUPS),
'new_value': interaction_answer_groups
}), exp_domain.ExplorationChange({
'cmd': exp_domain.CMD_EDIT_STATE_PROPERTY,
'state_name': feconf.DEFAULT_INIT_STATE_NAME,
'property_name': (
exp_domain.STATE_PROPERTY_CONTENT_IDS_TO_AUDIO_TRANSLATIONS),
'new_value': {
'content': {},
'feedback_1': {},
'default_outcome': {}
}
})]

with self.swap(feconf, 'ENABLE_ML_CLASSIFIERS', True):
Expand Down Expand Up @@ -1406,10 +1396,17 @@ def test_export_to_zip_file(self):
exploration = self.save_new_valid_exploration(
self.EXP_ID, self.owner_id, objective='The objective')
init_state = exploration.states[exploration.init_state_name]
init_interaction = init_state.interaction
init_interaction.default_outcome.dest = exploration.init_state_name
default_outcome_dict = init_state.interaction.default_outcome.to_dict()
default_outcome_dict['dest'] = exploration.init_state_name
exp_services.update_exploration(
self.owner_id, self.EXP_ID, [
exp_domain.ExplorationChange({
'cmd': exp_domain.CMD_EDIT_STATE_PROPERTY,
'property_name': (
exp_domain.STATE_PROPERTY_INTERACTION_DEFAULT_OUTCOME),
'state_name': exploration.init_state_name,
'new_value': default_outcome_dict
}),
exp_domain.ExplorationChange({
'cmd': exp_domain.CMD_ADD_STATE,
'state_name': 'New state',
Expand All @@ -1433,10 +1430,17 @@ def test_export_to_zip_file_with_assets(self):
exploration = self.save_new_valid_exploration(
self.EXP_ID, self.owner_id, objective='The objective')
init_state = exploration.states[exploration.init_state_name]
init_interaction = init_state.interaction
init_interaction.default_outcome.dest = exploration.init_state_name
default_outcome_dict = init_state.interaction.default_outcome.to_dict()
default_outcome_dict['dest'] = exploration.init_state_name
exp_services.update_exploration(
self.owner_id, self.EXP_ID, [
exp_domain.ExplorationChange({
'cmd': exp_domain.CMD_EDIT_STATE_PROPERTY,
'property_name': (
exp_domain.STATE_PROPERTY_INTERACTION_DEFAULT_OUTCOME),
'state_name': exploration.init_state_name,
'new_value': default_outcome_dict
}),
exp_domain.ExplorationChange({
'cmd': exp_domain.CMD_ADD_STATE,
'state_name': 'New state',
Expand Down Expand Up @@ -1469,9 +1473,15 @@ def test_export_by_versions(self):
self.assertEqual(exploration.version, 1)

init_state = exploration.states[exploration.init_state_name]
init_interaction = init_state.interaction
init_interaction.default_outcome.dest = exploration.init_state_name
default_outcome_dict = init_state.interaction.default_outcome.to_dict()
default_outcome_dict['dest'] = exploration.init_state_name
change_list = [exp_domain.ExplorationChange({
'cmd': exp_domain.CMD_EDIT_STATE_PROPERTY,
'property_name': (
exp_domain.STATE_PROPERTY_INTERACTION_DEFAULT_OUTCOME),
'state_name': exploration.init_state_name,
'new_value': default_outcome_dict
}), exp_domain.ExplorationChange({
'cmd': exp_domain.CMD_ADD_STATE,
'state_name': 'New state'
}), exp_domain.ExplorationChange({
Expand Down Expand Up @@ -1621,10 +1631,17 @@ def test_export_to_dict(self):
exploration = self.save_new_valid_exploration(
self.EXP_ID, self.owner_id, objective='The objective')
init_state = exploration.states[exploration.init_state_name]
init_interaction = init_state.interaction
init_interaction.default_outcome.dest = exploration.init_state_name
default_outcome_dict = init_state.interaction.default_outcome.to_dict()
default_outcome_dict['dest'] = exploration.init_state_name
exp_services.update_exploration(
self.owner_id, self.EXP_ID, [
exp_domain.ExplorationChange({
'cmd': exp_domain.CMD_EDIT_STATE_PROPERTY,
'property_name': (
exp_domain.STATE_PROPERTY_INTERACTION_DEFAULT_OUTCOME),
'state_name': exploration.init_state_name,
'new_value': default_outcome_dict
}),
exp_domain.ExplorationChange({
'cmd': exp_domain.CMD_ADD_STATE,
'state_name': 'New state',
Expand All @@ -1647,9 +1664,15 @@ def test_export_by_versions(self):
self.assertEqual(exploration.version, 1)

init_state = exploration.states[exploration.init_state_name]
init_interaction = init_state.interaction
init_interaction.default_outcome.dest = exploration.init_state_name
default_outcome_dict = init_state.interaction.default_outcome.to_dict()
default_outcome_dict['dest'] = exploration.init_state_name
change_list = [exp_domain.ExplorationChange({
'cmd': exp_domain.CMD_EDIT_STATE_PROPERTY,
'property_name': (
exp_domain.STATE_PROPERTY_INTERACTION_DEFAULT_OUTCOME),
'state_name': exploration.init_state_name,
'new_value': default_outcome_dict
}), exp_domain.ExplorationChange({
'cmd': exp_domain.CMD_ADD_STATE,
'state_name': 'New state'
}), exp_domain.ExplorationChange({
Expand Down Expand Up @@ -1750,12 +1773,6 @@ def setUp(self):
'missing_prerequisite_skill_id': None
}

self.content_ids_to_audio_translations = {
'content': {},
'default_outcome': {},
'feedback_1': {}
}

def test_add_state_cmd(self):
""" Test adding of states."""
exploration = exp_services.get_exploration_by_id(self.EXP_ID)
Expand Down Expand Up @@ -1931,11 +1948,7 @@ def test_update_interaction_handlers_fails(self):
_get_change_list(
self.init_state_name,
exp_domain.STATE_PROPERTY_INTERACTION_HANDLERS,
self.interaction_answer_groups) +
_get_change_list(
self.init_state_name,
exp_domain.STATE_PROPERTY_CONTENT_IDS_TO_AUDIO_TRANSLATIONS,
self.content_ids_to_audio_translations),
self.interaction_answer_groups),
'')

def test_update_interaction_answer_groups(self):
Expand Down Expand Up @@ -1967,11 +1980,7 @@ def test_update_interaction_answer_groups(self):
_get_change_list(
self.init_state_name,
exp_domain.STATE_PROPERTY_INTERACTION_DEFAULT_OUTCOME,
self.interaction_default_outcome) +
_get_change_list(
self.init_state_name,
exp_domain.STATE_PROPERTY_CONTENT_IDS_TO_AUDIO_TRANSLATIONS,
self.content_ids_to_audio_translations),
self.interaction_default_outcome),
'')

exploration = exp_services.get_exploration_by_id(self.EXP_ID)
Expand Down Expand Up @@ -2005,11 +2014,7 @@ def test_update_state_invalid_state(self):
_get_change_list(
self.init_state_name,
exp_domain.STATE_PROPERTY_INTERACTION_DEFAULT_OUTCOME,
self.interaction_default_outcome) +
_get_change_list(
self.init_state_name,
exp_domain.STATE_PROPERTY_CONTENT_IDS_TO_AUDIO_TRANSLATIONS,
self.content_ids_to_audio_translations),
self.interaction_default_outcome),
'')

def test_update_state_missing_keys(self):
Expand All @@ -2030,11 +2035,7 @@ def test_update_state_missing_keys(self):
_get_change_list(
self.init_state_name,
exp_domain.STATE_PROPERTY_INTERACTION_DEFAULT_OUTCOME,
self.interaction_default_outcome) +
_get_change_list(
self.init_state_name,
exp_domain.STATE_PROPERTY_CONTENT_IDS_TO_AUDIO_TRANSLATIONS,
self.content_ids_to_audio_translations),
self.interaction_default_outcome),
'')

def test_update_state_variable_types(self):
Expand All @@ -2055,11 +2056,7 @@ def test_update_state_variable_types(self):
_get_change_list(
self.init_state_name,
exp_domain.STATE_PROPERTY_INTERACTION_DEFAULT_OUTCOME,
self.interaction_default_outcome) +
_get_change_list(
self.init_state_name,
exp_domain.STATE_PROPERTY_CONTENT_IDS_TO_AUDIO_TRANSLATIONS,
self.content_ids_to_audio_translations),
self.interaction_default_outcome),
'')

def test_update_content(self):
Expand Down
Loading

0 comments on commit 06f91ed

Please sign in to comment.