Don't localize search indexes for teams
TNL-3239
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
from django.conf import settings
|
||||
from django.db.models.signals import post_save
|
||||
from django.dispatch import receiver
|
||||
from django.utils import translation
|
||||
|
||||
from search.search_engine_base import SearchEngine
|
||||
|
||||
@@ -45,12 +46,14 @@ class CourseTeamIndexer(object):
|
||||
"""
|
||||
Generate the text field used for general search.
|
||||
"""
|
||||
return "{name}\n{description}\n{country}\n{language}".format(
|
||||
name=self.course_team.name.encode('utf-8'),
|
||||
description=self.course_team.description.encode('utf-8'),
|
||||
country=self.course_team.country.name.format(),
|
||||
language=self._language_name()
|
||||
)
|
||||
# Always use the English version of any localizable strings (see TNL-3239)
|
||||
with translation.override('en'):
|
||||
return "{name}\n{description}\n{country}\n{language}".format(
|
||||
name=self.course_team.name.encode('utf-8'),
|
||||
description=self.course_team.description.encode('utf-8'),
|
||||
country=self.course_team.country.name.format(),
|
||||
language=self._language_name()
|
||||
)
|
||||
|
||||
def _language_name(self):
|
||||
"""
|
||||
|
||||
@@ -9,6 +9,7 @@ import ddt
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.conf import settings
|
||||
from django.db.models.signals import post_save
|
||||
from django.utils import translation
|
||||
from nose.plugins.attrib import attr
|
||||
from rest_framework.test import APITestCase, APIClient
|
||||
|
||||
@@ -519,12 +520,13 @@ class TestListTeamsAPI(EventTestMixin, TeamAPITestCase):
|
||||
)
|
||||
@ddt.unpack
|
||||
def test_text_search(self, text_search, expected_team_names):
|
||||
# clear out the teams search index before reindexing
|
||||
CourseTeamIndexer.engine().destroy()
|
||||
|
||||
for team in self.test_team_name_id_map.values():
|
||||
CourseTeamIndexer.index(team)
|
||||
def reset_search_index():
|
||||
"""Clear out the search index and reindex the teams."""
|
||||
CourseTeamIndexer.engine().destroy()
|
||||
for team in self.test_team_name_id_map.values():
|
||||
CourseTeamIndexer.index(team)
|
||||
|
||||
reset_search_index()
|
||||
self.verify_names(
|
||||
{'course_id': self.test_course_2.id, 'text_search': text_search},
|
||||
200,
|
||||
@@ -540,6 +542,16 @@ class TestListTeamsAPI(EventTestMixin, TeamAPITestCase):
|
||||
number_of_results=len(expected_team_names)
|
||||
)
|
||||
|
||||
# Verify that the searches still work for a user from a different locale
|
||||
with translation.override('ar'):
|
||||
reset_search_index()
|
||||
self.verify_names(
|
||||
{'course_id': self.test_course_2.id, 'text_search': text_search},
|
||||
200,
|
||||
expected_team_names,
|
||||
user='student_enrolled_public_profile'
|
||||
)
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class TestCreateTeamAPI(EventTestMixin, TeamAPITestCase):
|
||||
|
||||
Reference in New Issue
Block a user