Anonymous avatar Anonymous committed 32328a5

added test for filters

Comments (0)

Files changed (2)

+syntax: glob
+.project
+.pydevproject
+.settings
+*~
+*.orig
+*.pyc
+*.pyo
+*.swp
+*.tmp
+_generated_media
+.dynamic_media
+desktop.ini
+settings_overrides.py
+nbproject
+django
 
 from search.core import SearchIndexField, startswith
 
-# TODO: add filters test to test if values only get indexed if the filter matches
 class Indexed(models.Model):
     # Test normal and prefix index
     one = models.CharField(max_length=500, null=True)
     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=(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.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'
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.