incubator-bloodhound-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From and...@apache.org
Subject svn commit: r1446127 - in /incubator/bloodhound/trunk/bloodhound_search/bhsearch/tests: api.py base.py index_with_whoosh.py web_ui.py whoosh_backend.py
Date Thu, 14 Feb 2013 11:37:51 GMT
Author: andrej
Date: Thu Feb 14 11:37:51 2013
New Revision: 1446127

URL: http://svn.apache.org/r1446127
Log:
fix unit tests after adding SortInstruction, prepare unit-test for #389 wiki syntax stripping

Modified:
    incubator/bloodhound/trunk/bloodhound_search/bhsearch/tests/api.py
    incubator/bloodhound/trunk/bloodhound_search/bhsearch/tests/base.py
    incubator/bloodhound/trunk/bloodhound_search/bhsearch/tests/index_with_whoosh.py
    incubator/bloodhound/trunk/bloodhound_search/bhsearch/tests/web_ui.py
    incubator/bloodhound/trunk/bloodhound_search/bhsearch/tests/whoosh_backend.py

Modified: incubator/bloodhound/trunk/bloodhound_search/bhsearch/tests/api.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/trunk/bloodhound_search/bhsearch/tests/api.py?rev=1446127&r1=1446126&r2=1446127&view=diff
==============================================================================
--- incubator/bloodhound/trunk/bloodhound_search/bhsearch/tests/api.py (original)
+++ incubator/bloodhound/trunk/bloodhound_search/bhsearch/tests/api.py Thu Feb 14 11:37:51
2013
@@ -20,7 +20,7 @@
 import unittest
 import tempfile
 import shutil
-from bhsearch.api import BloodhoundSearchApi, ASC
+from bhsearch.api import BloodhoundSearchApi, ASC, SortInstruction
 from bhsearch.query_parser import DefaultQueryParser
 from bhsearch.tests.base import BaseBloodhoundSearchTest
 from bhsearch.search_resources.ticket_search import TicketSearchParticipant
