Skip to content

Commit

Permalink
Fixes oppia#6181:Removed the exception which occured during clearing …
Browse files Browse the repository at this point in the history
…search index (oppia#6518)

* First

* First

* Second

* Third

* Fourth

* Reset

* Added test

* Fixed

* Removed GSE

* Removed models

* removed a line
  • Loading branch information
anubhavsinha98 authored and seanlip committed Mar 30, 2019
1 parent 454d734 commit c7314a1
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
4 changes: 3 additions & 1 deletion core/controllers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from core.domain import recommendations_services
from core.domain import rights_manager
from core.domain import role_services
from core.domain import search_services
from core.domain import stats_services
from core.domain import topic_domain
from core.domain import topic_services
Expand Down Expand Up @@ -155,7 +156,8 @@ def post(self):
self._generate_dummy_explorations(
num_dummy_exps_to_generate, num_dummy_exps_to_publish)
elif self.payload.get('action') == 'clear_search_index':
exp_services.clear_search_index()
search_services.clear_collection_search_index()
search_services.clear_exploration_search_index()
elif self.payload.get('action') == 'save_config_properties':
new_config_property_values = self.payload.get(
'new_config_property_values')
Expand Down
30 changes: 30 additions & 0 deletions core/controllers/admin_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
"""Tests for the admin page."""

from core.controllers import base
from core.domain import collection_services
from core.domain import exp_domain
from core.domain import exp_services
from core.domain import search_services
from core.domain import stats_domain
from core.domain import stats_services
from core.tests import test_utils
Expand Down Expand Up @@ -295,3 +297,31 @@ def test_that_handler_raises_exception(self):
self.assertEqual(
response['error'],
'Exploration \'exp\' does not have \'state name\' state.')


class ClearSearchIndexTest(test_utils.GenericTestBase):
"""Tests that search index gets cleared."""

def test_clear_search_index(self):
exp_services.load_demo('0')
result_explorations = search_services.search_explorations(
'Welcome', 2)[0]
self.assertEqual(result_explorations, ['0'])
collection_services.load_demo('0')
result_collections = search_services.search_collections('Welcome', 2)[0]
self.assertEqual(result_collections, ['0'])
self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME)
self.login(self.ADMIN_EMAIL, is_super_admin=True)
response = self.get_html_response('/admin')
csrf_token = self.get_csrf_token_from_response(response)
generated_exps_response = self.post_json(
'/adminhandler', {
'action': 'clear_search_index'
},
csrf_token=csrf_token)
self.assertEqual(generated_exps_response, {})
result_explorations = search_services.search_explorations(
'Welcome', 2)[0]
self.assertEqual(result_explorations, [])
result_collections = search_services.search_collections('Welcome', 2)[0]
self.assertEqual(result_collections, [])
16 changes: 16 additions & 0 deletions core/domain/search_services_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,19 @@ def mock_get_rights(unused_exp_id):
search_services.update_exploration_status_in_search(self.EXP_ID)

self.assertEqual(delete_docs_counter.times_called, 1)

def test_clear_exploration_search_index(self):
exp_services.load_demo('0')
result = search_services.search_explorations('Welcome', 2)[0]
self.assertEqual(result, ['0'])
search_services.clear_exploration_search_index()
result = search_services.search_explorations('Welcome', 2)[0]
self.assertEqual(result, [])

def test_clear_collection_search_index(self):
collection_services.load_demo('0')
result = search_services.search_collections('Welcome', 2)[0]
self.assertEqual(result, ['0'])
search_services.clear_collection_search_index()
result = search_services.search_collections('Welcome', 2)[0]
self.assertEqual(result, [])

0 comments on commit c7314a1

Please sign in to comment.