changeset 4977:2171281b6d79

Xapian2009: Search tests update. regex: and case: prefixes tests were added for title, linkto and category.
author Dmitrijs Milajevs <dimazest@gmail.com>
date Wed, 05 Aug 2009 21:33:38 +0200
parents 8df5d749cf2d
children 0b5aaec043cd
files MoinMoin/search/_tests/test_search.py
diffstat 1 files changed, 32 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/search/_tests/test_search.py	Tue Aug 04 20:24:07 2009 +0200
+++ b/MoinMoin/search/_tests/test_search.py	Wed Aug 05 21:33:38 2009 +0200
@@ -76,16 +76,44 @@
     """ search: test search """
     doesnotexist = u'jfhsdaASDLASKDJ'
 
-    def testTitleSearchFrontPage(self):
-        """ search: title search for FrontPage """
-        result = search.searchPages(self.request, u"title:FrontPage")
-        assert len(result.hits) == 1
+    def test_prefix_search(self):
+
+        def simple_test(prefix, term):
+            result = search.searchPages(self.request, u"%s:%s" % (prefix, term))
+            assert result.hits
+            result = search.searchPages(self.request, u"%s:%s" % (prefix, self.doesnotexist))
+            assert not result.hits
+
+        def re_test(prefix, term):
+            result = search.searchPages(self.request, ur"%s:re:\b%s\b" % (prefix, term))
+            assert result.hits
+            result = search.searchPages(self.request, ur"%s:re:\b%s\b" % (prefix, self.doesnotexist))
+            assert not result.hits
+
+        def case_test(prefix, term):
+            result = search.searchPages(self.request, u"%s:case:%s" % (prefix, term))
+            assert result.hits
+            result = search.searchPages(self.request, u"%s:case:%s" % (prefix, term.lower()))
+            assert not result.hits
+
+        def case_re_test(prefix, term):
+            result = search.searchPages(self.request, ur"%s:case:re:\%s\b" % (prefix, term))
+            assert result.hits
+            result = search.searchPages(self.request, ur"%s:case:re:\%s\b" % (prefix, term.lower()))
+            assert not result.hits
+
+        for prefix, term in [('title', 'FrontPage'), ('linkto', 'FrontPage'), ('category', 'CategoryHomepage')]:
+            for test in [simple_test, re_test, case_test, case_re_test]:
+                yield '%s %s' % (prefix, test.func_name), test, prefix, term
 
     def testTitleSearchAND(self):
         """ search: title search with AND expression """
         result = search.searchPages(self.request, u"title:Help title:Index")
         assert len(result.hits) == 1
 
+        result = search.searchPages(self.request, u"title:Help title:%s" % self.doesnotexist)
+        assert len(result.hits) == 0
+
     def testTitleSearchOR(self):
         """ search: title search with OR expression """
         result = search.searchPages(self.request, u"title:FrontPage or title:RecentChanges")