@@ -110,7 +110,7 @@ class ApiQueryWithWhooshTestCase(BaseBlo
         results = self.search_api.query(
             "*",
             filter= ['status:"closed"', 'component:"c1"'],
-            sort= [("id", ASC)]
+            sort= [SortInstruction("id", ASC)]
         )
         self.print_result(results)
         #assert

Modified: incubator/bloodhound/trunk/bloodhound_search/bhsearch/tests/base.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/trunk/bloodhound_search/bhsearch/tests/base.py?rev=1446127&r1=1446126&r2=1446127&view=diff
==============================================================================
--- incubator/bloodhound/trunk/bloodhound_search/bhsearch/tests/base.py (original)
+++ incubator/bloodhound/trunk/bloodhound_search/bhsearch/tests/base.py Thu Feb 14 11:37:51
2013
@@ -28,17 +28,28 @@ from pprint import pprint
 
 from bhsearch.web_ui import BloodhoundSearchModule
 from trac.ticket import Ticket, Milestone
-from trac.test import EnvironmentStub
+from trac.test import EnvironmentStub, Mock, MockPerm
+from trac.web import Href, arg_list_to_args
 from trac.wiki import WikiPage
 
+BASE_PATH = "/main/"
+
 class BaseBloodhoundSearchTest(unittest.TestCase):
 
-    def setUp(self, enabled = None):
+    def setUp(self, enabled = None, create_req = False):
         if not enabled:
             enabled = ['bhsearch.*']
         self.env = EnvironmentStub(enable=enabled)
         self.env.path = tempfile.mkdtemp('bhsearch-tempenv')
         self.env.config.set('bhsearch', 'silence_on_error', "False")
+        if create_req:
+            self.req = Mock(
+                perm=MockPerm(),
+                chrome={'logo': {}},
+                href=Href("/main"),
+                base_path=BASE_PATH,
+                args=arg_list_to_args([]),
+            )
 
     def tearDown(self):
         shutil.rmtree(self.env.path)

Modified: incubator/bloodhound/trunk/bloodhound_search/bhsearch/tests/index_with_whoosh.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/trunk/bloodhound_search/bhsearch/tests/index_with_whoosh.py?rev=1446127&r1=1446126&r2=1446127&view=diff
==============================================================================
--- incubator/bloodhound/trunk/bloodhound_search/bhsearch/tests/index_with_whoosh.py (original)
+++ incubator/bloodhound/trunk/bloodhound_search/bhsearch/tests/index_with_whoosh.py Thu Feb
14 11:37:51 2013
@@ -17,6 +17,7 @@
 #  KIND, either express or implied.  See the License for the
 #  specific language governing permissions and limitations
 #  under the License.
+from contextlib import closing
 
 import unittest
 import shutil
@@ -26,7 +27,8 @@ from bhsearch.tests.base import BaseBloo
 from bhsearch.search_resources.ticket_search import TicketIndexer
 
 from bhsearch.whoosh_backend import WhooshBackend
-
+from trac.test import MockPerm
+from trac.web import Href
 
 class IndexWhooshTestCase(BaseBloodhoundSearchTest):
     def setUp(self):
@@ -114,9 +116,60 @@ class IndexWhooshTestCase(BaseBloodhound
         self.print_result(results)
         self.assertEqual(2, results.hits)
 
+class FormattingTestCase(BaseBloodhoundSearchTest):
+    def setUp(self):
+        super(FormattingTestCase, self).setUp(
+            ['trac.*', 'bhsearch.*'],
+            create_req=True,
+        )
+
+    def test_can_format_wiki_to_text(self):
+        wiki_content = """= Header #overview
+
+        '''bold''', ''italic'', '''''Wikipedia style'''''
+
+        {{{
+        code
+        }}}
+
+        [[PageOutline]]
+
+        || '''Table''' || sampe ||
+
+          - list
+          - sample
+
+        [[Image(mockup_tickets.png)]] [wiki:SomePage p1] [ticket:1 ticket one]
+        http://www.edgewall.com/,
+        [http://www.edgewall.com Edgewall Software]
+
+        [#point1]
+        """
+#        wiki_content = """
+#'''''one''''', '''''two''''', '''''three''''', '''''four'''''
+#        """
+
+        page = self.create_wiki("Dummy wiki", wiki_content)
+        from trac.mimeview.api import RenderingContext
+        context = RenderingContext(
+            page.resource,
+            href=Href('/'),
+            perm=MockPerm(),
+        )
+        context.req = None # 1.0 FIXME .req shouldn't be required by formatter
+#        result = format_to_oneliner(self.env, context, wiki_content)
+#        from trac.wiki.formatter import format_to_oneliner
+        from trac.web.chrome import  format_to_html
+        result = format_to_html(self.env, context, wiki_content)
+        print result
+#
+
 
 def suite():
-    return unittest.makeSuite(IndexWhooshTestCase, 'test')
+    test_suite = unittest.TestSuite()
+    test_suite.addTest(unittest.makeSuite(IndexWhooshTestCase, 'test'))
+    test_suite.addTest(unittest.makeSuite(FormattingTestCase, 'test'))
+    return test_suite
 
 if __name__ == '__main__':
     unittest.main()

Modified: incubator/bloodhound/trunk/bloodhound_search/bhsearch/tests/web_ui.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/trunk/bloodhound_search/bhsearch/tests/web_ui.py?rev=1446127&r1=1446126&r2=1446127&view=diff
==============================================================================
--- incubator/bloodhound/trunk/bloodhound_search/bhsearch/tests/web_ui.py (original)
+++ incubator/bloodhound/trunk/bloodhound_search/bhsearch/tests/web_ui.py Thu Feb 14 11:37:51
2013
@@ -39,7 +39,12 @@ DEFAULT_DOCS_PER_PAGE = 10
 
 class WebUiTestCaseWithWhoosh(BaseBloodhoundSearchTest):
     def setUp(self):
-        super(WebUiTestCaseWithWhoosh, self).setUp(['trac.*', 'bhsearch.*'])
+        super(WebUiTestCaseWithWhoosh, self).setUp(
+            ['trac.*', 'bhsearch.*'],
+            create_req=True,
+        )
+        self.req.redirect = self.redirect
+
         whoosh_backend = WhooshBackend(self.env)
         whoosh_backend.recreate_index()
 

Modified: incubator/bloodhound/trunk/bloodhound_search/bhsearch/tests/whoosh_backend.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/trunk/bloodhound_search/bhsearch/tests/whoosh_backend.py?rev=1446127&r1=1446126&r2=1446127&view=diff
==============================================================================
--- incubator/bloodhound/trunk/bloodhound_search/bhsearch/tests/whoosh_backend.py (original)
+++ incubator/bloodhound/trunk/bloodhound_search/bhsearch/tests/whoosh_backend.py Thu Feb
14 11:37:51 2013
@@ -22,7 +22,7 @@ from datetime import datetime
 import unittest
 import tempfile
 import shutil
-from bhsearch.api import ASC, DESC, SCORE
+from bhsearch.api import ASC, DESC, SCORE, SortInstruction
 from bhsearch.query_parser import DefaultQueryParser
 from bhsearch.tests.base import BaseBloodhoundSearchTest
 from bhsearch.whoosh_backend import (WhooshBackend,
@@ -50,7 +50,7 @@ class WhooshBackendTestCase(BaseBloodhou
         self.whoosh_backend.add_doc(dict(id="2", type="ticket"))
         result = self.whoosh_backend.query(
             query.Every(),
-            sort = [("id", ASC)],
+            sort = [SortInstruction("id", ASC)],
         )
         self.print_result(result)
         self.assertEqual(2, result.hits)
@@ -99,7 +99,7 @@ class WhooshBackendTestCase(BaseBloodhou
         self.whoosh_backend.add_doc(dict(id="1", type="ticket1"))
         result = self.whoosh_backend.query(
             query.Every(),
-            sort = [("type", ASC), ("id", ASC)],
+            sort = [SortInstruction("type", ASC), SortInstruction("id", ASC)],
             fields=("id", "type"),
         )
         self.print_result(result)
@@ -116,7 +116,7 @@ class WhooshBackendTestCase(BaseBloodhou
         self.whoosh_backend.add_doc(dict(id="1", type="ticket1"))
         result = self.whoosh_backend.query(
             query.Every(),
-            sort = [("type", ASC), ("id", DESC)],
+            sort = [SortInstruction("type", ASC), SortInstruction("id", DESC)],
             fields=("id", "type"),
         )
         self.print_result(result)
@@ -163,7 +163,10 @@ class WhooshBackendTestCase(BaseBloodhou
 
         result = self.whoosh_backend.query(
             parsed_query,
-            sort = [(SCORE, ASC), ("time", DESC)],
+            sort = [
+                SortInstruction(SCORE, ASC),
+                SortInstruction("time", DESC)
+            ],
         )
         self.print_result(result)
         self.assertEqual(3, result.hits)
@@ -181,7 +184,7 @@ class WhooshBackendTestCase(BaseBloodhou
         self.whoosh_backend.add_doc(dict(id="3", type="wiki", product="A"))
         result = self.whoosh_backend.query(
             query.Every(),
-            sort = [("type", ASC), ("id", DESC)],
+            sort = [SortInstruction("type", ASC), SortInstruction("id", DESC)],
             fields=("id", "type"),
             facets= ("type", "product")
         )
@@ -207,7 +210,7 @@ class WhooshBackendTestCase(BaseBloodhou
     def test_can_return_empty_result(self):
         result = self.whoosh_backend.query(
             query.Every(),
-            sort = [("type", ASC), ("id", DESC)],
+            sort = [SortInstruction("type", ASC), SortInstruction("id", DESC)],
             fields=("id", "type"),
             facets= ("type", "product")
         )



Mime
View raw message