Skip to content

Commit

Permalink
Fix tests for removal of HTMLFile logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ericholscher committed Feb 6, 2019
1 parent b95c1fe commit c16747c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 16 deletions.
4 changes: 3 additions & 1 deletion readthedocs/search/tests/conftest.py
Expand Up @@ -7,6 +7,7 @@
from django_dynamic_fixture import G

from readthedocs.projects.models import Project, HTMLFile
from readthedocs.search.documents import PageDocument
from .dummy_data import ALL_PROJECTS, PROJECT_DATA_FILES


Expand All @@ -30,7 +31,8 @@ def all_projects(es_index, mock_processed_json, db, settings):
# file_basename in config are without extension so add html extension
file_name = file_basename + '.html'
version = project.versions.all()[0]
G(HTMLFile, project=project, version=version, name=file_name)
html_file = G(HTMLFile, project=project, version=version, name=file_name)
PageDocument().update(html_file)

projects_list.append(project)

Expand Down
3 changes: 3 additions & 0 deletions readthedocs/search/tests/test_api.py
Expand Up @@ -6,6 +6,7 @@
from readthedocs.builds.models import Version
from readthedocs.projects.models import HTMLFile
from readthedocs.search.tests.utils import get_search_query_from_project_file
from readthedocs.search.documents import PageDocument


@pytest.mark.django_db
Expand Down Expand Up @@ -67,6 +68,7 @@ def test_doc_search_filter_by_version(self, api_client, project):
# Make primary key to None, so django will create new object
f.pk = None
f.save()
PageDocument().update(f)

search_params = {'q': query, 'project': project.slug, 'version': dummy_version.slug}
resp = api_client.get(self.url, search_params)
Expand All @@ -88,6 +90,7 @@ def test_doc_search_pagination(self, api_client, project):
# Make primary key to None, so django will create new object
html_file.pk = None
html_file.save()
PageDocument().update(html_file)

search_params = {'q': query, 'project': project.slug, 'version': latest_version.slug}
resp = api_client.get(self.url, search_params)
Expand Down
15 changes: 0 additions & 15 deletions readthedocs/search/tests/test_views.py
Expand Up @@ -130,21 +130,6 @@ def test_file_search_exact_match(self, client, project):

assert len(result) == 1

def test_page_search_not_return_removed_page(self, client, project):
"""Check removed page are not in the search index."""
query = get_search_query_from_project_file(project_slug=project.slug)
# Make a query to check it returns result
result, _ = self._get_search_result(url=self.url, client=client,
search_params={'q': query, 'type': 'file'})
assert len(result) == 1

# Delete all the HTML files of the project
HTMLFile.objects.filter(project=project).delete()
# Run the query again and this time there should not be any result
result, _ = self._get_search_result(url=self.url, client=client,
search_params={'q': query, 'type': 'file'})
assert len(result) == 0

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

0 comments on commit c16747c

Please sign in to comment.