@@ -38,9 +38,9 @@ def test_search_by_project_name(self, client, project, all_projects):
38
38
)
39
39
40
40
assert len (results ) == 1
41
- assert project .name . encode ( 'utf-8' ) in results [0 ]. name . encode ( 'utf-8' )
41
+ assert project .name == results [0 ][ ' name' ]
42
42
for proj in all_projects [1 :]:
43
- assert proj .name . encode ( 'utf-8' ) not in results [0 ]. name . encode ( 'utf-8' )
43
+ assert proj .name != results [0 ][ ' name' ]
44
44
45
45
def test_search_project_have_correct_language_facets (self , client , project ):
46
46
"""Test that searching project should have correct language facets in the results"""
@@ -102,23 +102,22 @@ def _get_search_result(self, url, client, search_params):
102
102
103
103
return results , facets
104
104
105
- def _get_highlight (self , result , data_type ):
105
+ def _get_highlight (self , result , field , type = None ):
106
106
# if query is from page title,
107
107
# highlighted title is present in 'result.meta.highlight.title'
108
- if data_type == 'title' :
109
- highlight = result . meta . highlight . title
108
+ if not type and field == 'title' :
109
+ highlight = result [ ' highlight' ][ ' title' ]
110
110
111
111
# if result is not from page title,
112
- # then results and highlighted results are present inside 'inner_hits '
112
+ # then results and highlighted results are present inside 'blocks '
113
113
else :
114
- inner_hits = result . meta . inner_hits
115
- assert len (inner_hits ) >= 1
114
+ blocks = result [ 'blocks' ]
115
+ assert len (blocks ) >= 1
116
116
117
117
# checking first inner_hit
118
- inner_hit_0 = inner_hits [0 ]
119
- expected_type = data_type .split ('.' )[0 ] # can be either 'sections' or 'domains'
120
- assert inner_hit_0 ['type' ] == expected_type
121
- highlight = inner_hit_0 ['highlight' ][data_type ]
118
+ inner_hit_0 = blocks [0 ]
119
+ assert inner_hit_0 ['type' ] == type
120
+ highlight = inner_hit_0 ['highlight' ][field ]
122
121
123
122
return highlight
124
123
@@ -132,10 +131,17 @@ def _get_highlighted_words(self, string):
132
131
@pytest .mark .parametrize ('data_type' , DATA_TYPES_VALUES )
133
132
@pytest .mark .parametrize ('page_num' , [0 , 1 ])
134
133
def test_file_search (self , client , project , data_type , page_num ):
134
+ data_type = data_type .split ('.' )
135
+ type , field = None , None
136
+ if len (data_type ) < 2 :
137
+ field = data_type [0 ]
138
+ else :
139
+ type , field = data_type
135
140
query = get_search_query_from_project_file (
136
141
project_slug = project .slug ,
137
142
page_num = page_num ,
138
- data_type = data_type
143
+ type = type ,
144
+ field = field ,
139
145
)
140
146
results , _ = self ._get_search_result (
141
147
url = self .url ,
@@ -146,7 +152,7 @@ def test_file_search(self, client, project, data_type, page_num):
146
152
147
153
# checking first result
148
154
result_0 = results [0 ]
149
- highlight = self ._get_highlight (result_0 , data_type )
155
+ highlight = self ._get_highlight (result_0 , field , type )
150
156
assert len (highlight ) == 1
151
157
152
158
highlighted_words = self ._get_highlighted_words (highlight [0 ])
@@ -204,11 +210,11 @@ def test_file_search_filter_role_name(self, client):
204
210
# in `signals` page
205
211
assert len (new_results ) == 1
206
212
first_result = new_results [0 ] # first result
207
- inner_hits = first_result . meta . inner_hits # inner_hits of first results
208
- assert len (inner_hits ) >= 1
209
- inner_hit_0 = inner_hits [0 ] # first inner_hit
210
- assert inner_hit_0 . type == 'domains '
211
- assert inner_hit_0 . source . role_name == confval_facet
213
+ blocks = first_result [ 'blocks' ] # blocks of first results
214
+ assert len (blocks ) >= 1
215
+ inner_hit_0 = blocks [0 ] # first inner_hit
216
+ assert inner_hit_0 [ ' type' ] == 'domain '
217
+ assert inner_hit_0 [ 'role' ] == confval_facet
212
218
213
219
for facet in new_role_names_facets :
214
220
if facet [0 ] == confval_facet :
@@ -224,9 +230,16 @@ def test_file_search_case_insensitive(self, client, project, case, data_type):
224
230
225
231
It tests with uppercase, lowercase and camelcase.
226
232
"""
233
+ type , field = None , None
234
+ data_type = data_type .split ('.' )
235
+ if len (data_type ) < 2 :
236
+ field = data_type [0 ]
237
+ else :
238
+ type , field = data_type
227
239
query_text = get_search_query_from_project_file (
228
240
project_slug = project .slug ,
229
- data_type = data_type
241
+ type = type ,
242
+ field = field ,
230
243
)
231
244
cased_query = getattr (query_text , case )
232
245
query = cased_query ()
@@ -239,7 +252,7 @@ def test_file_search_case_insensitive(self, client, project, case, data_type):
239
252
assert len (results ) >= 1
240
253
241
254
first_result = results [0 ]
242
- highlight = self ._get_highlight (first_result , data_type )
255
+ highlight = self ._get_highlight (first_result , field , type )
243
256
assert len (highlight ) == 1
244
257
highlighted_words = self ._get_highlighted_words (highlight [0 ])
245
258
assert len (highlighted_words ) >= 1
@@ -267,13 +280,13 @@ def test_file_search_exact_match(self, client, project):
267
280
# because the phrase is present in
268
281
# only one project
269
282
assert len (results ) == 1
270
- assert results [0 ]. project == 'kuma'
271
- assert results [0 ]. path == 'testdocumentation '
283
+ assert results [0 ][ ' project' ] == 'kuma'
284
+ assert results [0 ][ 'link' ] == 'http://readthedocs.org/docs/kuma/en/latest/documentation.html '
272
285
273
- inner_hits = results [0 ]. meta . inner_hits
274
- assert len (inner_hits ) == 1
275
- assert inner_hits [0 ]. type == 'sections '
276
- highlight = self ._get_highlight (results [0 ], 'sections. content' )
286
+ blocks = results [0 ][ 'blocks' ]
287
+ assert len (blocks ) == 1
288
+ assert blocks [0 ][ ' type' ] == 'section '
289
+ highlight = self ._get_highlight (results [0 ], 'content' , 'section ' )
277
290
assert len (highlight ) == 1
278
291
highlighted_words = self ._get_highlighted_words (highlight [0 ])
279
292
assert len (highlighted_words ) >= 1
@@ -316,12 +329,12 @@ def test_file_search_filter_by_project(self, client):
316
329
search_params = search_params ,
317
330
)
318
331
project_facets = facets ['project' ]
319
- resulted_project_facets = [ facet [0 ] for facet in project_facets ]
332
+ resulted_project_facets = [facet [0 ] for facet in project_facets ]
320
333
321
334
# There should be 1 search result as we have filtered
322
335
assert len (results ) == 1
323
336
# kuma should should be there only
324
- assert 'kuma' == results [0 ]. project
337
+ assert 'kuma' == results [0 ][ ' project' ]
325
338
326
339
# But there should be 2 projects in the project facets
327
340
# as the query is present in both projects
0 commit comments