Author: astaric
Date: Wed Jun 26 15:15:52 2013
New Revision: 1496958

URL: http://svn.apache.org/r1496958
Log:
More robust handling of resources in timeline widget.

Should fix problem described in #547.

Added:
    bloodhound/trunk/bloodhound_dashboard/bhdashboard/tests/widgets/
    bloodhound/trunk/bloodhound_dashboard/bhdashboard/tests/widgets/__init__.py
    bloodhound/trunk/bloodhound_dashboard/bhdashboard/tests/widgets/timeline.py
Modified:
    bloodhound/trunk/bloodhound_dashboard/bhdashboard/widgets/timeline.py

Added: 
bloodhound/trunk/bloodhound_dashboard/bhdashboard/tests/widgets/__init__.py
URL: 
http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_dashboard/bhdashboard/tests/widgets/__init__.py?rev=1496958&view=auto
==============================================================================
--- bloodhound/trunk/bloodhound_dashboard/bhdashboard/tests/widgets/__init__.py 
(added)
+++ bloodhound/trunk/bloodhound_dashboard/bhdashboard/tests/widgets/__init__.py 
Wed Jun 26 15:15:52 2013
@@ -0,0 +1,19 @@
+#!/usr/bin/env python
+# -*- coding: UTF-8 -*-
+
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing,
+#  software distributed under the License is distributed on an
+#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#  KIND, either express or implied.  See the License for the
+#  specific language governing permissions and limitations
+#  under the License.

Added: 
bloodhound/trunk/bloodhound_dashboard/bhdashboard/tests/widgets/timeline.py
URL: 
http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_dashboard/bhdashboard/tests/widgets/timeline.py?rev=1496958&view=auto
==============================================================================
--- bloodhound/trunk/bloodhound_dashboard/bhdashboard/tests/widgets/timeline.py 
(added)
+++ bloodhound/trunk/bloodhound_dashboard/bhdashboard/tests/widgets/timeline.py 
Wed Jun 26 15:15:52 2013
@@ -0,0 +1,56 @@
+#!/usr/bin/env python
+# -*- coding: UTF-8 -*-
+
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing,
+#  software distributed under the License is distributed on an
+#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#  KIND, either express or implied.  See the License for the
+#  specific language governing permissions and limitations
+#  under the License.
+import unittest
+from bhdashboard.widgets.timeline import TicketFieldTimelineFilter
+from trac.test import EnvironmentStub, Mock
+from trac.ticket import Ticket
+
+
+class TicketFieldTimelineFilterTests(unittest.TestCase):
+    def setUp(self):
+        self.env = EnvironmentStub()
+        t1 = self._insert_and_load_ticket("foo")
+        self.filter = TicketFieldTimelineFilter(self.env)
+        self.context = context = Mock(resource=t1.resource)
+
+    def tearDown(self):
+        self.env.reset_db()
+
+    def test_returns_none_for_invalid_ticket_id(self):
+        event = ['ticket', None, None, ['88']]
+
+        result = self.filter.filter_event(self.context, None, event, None)
+        self.assertIsNone(result)
+
+    def test_long_resource_id(self):
+        """Test resource with long id (#547)"""
+        resource = self.context.resource
+        resource.id = long(resource.id)
+        event = ['ticket', None, None, [resource]]
+
+        result = self.filter.filter_event(self.context, None, event, None)
+        self.assertEqual(result, event)
+
+    def _insert_and_load_ticket(self, summary, **kw):
+        ticket = Ticket(self.env)
+        ticket["summary"] = summary
+        for k, v in kw.items():
+            ticket[k] = v
+        return Ticket(self.env, ticket.insert())

Modified: bloodhound/trunk/bloodhound_dashboard/bhdashboard/widgets/timeline.py
URL: 
http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_dashboard/bhdashboard/widgets/timeline.py?rev=1496958&r1=1496957&r2=1496958&view=diff
==============================================================================
--- bloodhound/trunk/bloodhound_dashboard/bhdashboard/widgets/timeline.py 
(original)
+++ bloodhound/trunk/bloodhound_dashboard/bhdashboard/widgets/timeline.py Wed 
Jun 26 15:15:52 2013
@@ -33,7 +33,7 @@ from trac.core import Component, Extensi
         TracError
 from trac.config import IntOption
 from trac.mimeview.api import RenderingContext
-from trac.resource import Resource, resource_exists
+from trac.resource import Resource, resource_exists, ResourceNotFound
 from trac.timeline.web_ui import TimelineModule
 from trac.ticket.api import TicketSystem
 from trac.ticket.model import Ticket
@@ -380,22 +380,24 @@ class TicketFieldTimelineFilter(Componen
                 except:
                     self.log.exception('Unknown ticket event %s ... [SKIP]',
                             event)
-                else:
-                    if not isinstance(ticket_ids, list):
-                        ticket_ids = [ticket_ids]
+                    return None
+
+                if not isinstance(ticket_ids, list):
+                    ticket_ids = [ticket_ids]
                 context._ticket_cache = ticket_cache = \
-                        getattr(context, '_ticket_cache', None) or {}
+                    getattr(context, '_ticket_cache', None) or {}
                 for t in ticket_ids:
                     if isinstance(t, Resource):
                         if event[0] != 'attachment':
                             t = t.id
                         else:
                             t = t.parent.id
-                    if isinstance(t, (int, basestring)):
+                    try:
                         t = ticket_cache.get(t) or Ticket(self.env, t)
-                    if field_name == 'ticket':
-                        if t.id == context.resource.id:
-                            return event
+                    except ResourceNotFound:
+                        return None
+                    if field_name == 'ticket' and t.id == context.resource.id:
+                        return event
                     if t[field_name] == context.resource.id:
                         return event
                     ticket_cache[t.id] = t


Reply via email to