Author: astaric
Date: Mon Aug 26 08:27:40 2013
New Revision: 1517457

URL: http://svn.apache.org/r1517457
Log:
Catch error when relation notification fails.

Display a warning instead.
Refs: #644

Modified:
    bloodhound/trunk/bloodhound_relations/bhrelations/api.py
    bloodhound/trunk/bloodhound_relations/bhrelations/tests/base.py
    bloodhound/trunk/bloodhound_relations/bhrelations/tests/web_ui.py
    bloodhound/trunk/bloodhound_relations/bhrelations/web_ui.py

Modified: bloodhound/trunk/bloodhound_relations/bhrelations/api.py
URL: 
http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_relations/bhrelations/api.py?rev=1517457&r1=1517456&r2=1517457&view=diff
==============================================================================
--- bloodhound/trunk/bloodhound_relations/bhrelations/api.py (original)
+++ bloodhound/trunk/bloodhound_relations/bhrelations/api.py Mon Aug 26 
08:27:40 2013
@@ -269,9 +269,6 @@ class RelationsSystem(Component):
             for listener in self.changing_listeners:
                 listener.adding_relation(relation)
 
-            from bhrelations.notification import RelationNotifyEmail
-            RelationNotifyEmail(self.env).notify(relation)
-
     def delete(self, relation_id, when=None):
         if when is None:
             when = datetime.now(utc)

Modified: bloodhound/trunk/bloodhound_relations/bhrelations/tests/base.py
URL: 
http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_relations/bhrelations/tests/base.py?rev=1517457&r1=1517456&r2=1517457&view=diff
==============================================================================
--- bloodhound/trunk/bloodhound_relations/bhrelations/tests/base.py (original)
+++ bloodhound/trunk/bloodhound_relations/bhrelations/tests/base.py Mon Aug 26 
08:27:40 2013
@@ -18,7 +18,8 @@
 from _sqlite3 import OperationalError
 from tests.env import MultiproductTestCase
 from multiproduct.env import ProductEnvironment
-from bhrelations.api import RelationsSystem, EnvironmentSetup
+from bhrelations.api import RelationsSystem, EnvironmentSetup, \
+    RELATIONS_CONFIG_NAME
 from trac.test import EnvironmentStub, Mock, MockPerm
 from trac.ticket import Ticket
 from trac.util.datefmt import utc
@@ -43,7 +44,7 @@ class BaseRelationsTestCase(Multiproduct
                        'BlockerValidator')
         env.config.set('bhrelations', 'duplicate_relation',
                        'duplicateof')
-        config_name = RelationsSystem.RELATIONS_CONFIG_NAME
+        config_name = RELATIONS_CONFIG_NAME
         env.config.set(config_name, 'dependency', 'dependson,dependent')
         env.config.set(config_name, 'dependency.validators',
                        'NoCycles,SingleProduct')
@@ -72,7 +73,8 @@ class BaseRelationsTestCase(Multiproduct
 
         self.req = Mock(href=self.env.href, authname='anonymous', tz=utc,
                         args=dict(action='dummy'),
-                        locale=locale_en, lc_time=locale_en)
+                        locale=locale_en, lc_time=locale_en,
+                        chrome={'warnings': []})
         self.req.perm = MockPerm()
         self.relations_system = RelationsSystem(self.env)
         self._upgrade_env()

Modified: bloodhound/trunk/bloodhound_relations/bhrelations/tests/web_ui.py
URL: 
http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_relations/bhrelations/tests/web_ui.py?rev=1517457&r1=1517456&r2=1517457&view=diff
==============================================================================
--- bloodhound/trunk/bloodhound_relations/bhrelations/tests/web_ui.py (original)
+++ bloodhound/trunk/bloodhound_relations/bhrelations/tests/web_ui.py Mon Aug 
26 08:27:40 2013
@@ -86,6 +86,20 @@ class RelationManagementModuleTestCase(B
 
         self.assertEqual(len(data["relations"]), 1)
 
+    def test_failure_to_notify_does_not_result_in_error(self):
+        t2 = self._insert_ticket(self.env, "Bar")
+        self.req.args['add'] = True
+        self.req.args['dest_tid'] = str(t2)
+        self.req.args['reltype'] = 'dependson'
+        rlm = RelationManagementModule(self.env)
+        rlm.notify_relation_changed = self._failing_notification
+
+        url, data, x = rlm.process_request(self.req)
+        self.assertEqual(len(self.req.chrome['warnings']), 1)
+
+    def _failing_notification(self, relation):
+        raise Exception()
+
     def process_request(self):
         url, data, x = RelationManagementModule(self.env).process_request(
             self.req)

Modified: bloodhound/trunk/bloodhound_relations/bhrelations/web_ui.py
URL: 
http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_relations/bhrelations/web_ui.py?rev=1517457&r1=1517456&r2=1517457&view=diff
==============================================================================
--- bloodhound/trunk/bloodhound_relations/bhrelations/web_ui.py (original)
+++ bloodhound/trunk/bloodhound_relations/bhrelations/web_ui.py Mon Aug 26 
08:27:40 2013
@@ -29,6 +29,7 @@ import re
 from trac.core import Component, implements, TracError
 from trac.resource import get_resource_url, Resource
 from trac.ticket.model import Ticket
+from trac.util import exception_to_unicode, to_unicode
 from trac.util.translation import _
 from trac.web import IRequestHandler, IRequestFilter
 from trac.web.chrome import ITemplateProvider, add_warning
@@ -104,6 +105,18 @@ class RelationManagementModule(Component
                     except ValidationError as ex:
                         data['error'] = ex.message
 
+                # Notify
+                try:
+                    self.notify_relation_changed(relation)
+                except Exception, e:
+                    self.log.error("Failure sending notification on"
+                                   "creation of relation: %s",
+                                   exception_to_unicode(e))
+                    add_warning(req, _("The relation has been added, but an "
+                                       "error occurred while sending"
+                                       "notifications: " "%(message)s",
+                                       message=to_unicode(e)))
+
                 if 'error' in data:
                     data['relation'] = relation
             else:
@@ -117,6 +130,10 @@ class RelationManagementModule(Component
         })
         return 'relations_manage.html', data, None
 
+    def notify_relation_changed(self, relation):
+        from bhrelations.notification import RelationNotifyEmail
+        RelationNotifyEmail(self.env).notify(relation)
+
     # ITemplateProvider methods
     def get_htdocs_dirs(self):
         return []


Reply via email to