1
- import random
2
- import string
3
-
4
1
import pytest
5
- from django .core .management import call_command
6
2
from django .core .urlresolvers import reverse
7
3
from django_dynamic_fixture import G
8
- from django_elasticsearch_dsl import Index
9
4
from pyquery import PyQuery as pq
10
- from pytest_mock import mock
11
5
12
6
from readthedocs .builds .constants import LATEST
13
7
from readthedocs .builds .models import Version
14
- from readthedocs .projects .models import Project
8
+ from readthedocs .projects .models import Project , HTMLFile
15
9
from readthedocs .search .tests .utils import get_search_query_from_project_file
16
10
17
11
@@ -75,7 +69,7 @@ def _get_search_result(self, url, client, search_params):
75
69
assert resp .status_code == 200
76
70
77
71
page = pq (resp .content )
78
- result = page .find ('.module-list-wrapper .module -item' )
72
+ result = page .find ('.module-list-wrapper .search-result -item' )
79
73
return result , page
80
74
81
75
@pytest .mark .parametrize ('data_type' , ['content' , 'headers' , 'title' ])
@@ -95,16 +89,26 @@ def test_file_search_case_insensitive(self, client, project, case):
95
89
96
90
It tests with uppercase, lowercase and camelcase
97
91
"""
98
- query = get_search_query_from_project_file (project_slug = project .slug )\
92
+ query_text = get_search_query_from_project_file (project_slug = project .slug )
99
93
100
- cased_query = getattr (query , case )
94
+ cased_query = getattr (query_text , case )
95
+ query = cased_query ()
101
96
102
97
result , _ = self ._get_search_result (url = self .url , client = client ,
103
- search_params = {'q' : cased_query () , 'type' : 'file' })
98
+ search_params = {'q' : query , 'type' : 'file' })
104
99
105
100
assert len (result ) == 1
106
101
# Check the actual text is in the result, not the cased one
107
- assert query in result .text ()
102
+ assert query_text in result .text ()
103
+
104
+ def test_page_search_not_return_removed_page (self , client , project ):
105
+ """Check removed page are not in the search index"""
106
+ query = get_search_query_from_project_file (project_slug = project .slug )
107
+ # Delete all the HTML files of the project
108
+ p = HTMLFile .objects .filter (project = project ).delete ()
109
+ result , _ = self ._get_search_result (url = self .url , client = client ,
110
+ search_params = {'q' : query , 'type' : 'file' })
111
+ assert len (result ) == 0
108
112
109
113
def test_file_search_show_projects (self , client , all_projects ):
110
114
"""Test that search result page shows list of projects while searching for files"""
0 commit comments