Projet

Général

Profil

0001-search-fix-view-when-indexed-cell-has-no-page-51251.patch

Lauréline Guérin, 18 février 2021 14:15

Télécharger (2,43 ko)

Voir les différences:

Subject: [PATCH] search: fix view when indexed cell has no page (#51251)

 combo/apps/search/utils.py |  2 +-
 tests/test_search.py       | 10 +++++++++-
 2 files changed, 10 insertions(+), 2 deletions(-)
combo/apps/search/utils.py
143 143
                'text': hit.title,
144 144
                'rank': getattr(hit, 'rank', None),
145 145
                'url': hit.url,
146
                'description': hit.page.description if with_description is True else '',
146
                'description': hit.page.description if (hit.page and with_description is True) else '',
147 147
            }
148 148
        )
149 149
        seen[hit.url] = True
tests/test_search.py
5 5

  
6 6
from django.conf import settings
7 7
from django.contrib.auth.models import AnonymousUser, User, Group
8
from django.contrib.contenttypes.models import ContentType
8 9
from django.db import connection
9 10
from django.test import override_settings
10 11
from django.test.client import RequestFactory
......
401 402
    result = result.replace('\n', '')
402 403
    assert '<li><a href="/second-page/">second page</a></li>' in result
403 404

  
405
    # indexed cell without page
406
    cell_type = ContentType.objects.get_for_model(cell)
407
    IndexedCell.objects.create(
408
        title='other', cell_type=cell_type, cell_pk=cell.pk, public_access=True, url='fake'
409
    )
410
    # enable description
404 411
    cell._search_services['options'] = {'_text': {'with_description': True}}
405 412
    cell.save()
406 413
    resp = app.get('/ajax/search/%s/_text/?q=other' % cell.id, status=200)
407
    assert resp.text.count('<li') == 1
414
    assert resp.text.count('<li') == 2
408 415
    result = resp.text
409 416
    result = result.replace('  ', '')
410 417
    result = result.replace('\n', '')
418
    assert '<li><a href="fake">other</a></li>' in result
411 419
    assert '<li><a href="/second-page/">second page</a><div>Foo Bar Description</div></li>' in result
412 420

  
413 421
    resp = app.get('/ajax/search/%s/_text/?q=baz' % cell.id, status=200)
414
-