Skip to content

Commit

Permalink
Remaining changes for the oppia#15861 (oppia#16525)
Browse files Browse the repository at this point in the history
* made remaining changes

* removed validation

* updated rte part

* reverted the changes for soup encoding

* added continue for the validation

* fixed coverage

* coverage
  • Loading branch information
lkbhitesh07 authored Nov 16, 2022
1 parent 5471941 commit cc1376a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 50 deletions.
5 changes: 2 additions & 3 deletions core/domain/exp_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -3345,7 +3345,7 @@ def _choices_should_be_unique_and_non_empty(
if state_dict['interaction']['solution'] is not None:
solution = state_dict['interaction']['solution']['correct_answer']
if isinstance(solution, list) and any(
invalid_choice['html'] in solution for invalid_choice in
invalid_choice['content_id'] in solution for invalid_choice in
choices_to_remove
):
state_dict['interaction']['solution'] = None
Expand Down Expand Up @@ -4360,7 +4360,6 @@ def _fix_drag_and_drop_input_interaction(
ele_element = ele_x_at_y_rule['element']
assert isinstance(ele_position, int)
if ele_position > len(rule_spec_val_x):
invalid_rules.append(rule_spec)
continue
rule_choice = rule_spec_val_x[ele_position - 1]

Expand Down Expand Up @@ -4898,7 +4897,7 @@ def fix_content(cls, html: str) -> str:
html = cls._fix_rte_tags(
html, is_tags_nested_inside_tabs_or_collapsible=False)
html = cls._fix_tabs_and_collapsible_tags(html)
return html
return html.replace('\xa0', ' ')

@classmethod
def _update_state_rte(
Expand Down
84 changes: 44 additions & 40 deletions core/domain/exp_domain_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2197,18 +2197,15 @@ def test_drag_and_drop_interaction(self) -> None:
state_domain.AnswerGroup.from_dict({
'rule_specs': [
{
'rule_type': 'HasElementXAtPositionY',
'inputs': {
'x': 'ca_choices_0',
'y': 4
}
},
{
'rule_type': 'IsEqualToOrdering',
'rule_type': (
'IsEqualToOrderingWithOneItemAtIncorrectPosition'),
'inputs': {
'x': [
[
'ca_choices_0', 'ca_choices_1', 'ca_choices_2'
'ca_choices_0'
],
[
'ca_choices_1', 'ca_choices_2'
],
[
'ca_choices_3'
Expand All @@ -2217,8 +2214,7 @@ def test_drag_and_drop_interaction(self) -> None:
}
},
{
'rule_type': (
'IsEqualToOrderingWithOneItemAtIncorrectPosition'),
'rule_type': 'IsEqualToOrdering',
'inputs': {
'x': [
[
Expand All @@ -2233,18 +2229,22 @@ def test_drag_and_drop_interaction(self) -> None:
]
}
},
{
'rule_type': 'HasElementXAtPositionY',
'inputs': {
'x': 'ca_choices_0',
'y': 4
}
},
{
'rule_type': 'IsEqualToOrdering',
'inputs': {
'x': [
[
'ca_choices_0'
],
[
'ca_choices_1', 'ca_choices_2'
'ca_choices_3'
],
[
'ca_choices_3'
'ca_choices_0', 'ca_choices_1', 'ca_choices_2'
]
]
}
Expand Down Expand Up @@ -2402,21 +2402,6 @@ def test_drag_and_drop_interaction(self) -> None:
state_domain.SubtitledHtml('ca_choices_2', '<p>3</p>')
]

self.state.interaction.customization_args[
'allowMultipleItemsInSamePosition'].value = True

with self.assertRaisesRegex(
utils.ValidationError, 'Rule - 1 of answer group 0 '
'does not have the enough position to match for the '
'HasElementXAtPositionY rule above.'
):
self.new_exploration.validate(strict=True)
rule_specs.remove(rule_specs[0])
rule_specs.remove(rule_specs[0])

self.state.interaction.customization_args[
'allowMultipleItemsInSamePosition'].value = False

with self.assertRaisesRegex(
utils.ValidationError, 'The rule \'0\' of answer group \'0\' '
'having rule type - IsEqualToOrderingWithOneItemAtIncorrectPosition'
Expand All @@ -2437,12 +2422,14 @@ def test_drag_and_drop_interaction(self) -> None:
self.state.interaction.customization_args[
'allowMultipleItemsInSamePosition'].value = True
with self.assertRaisesRegex(
utils.ValidationError, 'The rule \'1\' of answer group \'0\', '
utils.ValidationError, 'The rule \'3\' of answer group \'0\', '
'the value 1 and value 2 cannot be same when rule type is '
'HasElementXBeforeElementY of DragAndDropSortInput interaction.'
):
self.new_exploration.validate(strict=True)
rule_specs.remove(rule_specs[1])
rule_specs.remove(rule_specs[1])
rule_specs.remove(rule_specs[1])

self._assert_validation_error(
self.new_exploration, 'The rule \'1\'of answer group \'0\', '
Expand Down Expand Up @@ -9856,7 +9843,7 @@ def test_fixing_invalid_item_selec_exp_data_by_migrating_to_v58(
solution:
answer_is_exclusive: true
correct_answer:
- <p>1</p>
- ca_choices_20
explanation:
content_id: solution
html: This is <i>solution</i> for state1
Expand Down Expand Up @@ -10019,7 +10006,7 @@ def test_fixing_invalid_item_selec_exp_data_by_migrating_to_v58(
solution:
answer_is_exclusive: true
correct_answer:
- <p>1</p>
- ca_choices_20
explanation:
content_id: solution
html: This is <i>solution</i> for state1
Expand Down Expand Up @@ -10219,7 +10206,7 @@ def test_fixing_invalid_item_selec_exp_data_by_migrating_to_v58(
solution:
answer_is_exclusive: true
correct_answer:
- <p> </p>
- ca_choices_23
explanation:
content_id: solution
html: This is <i>solution</i> for state1
Expand Down Expand Up @@ -11058,11 +11045,6 @@ def test_fixing_invalid_drag_and_drop_exp_data_by_migrating_to_v58(
x: ca_choices_27
y: 4
rule_type: HasElementXAtPositionY
- inputs:
x:
- - ca_choices_29
- - ca_choices_28
rule_type: IsEqualToOrdering
tagged_skill_misconception_id: null
training_data: []
confirmed_unclassified_answers: []
Expand Down Expand Up @@ -11354,6 +11336,17 @@ def test_fixing_invalid_drag_and_drop_exp_data_by_migrating_to_v58(
- ca_choices_28
- - ca_choices_26
rule_type: IsEqualToOrdering
- inputs:
x: ca_choices_27
y: 4
rule_type: HasElementXAtPositionY
- inputs:
x:
- - ca_choices_29
- ca_choices_27
- ca_choices_28
- ca_choices_26
rule_type: IsEqualToOrdering
tagged_skill_misconception_id: null
training_data: []
confirmed_unclassified_answers: []
Expand Down Expand Up @@ -11483,6 +11476,17 @@ def test_fixing_invalid_drag_and_drop_exp_data_by_migrating_to_v58(
- - ca_choices_28
- - ca_choices_29
rule_type: IsEqualToOrderingWithOneItemAtIncorrectPosition
- inputs:
x: ca_choices_27
y: 4
rule_type: HasElementXAtPositionY
- inputs:
x:
- - ca_choices_29
- ca_choices_27
- ca_choices_28
- ca_choices_26
rule_type: IsEqualToOrdering
tagged_skill_misconception_id: null
training_data: []
confirmed_unclassified_answers: []
Expand Down
8 changes: 1 addition & 7 deletions core/domain/state_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -1778,13 +1778,7 @@ def _validate_drag_and_drop_input(self, strict: bool = False) -> None:
ele_element = ele['element']

if ele_position > len(rule_spec.inputs['x']):
raise utils.ValidationError(
f'Rule - {rule_spec_index} of '
f'answer group {ans_group_index} '
f'does not have the enough position '
f'to match for the '
f'HasElementXAtPositionY rule above.'
)
continue

rule_choice = rule_spec.inputs['x'][
ele_position - 1]
Expand Down

0 comments on commit cc1376a

Please sign in to comment.