changeset 2486:8fb3dc91df77

Merge devel.
author Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
date Sat, 21 Jul 2007 02:33:34 +0200
parents 7131fda5e82d (current diff) 0c66cfd93cd9 (diff)
children fabbb4dbd99e
files MoinMoin/_tests/test_events.py
diffstat 5 files changed, 176 insertions(+), 95 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/_tests/test_events.py	Fri Jul 20 22:56:13 2007 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,86 +0,0 @@
-# -*- coding: iso-8859-1 -*-
-"""
-    MoinMoin - tests for MoinMoin.events module
-
-    @copyright: 2007 by Karol Nowak <grywacz@gmail.com>
-    @license: GNU GPL, see COPYING for details.
-"""
-
-import py
-
-import MoinMoin.events as events
-import MoinMoin.events.notification as notification
-import MoinMoin.events.jabbernotify as jabbernotify
-from MoinMoin.Page import Page
-from MoinMoin.user import User
-
-def test_get_handlers(request):
-    """Test if there are any event handlers. There should be some internal ones"""
-
-    assert events.get_handlers(request.cfg)
-
-def test_send_event(request):
-    """Test if event handlers are called and if proper messages are returned"""
-
-    return_string = u"test_send_event"
-
-    def event_handler(event):
-        return notification.Failure("Just a test")
-
-    request.cfg.event_handlers = [event_handler]
-    event = events.Event(request)
-
-    print "A proper event handler must be called and an 1-element list of results returned"
-    results = events.send_event(event)
-    assert issubclass(results[0].__class__, events.EventResult)
-
-def test_subscribable_events(request):
-    """Test if there are any subscribable events. There should be some."""
-
-    print "There should be at least a few subscribable events!"
-    assert events.get_subscribable_events()
-
-def test_page_change_message(request):
-    page = Page(request, "FrontPage")
-
-    print "Provided with a dumb change type argument, this should raise an exception!"
-    py.test.raises(notification.UnknownChangeType, notification.page_change_message,
-                   "StupidType", request, page, "en", revisions=page.getRevList())
-
-def test_filter_subscriber_list(request):
-    user = User(request)
-    event = events.Event(request)
-
-    print "User is subscribed to this event on jabber."
-    print "This means, that he should stay on the list."
-    user.jid = "user@example.com"
-    user.jabber_subscribed_events = [events.Event.__name__]
-    subscribers = {"en": [user]}
-    notification.filter_subscriber_list(event, subscribers, True)
-    assert subscribers["en"]
-
-    print "User is not subscribed to this event on jabber."
-    print "The list should be empty."
-    user.jid = "user@example.com"
-    user.jabber_subscribed_events = []
-    subscribers = {"en": [user]}
-    notification.filter_subscriber_list(event, subscribers, True)
-    assert not subscribers["en"]
-
-    print "User is subscribed to this event on email."
-    print "This means, that he should stay on the list."
-    user.email = "user@example.com"
-    user.email_subscribed_events = [events.Event.__name__]
-    subscribers = {"en": [user]}
-    notification.filter_subscriber_list(event, subscribers, False)
-    assert subscribers["en"]
-
-    print "User is not subscribed to this event on email."
-    print "The list should be empty."
-    user.email = "user@example.com"
-    user.email_subscribed_events = []
-    subscribers = {"en": [user]}
-    notification.filter_subscriber_list(event, subscribers, False)
-    assert not subscribers["en"]
-
-coverage_modules = ["MoinMoin.events"]
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/events/_tests/test_events.py	Sat Jul 21 02:33:34 2007 +0200
@@ -0,0 +1,86 @@
+# -*- coding: iso-8859-1 -*-
+"""
+    MoinMoin - tests for MoinMoin.events module
+
+    @copyright: 2007 by Karol Nowak <grywacz@gmail.com>
+    @license: GNU GPL, see COPYING for details.
+"""
+
+import py
+
+import MoinMoin.events as events
+import MoinMoin.events.notification as notification
+import MoinMoin.events.jabbernotify as jabbernotify
+from MoinMoin.Page import Page
+from MoinMoin.user import User
+
+def test_get_handlers(request):
+    """Test if there are any event handlers. There should be some internal ones"""
+
+    assert events.get_handlers(request.cfg)
+
+def test_send_event(request):
+    """Test if event handlers are called and if proper messages are returned"""
+
+    return_string = u"test_send_event"
+
+    def event_handler(event):
+        return notification.Failure("Just a test")
+
+    request.cfg.event_handlers = [event_handler]
+    event = events.Event(request)
+
+    print "A proper event handler must be called and an 1-element list of results returned"
+    results = events.send_event(event)
+    assert issubclass(results[0].__class__, events.EventResult)
+
+def test_subscribable_events(request):
+    """Test if there are any subscribable events. There should be some."""
+
+    print "There should be at least a few subscribable events!"
+    assert events.get_subscribable_events()
+
+def test_page_change_message(request):
+    page = Page(request, "FrontPage")
+
+    print "Provided with a dumb change type argument, this should raise an exception!"
+    py.test.raises(notification.UnknownChangeType, notification.page_change_message,
+                   "StupidType", request, page, "en", revisions=page.getRevList())
+
+def test_filter_subscriber_list(request):
+    user = User(request)
+    event = events.Event(request)
+
+    print "User is subscribed to this event on jabber."
+    print "This means, that he should stay on the list."
+    user.jid = "user@example.com"
+    user.jabber_subscribed_events = [events.Event.__name__]
+    subscribers = {"en": [user]}
+    notification.filter_subscriber_list(event, subscribers, True)
+    assert subscribers["en"]
+
+    print "User is not subscribed to this event on jabber."
+    print "The list should be empty."
+    user.jid = "user@example.com"
+    user.jabber_subscribed_events = []
+    subscribers = {"en": [user]}
+    notification.filter_subscriber_list(event, subscribers, True)
+    assert not subscribers["en"]
+
+    print "User is subscribed to this event on email."
+    print "This means, that he should stay on the list."
+    user.email = "user@example.com"
+    user.email_subscribed_events = [events.Event.__name__]
+    subscribers = {"en": [user]}
+    notification.filter_subscriber_list(event, subscribers, False)
+    assert subscribers["en"]
+
+    print "User is not subscribed to this event on email."
+    print "The list should be empty."
+    user.email = "user@example.com"
+    user.email_subscribed_events = []
+    subscribers = {"en": [user]}
+    notification.filter_subscriber_list(event, subscribers, False)
+    assert not subscribers["en"]
+
+coverage_modules = ["MoinMoin.events"]
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/filter/_tests/test_filter.py	Sat Jul 21 02:33:34 2007 +0200
@@ -0,0 +1,64 @@
+# -*- coding: iso-8859-1 -*-
+"""
+    MoinMoin - tests for MoinMoin.filter module
+
+    @copyright: 2007 by MoinMoin:ThomasWaldmann
+    @license: GNU GPL, see COPYING for details.
+"""
+
+import py
+from MoinMoin import filter
+
+class TestFilters:
+
+    def make_file(self, data):
+        import tempfile
+        fname = tempfile.mktemp()
+        f = file(fname, 'w')
+        f.write(data)
+        f.close()
+        return fname
+
+    def testBinaryGeneric(self):
+        from MoinMoin.filter.application_octet_stream import execute as _filter
+        tests = [('', ''),
+                 ('this\x00is\x00a\x00test\x00', u'this test'), # throws away short stuff
+                ]
+        for data, expected in tests:
+            fname = self.make_file(data)
+            assert _filter(None, fname) == expected
+
+    def testTextGeneric(self):
+        from MoinMoin.filter.text import execute as _filter
+        tests = [('', ''),
+                 ('asdf\r\nghjk', u'asdf\r\nghjk'),
+                 # add some tests with umlauts in diff. encodings
+                ]
+        for data, expected in tests:
+            fname = self.make_file(data)
+            assert _filter(None, fname) == expected
+
+    def testTextHtml(self):
+        from MoinMoin.filter.text_html import execute as _filter
+        tests = [('', ''),
+                 ('<html><body>Hello<br>World!</body></html>', u'Hello World!'),
+                ]
+        for data, expected in tests:
+            fname = self.make_file(data)
+            assert _filter(None, fname) == expected
+
+    def testTextXml(self):
+        from MoinMoin.filter.text_xml import execute as _filter
+        tests = [('', ''),
+                 ('<xml><para>Hello</para><para>World!</para></xml>', u'Hello World!'),
+                ]
+        for data, expected in tests:
+            fname = self.make_file(data)
+            assert _filter(None, fname) == expected
+
+coverage_modules = ['MoinMoin.filter.text',
+                    'MoinMoin.filter.text_html',
+                    'MoinMoin.filter.text_xml',
+                    'MoinMoin.filter.application_octet_stream',
+                   ]
+
--- a/jabberbot/xmlrpcbot.py	Fri Jul 20 22:56:13 2007 +0200
+++ b/jabberbot/xmlrpcbot.py	Sat Jul 21 02:33:34 2007 +0200
@@ -228,9 +228,18 @@
         """Returns language of the a user identified by the given JID"""
 
         server = xmlrpclib.ServerProxy(self.config.wiki_url + "?action=xmlrpc2")
