Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix #2328 #2013] Refresh search index and test for case insensitive search #4277

Merged
merged 4 commits into from
Jun 21, 2018
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions readthedocs/search/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,26 +67,44 @@ def test_search_project_filter_language(self, client, project):

@pytest.mark.django_db
@pytest.mark.search
class TestElasticSearch(object):
class TestPageSearch(object):
url = reverse('search')

def _get_search_result(self, url, client, search_params):
resp = client.get(url, search_params)
assert resp.status_code == 200

page = pq(resp.content)
result = page.find('.module-list-wrapper .module-item-title')
result = page.find('.module-list-wrapper .module-item')
return result, page

@pytest.mark.parametrize('data_type', ['content', 'headers', 'title'])
@pytest.mark.parametrize('page_num', [0, 1])
def test_search_by_file_content(self, client, project, data_type, page_num):
def test_file_search(self, client, project, data_type, page_num):
query = get_search_query_from_project_file(project_slug=project.slug, page_num=page_num,
data_type=data_type)

result, _ = self._get_search_result(url=self.url, client=client,
search_params={'q': query, 'type': 'file'})
assert len(result) == 1, ("failed"+ query)
assert len(result) == 1
assert query in result.text()

@pytest.mark.parametrize('case', ['upper', 'lower', 'title'])
def test_file_search_case_insensitive(self, client, project, case):
"""Check File search is case insensitive

It tests with uppercase, lowercase and camelcase
"""
query = get_search_query_from_project_file(project_slug=project.slug)\
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stray slash at the end of this line.


cased_query = getattr(query, case)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels really magical. I think there is a better way to write this code so that it's more obvious what it is doing. Perhaps by calling the function reference that is returned here, instead of just passing it in below.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps by calling the function reference that is returned here, instead of just passing it in below.

Do you mean something like

if case == 'lower':
    query = query.lower()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or even just:

case_function = getattr(query, case)
query = case_function()

Something that shows that the return is a function & we're calling it.


result, _ = self._get_search_result(url=self.url, client=client,
search_params={'q': cased_query(), 'type': 'file'})

assert len(result) == 1
# Check the actual text is in the result, not the cased one
assert query in result.text()

def test_file_search_show_projects(self, client, all_projects):
"""Test that search result page shows list of projects while searching for files"""
Expand Down