Commits

Thomas Wanschik  committed 5abb2ef

adapted tests and backends to use the new SearchManager

  • Participants
  • Parent commits 80f60ea

Comments (0)

Files changed (3)

File search/backends/gae_background_tasks.py

 
 default_search_queue = getattr(settings, 'DEFAULT_SEARCH_QUEUE', 'default')
 
-def update_relation_index(search_index_field, parent_pk, delete):
+def update_relation_index(search_manager, parent_pk, delete):
     # pass only the field / model names to the background task to transfer less
     # data
-    app_label = search_index_field.model_class._meta.app_label
-    object_name = search_index_field.model_class._meta.object_name
-    deferred.defer(update, app_label, object_name, search_index_field.name,
+    app_label = search_manager.model_class._meta.app_label
+    object_name = search_manager.model_class._meta.object_name
+    deferred.defer(update, app_label, object_name, search_manager.name,
         parent_pk, delete, _queue=default_search_queue)
 
 def update(app_label, object_name, field_name, parent_pk, delete):

File search/backends/immediate_update.py

-def update_relation_index(search_index_field, parent_pk, delete):
-    search_index_field.update_relation_index(parent_pk, delete)
+def update_relation_index(search_manager, parent_pk, delete):
+    search_manager.update_relation_index(parent_pk, delete)

File search/tests.py

-## -*- coding: utf-8 -*-
-#from django.db import models
-#from django.test import TestCase
-#
-## use immediate_update on tests
-#from django.conf import settings
-#settings.BACKEND = 'search.backends.immediate_update'
-#
-#from search.core import SearchIndexField, startswith
-#
-#class Indexed(models.Model):
-#    # Test normal and prefix index
-#    one = models.CharField(max_length=500, null=True)
-#    one_index = SearchIndexField('one', indexer=startswith)
-#    two = models.CharField(max_length=500)
-#    one_two_index = SearchIndexField(('one', 'two'))
-#    check = models.BooleanField()
-#
-#    # Test relation index
-#    value = models.CharField(max_length=500)
-#    value_index = SearchIndexField('value', integrate=('one', 'check'))
-#
-##Test filters
-#class FiltersIndexed(models.Model):
-#    value = models.CharField(max_length=500)
-#    check = models.BooleanField()
-#    checked_index = SearchIndexField(('value', ), filters={'check':True, })
-#
-#class TestIndexed(TestCase):
-#    def setUp(self):
-#        for i in range(3):
-#            Indexed(one=u'OneOne%d' % i).save()
-#
-#        for i in range(3):
-#            Indexed(one=u'one%d' % i, two='two%d' % i).save()
-#
-#        for i in range(3):
-#            Indexed(one=(None, u'ÜÄÖ-+!#><|', 'blub')[i],
-#                    check=bool(i%2), value=u'value%d test-word' % i).save()
-#
-#        for i in range(3):
-#            FiltersIndexed(check=bool(i%2), value=u'value%d test-word' % i).save()
-#
-#    def test_setup(self):
-#        self.assertEqual(len(Indexed.one_index.search('oneo')), 3)
-#        self.assertEqual(len(Indexed.one_index.search('one')), 6)
-#
-#        self.assertEqual(len(Indexed.one_two_index.search('one2')), 1)
-#        self.assertEqual(len(Indexed.one_two_index.search('two')), 0)
-#        self.assertEqual(len(Indexed.one_two_index.search('two1')), 1)
-#
-#        # test against empty list because a relation index is used
-#        self.assertEqual(Indexed.value_index.search('word').get().value_index, [])
-#
-#        self.assertEqual(len(Indexed.value_index.search('word')), 3)
-#        self.assertEqual(len(Indexed.value_index.search('test-word')), 3)
-#
-#        self.assertEqual(len(Indexed.value_index.search('value0').filter(
-#            check=False)), 1)
-#        self.assertEqual(len(Indexed.value_index.search('value1').filter(
-#            check=True, one=u'ÜÄÖ-+!#><|')), 1)
-#        self.assertEqual(len(Indexed.value_index.search('value2').filter(
-#            check__exact=False, one='blub')), 1)
-#
-#        # test filters
-#        self.assertEqual(len(FiltersIndexed.checked_index.search('test-word')), 1)
-#
-#    def test_change(self):
-#        one = Indexed.one_index.search('oNeone1').get()
-#        one.one = 'oneoneone'
-#        one.save()
-#        # The index ListField must be empty on the main entity and filled
-#        # on the relation index, only
-#        self.assertEqual(len(Indexed.one_index.search('oNeoneo').get().one_index), 0)
-#        # TODO: Add _relation_index_model to the manager
-##        self.assertEqual(
-##            len(Indexed.one_index._relation_index_model.one_index.search('oNeoneo').get().one_index), 9)
-#
-#        value = Indexed.value_index.search('value0').get()
-#        value.value = 'value1 test-word'
-#        value.save()
-#        value.one = 'shidori'
-#        value.value = 'value3 rasengan/shidori'
-#        value.save()
-#        self.assertEqual(len(Indexed.value_index.search('rasengan')), 1)
-#        self.assertEqual(len(Indexed.value_index.search('value3')), 1)
-#
-#        value = Indexed.value_index.search('value3').get()
-#        value.delete()
-#        self.assertEqual(len(Indexed.value_index.search('value3')), 0)
-
 # -*- coding: utf-8 -*-
 from django.db import models
 from django.test import TestCase