-        language = server.getUserLanguageByJID(command.jid)
+        language = "en"
 
-        command.language = language or "en"
+        try:
+            language = server.getUserLanguageByJID(command.jid)
+        except xmlrpclib.Fault, fault:
+            self.log.error(str(fault))
+        except xmlrpclib.Error, err:
+            self.log.error(str(err))
+        except Exception, exc:
+            self.log.critical(str(exc))
+
+        command.language = language
         self.commands_out.put_nowait(command)
 
 
--- a/jabberbot/xmppbot.py	Fri Jul 20 22:56:13 2007 +0200
+++ b/jabberbot/xmppbot.py	Sat Jul 21 02:33:34 2007 +0200
@@ -223,6 +223,8 @@
 
                 self.send_message(jid, text)
 
+            return
+
         _ = self.getText(command.jid)
 
         # Handle subscribtion management commands
@@ -302,16 +304,22 @@
     def send_search_form(self, jid):
         _ = self.getText(jid)
 
-        # This encode may look weird, but due to some pyxmpp oddness we have
-        # to provide an unicode string. Maybe this should be fixed upstream...
+        # These encode()s may look weird, but due to some pyxmpp oddness we have
+        # to provide an utf-8 string instead of unicode. Bug reported, patches submitted...
+        form_title = _("Wiki search").encode("utf-8")
         help_form = _("Submit this form to perform a wiki search").encode("utf-8")
+        search_type1 = _("Title search")
+        search_type2 = _("Full-text search")
+        search_label = _("Search type")
+        search_label2 = _("Search text")
 
-        title_search = forms.Option("t", _("Title search")) #.decode("utf-8"))
-        full_search = forms.Option("f", _("Full-text search"))#.decode("utf-8"))
 
-        form = forms.Form(xmlnode_or_type="form", title=_("Wiki search"), instructions=help_form)
-        form.add_field(name="search_type", options=[title_search, full_search], field_type="list-single", label=_("Search type"))
-        form.add_field(name="search", field_type="text-single", label=_("Search text"))
+        title_search = forms.Option("t", search_type1)
+        full_search = forms.Option("f", search_type2)
+
+        form = forms.Form(xmlnode_or_type="form", title=form_title, instructions=help_form)
+        form.add_field(name="search_type", options=[title_search, full_search], field_type="list-single", label=search_label)
+        form.add_field(name="search", field_type="text-single", label=search_label2)
 
         message = Message(to_jid=jid, body=_("Please specify the search criteria."), subject=_("Wiki search"))
         message.add_content(form)