search: add a num queries test on index_site (#40252)

This commit is contained in:
Lauréline Guérin 2020-03-27 15:50:00 +01:00
parent 50b1101297
commit a83ce2c5ee
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
1 changed files with 17 additions and 0 deletions

View File

@ -7,8 +7,10 @@ import mock
from django.conf import settings
from django.contrib.auth.models import AnonymousUser, User, Group
from django.db import connection
from django.test import override_settings
from django.test.client import RequestFactory
from django.test.utils import CaptureQueriesContext
from django.core.management import call_command
from django.core.urlresolvers import reverse
@ -528,3 +530,18 @@ def test_no_sub_slug_search(app):
assert len(hits) == 1
hits = search_site(request, 'barfoo')
assert len(hits) == 0
def test_index_site_num_queries(app):
group = Group.objects.create(name='plop')
for i in range(0, 10):
page = Page.objects.create(title='page %s' % i, slug='example-page-%s' % i)
page.groups.set([group])
for j in range(0, 5):
cell = TextCell.objects.create(page=page, text='<p>foobar %s</p>' % j, order=j, public=False)
cell.groups.set([group])
index_site() # populate cache
with CaptureQueriesContext(connection) as ctx:
index_site()
assert len(ctx.captured_queries) == 591