Repository: oppia/oppia

Issue:
Refactoring and clean up backend tests.
Currently, there are functions like [add_hint](https://github.com/oppia/oppia/blob/develop/core/domain/state_domain.py#L1400) and [delete_hint](https://github.com/oppia/oppia/blob/develop/core/domain/state_domain.py#L1408) which we only use during testing, through this issue we want to cover the following:

- Remove those functions (Clean-up).
- Refactor the test files to use "commands" to update the state dict. 
Refactoring and clean up backend tests.
Currently, there are functions like [add_hint](https://github.com/oppia/oppia/blob/develop/core/domain/state_domain.py#L1400) and [delete_hint](https://github.com/oppia/oppia/blob/develop/core/domain/state_domain.py#L1408) which we only use during testing, through this issue we want to cover the following:

- Remove those functions (Clean-up).
- Refactor the test files to use "commands" to update the state dict. 


Discussion:
@DubeySandeep Can you please explain the second point? I didn't understand.
@rakshitkumarcse are you working on it? Else I would like to take it.
@lladhibhutall go ahead. Take it up.
Thanks.
@lladhibhutall , are you working on this issue ?

@anubhavsinha98 I will get started with it soon.
@DubeySandeep Is this issue still open? If yes I would like to work on it. Thanks!
@lladhibhutall Are you still working on the issue?
@YashJipkate If he isn't, feel free to take up the issue.
@rakshitkumarcse I'll wait for a day or two for his response and then I'll take up the issue in case of lack of response.
Thanks!
@DubeySandeep Can you please explain the second point? I didn't understand.
@rakshitkumarcse are you working on it? Else I would like to take it.
@lladhibhutall go ahead. Take it up.
Thanks.
@lladhibhutall , are you working on this issue ?

@anubhavsinha98 I will get started with it soon.
@DubeySandeep Is this issue still open? If yes I would like to work on it. Thanks!
@lladhibhutall Are you still working on the issue?
@YashJipkate If he isn't, feel free to take up the issue.
@rakshitkumarcse I'll wait for a day or two for his response and then I'll take up the issue in case of lack of response.
Thanks!

Resolving patch:
diff --git a/core/domain/state_domain.py b/core/domain/state_domain.py
--- a/core/domain/state_domain.py
+++ b/core/domain/state_domain.py
@@ -1300,29 +1300,6 @@ def update_content_ids_to_audio_translations(
                 content_ids_to_audio_translations_dict.iteritems())
         }
 
-    def add_hint(self, hint_content):
-        """Add a new hint to the list of hints.
-
-        Args:
-            hint_content: str. The hint text.
-        """
-        self.interaction.hints.append(Hint(hint_content))
-
-    def delete_hint(self, index):
-        """Delete a hint from the list of hints.
-
-        Args:
-            index: int. The position of the hint in the list of hints.
-
-        Raises:
-            IndexError: Index is less than 0.
-            IndexError: Index is greater than or equal than the length of hints
-                list.
-        """
-        if index < 0 or index >= len(self.interaction.hints):
-            raise IndexError('Hint index out of range')
-        del self.interaction.hints[index]
-
     def to_dict(self):
         """Returns a dict representing this State domain object.
 


Test patch:
diff --git a/core/domain/exp_domain_test.py b/core/domain/exp_domain_test.py
--- a/core/domain/exp_domain_test.py
+++ b/core/domain/exp_domain_test.py
@@ -590,13 +590,29 @@ def test_content_ids_to_audio_translations_validation(self):
         init_state.update_interaction_id('TextInput')
         exploration.validate()
 
-        init_state.add_hint(state_domain.SubtitledHtml('hint_1', {}))
+        hints_list = []
+        hints_list.append({
+            'hint_content': {
+                'content_id': 'hint_1',
+                'html': {}
+            }
+        })
+        init_state.update_interaction_hints(hints_list)
+
         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\'\]')
-        init_state.add_hint(state_domain.SubtitledHtml('hint_1', {}))
+
+        hints_list.append({
+            'hint_content': {
+                'content_id': 'hint_1',
+                'html': {}
+            }
+        })
+        init_state.update_interaction_hints(hints_list)
+
         self._assert_validation_error(
             exploration, 'Found a duplicate content id hint_1')
 
diff --git a/core/domain/state_domain_test.py b/core/domain/state_domain_test.py
--- a/core/domain/state_domain_test.py
+++ b/core/domain/state_domain_test.py
@@ -429,12 +429,14 @@ def test_hints_validation(self):
         init_state.update_interaction_id('TextInput')
         exploration.validate()
 
-        init_state.update_interaction_hints([{
+        hints_list = []
+        hints_list.append({
             'hint_content': {
                 'content_id': 'hint_1',
                 'html': 'hint one'
             },
-        }])
+        })
+        init_state.update_interaction_hints(hints_list)
 
         solution = {
             'answer_is_exclusive': False,
@@ -457,14 +459,29 @@ def test_hints_validation(self):
                 init_state.interaction.id, solution))
         exploration.validate()
 
-        # Add hint and delete hint.
-        init_state.add_hint(state_domain.SubtitledHtml('hint_2', 'new hint'))
+        hints_list.append({
+            'hint_content': {
+                'content_id': 'hint_2',
+                'html': 'new hint'
+            }
+        })
+        init_state.update_interaction_hints(hints_list)
+
         self.assertEqual(
             init_state.interaction.hints[1].hint_content.html,
             'new hint')
-        init_state.add_hint(
-            state_domain.SubtitledHtml('hint_3', 'hint three'))
-        init_state.delete_hint(1)
+
+        hints_list.append({
+            'hint_content': {
+                'content_id': 'hint_3',
+                'html': 'hint three'
+            }
+        })
+        init_state.update_interaction_hints(hints_list)
+
+        del hints_list[1]
+        init_state.update_interaction_hints(hints_list)
+
         init_state.update_content_ids_to_audio_translations({
             'content': {},
             'default_outcome': {},
@@ -486,7 +503,14 @@ def test_solution_validation(self):
         # Solution should be set to None as default.
         self.assertEqual(init_state.interaction.solution, None)
 
-        init_state.add_hint(state_domain.SubtitledHtml('hint_1', {}))
+        hints_list = []
+        hints_list.append({
+            'hint_content': {
+                'content_id': 'hint_1',
+                'html': {}
+            },
+        })
+        init_state.update_interaction_hints(hints_list)
         solution = {
             'answer_is_exclusive': False,
             'correct_answer': [0, 0],