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