kopia lustrzana https://github.com/wagtail/wagtail
Changes include: * fixing the FieldError exception that can occur as described in #3134 * add tests for the "search_garbage_collect" commandpull/3169/head
rodzic
a5b544631b
commit
51b4f0f53d
|
@ -26,6 +26,7 @@ Changelog
|
|||
* Fix: Form builder email notifications now output multiple values correctly (Sævar Öfjörð Magnússon)
|
||||
* Fix: Closing 'more' dropdown on explorer no longer jumps to the top of the page (Ducky)
|
||||
* Fix: Users with only publish permission are no longer given implicit permission to delete pages (Matt Westcott)
|
||||
* Fix: `search_garbage_collect` management command now works when wagtailsearchpromotions is not installed (Morgan Aubert)
|
||||
|
||||
|
||||
1.7 (20.10.2016)
|
||||
|
|
|
@ -185,6 +185,7 @@ Contributors
|
|||
* Benoît Vogel
|
||||
* Manuel E. Gutierrez
|
||||
* Albert O'Connor
|
||||
* Morgan Aubert
|
||||
|
||||
Translators
|
||||
===========
|
||||
|
|
|
@ -57,6 +57,7 @@ Bug fixes
|
|||
* Form builder email notifications now output multiple values correctly (Sævar Öfjörð Magnússon)
|
||||
* Closing 'more' dropdown on explorer no longer jumps to the top of the page (Ducky)
|
||||
* Users with only publish permission are no longer given implicit permission to delete pages (Matt Westcott)
|
||||
* ``search_garbage_collect`` management command now works when wagtailsearchpromotions is not installed (Morgan Aubert)
|
||||
|
||||
Upgrade considerations
|
||||
======================
|
||||
|
|
|
@ -41,7 +41,9 @@ class Query(models.Model):
|
|||
"""
|
||||
Deletes all Query records that have no daily hits or editors picks
|
||||
"""
|
||||
cls.objects.filter(daily_hits__isnull=True, editors_picks__isnull=True).delete()
|
||||
extra_filter_kwargs = {'editors_picks__isnull': True, } if hasattr(cls, 'editors_picks') \
|
||||
else {}
|
||||
cls.objects.filter(daily_hits__isnull=True, **extra_filter_kwargs).delete()
|
||||
|
||||
@classmethod
|
||||
def get(cls, query_string):
|
||||
|
|
|
@ -1,10 +1,15 @@
|
|||
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
import datetime
|
||||
|
||||
from django.conf import settings
|
||||
from django.core import management
|
||||
from django.test import TestCase
|
||||
from django.test.utils import override_settings
|
||||
from django.utils.six import StringIO
|
||||
|
||||
from wagtail.contrib.wagtailsearchpromotions.models import SearchPromotion
|
||||
from wagtail.tests.utils import WagtailTestUtils
|
||||
from wagtail.wagtailsearch import models
|
||||
from wagtail.wagtailsearch.utils import normalise_query_string
|
||||
|
@ -110,9 +115,46 @@ class TestQueryPopularity(TestCase):
|
|||
|
||||
class TestGarbageCollectCommand(TestCase):
|
||||
def test_garbage_collect_command(self):
|
||||
nowdt = datetime.datetime.now()
|
||||
old_hit_date = (nowdt - datetime.timedelta(days=14)).date()
|
||||
recent_hit_date = (nowdt - datetime.timedelta(days=1)).date()
|
||||
|
||||
# Add 10 hits that are more than one week old ; the related queries and the daily hits
|
||||
# should be deleted bu the search_garbage_collect command.
|
||||
querie_ids_to_be_deleted = []
|
||||
for i in range(10):
|
||||
q = models.Query.get("Hello {}".format(i))
|
||||
q.add_hit(date=old_hit_date)
|
||||
querie_ids_to_be_deleted.append(q.id)
|
||||
|
||||
# Add 10 hits that are less than one week old ; these ones should not be deleted.
|
||||
recent_querie_ids = []
|
||||
for i in range(10):
|
||||
q = models.Query.get("World {}".format(i))
|
||||
q.add_hit(date=recent_hit_date)
|
||||
recent_querie_ids.append(q.id)
|
||||
|
||||
# Add 10 queries that are promoted. These ones should not be deleted.
|
||||
promoted_querie_ids = []
|
||||
for i in range(10):
|
||||
q = models.Query.get("Foo bar {}".format(i))
|
||||
q.add_hit(date=old_hit_date)
|
||||
SearchPromotion.objects.create(query=q, page_id=1, sort_order=0, description='Test')
|
||||
promoted_querie_ids.append(q.id)
|
||||
|
||||
management.call_command('search_garbage_collect', interactive=False, stdout=StringIO())
|
||||
|
||||
# TODO: Test that this command is acctually doing its job
|
||||
self.assertFalse(models.Query.objects.filter(id__in=querie_ids_to_be_deleted).exists())
|
||||
self.assertFalse(models.QueryDailyHits.objects.filter(
|
||||
date=old_hit_date, query_id__in=querie_ids_to_be_deleted).exists())
|
||||
|
||||
self.assertEqual(models.Query.objects.filter(id__in=recent_querie_ids).count(), 10)
|
||||
self.assertEqual(models.QueryDailyHits.objects.filter(
|
||||
date=recent_hit_date, query_id__in=recent_querie_ids).count(), 10)
|
||||
|
||||
self.assertEqual(models.Query.objects.filter(id__in=promoted_querie_ids).count(), 10)
|
||||
self.assertEqual(models.QueryDailyHits.objects.filter(
|
||||
date=recent_hit_date, query_id__in=promoted_querie_ids).count(), 0)
|
||||
|
||||
|
||||
class TestQueryChooserView(TestCase, WagtailTestUtils):
|
||||
|
|
Ładowanie…
Reference in New Issue