Anonymous avatar Anonymous committed e55f4c2

[svn r9029] EstimationToolsPlugin: Fix issue with Y-axis scaling when 'expected' value was higher than any max value for hours. Tests included. Closes #7003.

Comments (0)

Files changed (3)


         dates = timetable.keys()
-        maxhours = max(timetable.values())
+        maxhours = max(timetable.values() + [int(options.get('expected', 0))])
         if maxhours <= Decimal(0):
             maxhours = Decimal(100)


 from decimal import Decimal
 from datetime import datetime, timedelta
 from estimationtools.burndownchart import BurndownChart
-from estimationtools.utils import parse_options
+from estimationtools.utils import parse_options, urldecode
 from trac.test import EnvironmentStub, MockPerm, Mock
 from trac.ticket.model import Ticket
 from trac.util.datefmt import utc
 from trac.web.href import Href
 import unittest
+from genshi.builder import QName
 class BurndownChartTestCase(unittest.TestCase):
             ticket['status'] = history[key]
             ticket.save_changes("me", "testing", datetime.combine(key,       
+    def _extract_query(self, image):
+        """ Parses <image/> element, urldecodes the query and returns it as dict. """
+        for t, v in image.attrib:
+            if t == QName('src'):
+                return urldecode(v.split('?')[1])
+        return {}
     def test_parse_options(self):
         db = self.env.get_db_cnx()
         options, query_args = parse_options(db, "milestone=milestone1, startdate=2008-02-20, enddate=2008-02-28", {})
         result = chart.render_macro(self.req, 'BurndownChart',
                         "milestone=One & Two, startdate=2010-09-15, enddate=2010-09-20")
         self.failUnless("&amp;chtt=One+%26+Two&amp;" in str(result))
+    def test_expected_y_axis(self):
+        chart = BurndownChart(self.env)
+        t = Ticket(self.env, self._insert_ticket('12'))
+        # Test without expected
+        result = chart.render_macro(self.req, 'BurndownChart',
+                        "startdate=2010-09-15, enddate=2010-09-20")
+        self.assertEquals(self._extract_query(result)['chxr'], [u'2,0,12'])
+        # Confirm Y axis changes with new higher expected
+        result = chart.render_macro(self.req, 'BurndownChart',
+                        "startdate=2010-09-15, enddate=2010-09-20, expected=200")
+        self.assertEquals(self._extract_query(result)['chxr'], [u'2,0,200'])


-import urllib2
+import urllib, urllib2
 from datetime import datetime
 from time import strptime
 from trac.config import Option, ListOption, BoolOption
         return s
     s = str(s).strip().lower()
     return not s in ['false','f','n','0','']
+def urldecode(query):
+    # Adapted from example on Python mailing lists
+    d = {}
+    a = query.split('&')
+    for s in a:
+        if s.find('='):
+            k,v = map(urllib.unquote, s.split('='))
+            try:
+                d[k].append(v)
+            except KeyError:
+                d[k] = [v]
+    return d
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.