Commits

Anonymous committed ba1a255

[svn r9694] EstimationToolsPlugin: Switch from pre-0.11 `render_macro()` call to `expand_macro()` call for Trac 0.11++

(Also fixes test that used a fixed time period, where test broke when the period passed...)

  • Participants
  • Parent commits e55f4c2

Comments (0)

Files changed (6)

estimationtools/burndownchart.py

     closed_states = get_closed_states()
     serverside_charts = get_serverside_charts()
 
-    def render_macro(self, req, name, content):
+    def expand_macro(self, formatter, name, content):
 
         # prepare options
+        req = formatter.req
         options, query_args = parse_options(self.env.get_db_cnx(), content, copy.copy(DEFAULT_OPTIONS))
 
         if not options['startdate']:

estimationtools/hoursremaining.py

         
     closed_states = get_closed_states()
     
-    def render_macro(self, req, name, content):
+    def expand_macro(self, formatter, name, content):
+        req = formatter.req
         _ignore, options = parse_args(content, strict=False)
 
         # we have to add custom estimation field to query so that field is added to

estimationtools/tests/burndownchart.py

                         abs_href = Href('http://www.example.com/'),
                         perm = MockPerm(),
                         authname='anonymous')
+        self.formatter = Mock(req=self.req)
         
     def _insert_ticket(self, estimation):
         ticket = Ticket(self.env)
     def test_build_zero_day_chart(self):
         chart = BurndownChart(self.env)
         # shouldn't throw
-        chart.render_macro(self.req, "", "startdate=2008-01-01, enddate=2008-01-01")
+        chart.expand_macro(self.formatter, "", "startdate=2008-01-01, enddate=2008-01-01")
         
     def test_calculate_timetable_simple(self):
         chart = BurndownChart(self.env)
         self.assertEqual(timetable, {day1: Decimal(10), day2: Decimal(10), day3: Decimal(5)})
 
     def test_url_encode(self):
+        start = datetime.now(utc).date()
+        end = (start + timedelta(days=5)).strftime('%Y-%m-%d')
+        start = start.strftime('%Y-%m-%d')
         chart = BurndownChart(self.env)
         t = Ticket(self.env, self._insert_ticket('12'))
-        result = chart.render_macro(self.req, 'BurndownChart',
-                        "milestone=milestone1, startdate=2010-09-15, enddate=2010-09-20")
+        result = chart.expand_macro(self.formatter, 'BurndownChart',
+                        "milestone=milestone1, startdate=%s, enddate=%s" % (start, end))
         self.failUnless("&chtt=milestone1&" in str(result))
-        result = chart.render_macro(self.req, 'BurndownChart',
-                        "milestone=One & Two, startdate=2010-09-15, enddate=2010-09-20")
+        result = chart.expand_macro(self.formatter, 'BurndownChart',
+                        "milestone=One & Two, startdate=%s, enddate=%s" % (start, end))
         self.failUnless("&chtt=One+%26+Two&" in str(result))
 
     def test_expected_y_axis(self):
+        start = datetime.now(utc).date()
+        end = (start + timedelta(days=5)).strftime('%Y-%m-%d')
+        start = start.strftime('%Y-%m-%d')
         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")
+        result = chart.expand_macro(self.formatter, 'BurndownChart',
+                        "startdate=%s, enddate=%s" % (start, end))
         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")
+        result = chart.expand_macro(self.formatter, 'BurndownChart',
+                        "startdate=%s, enddate=%s, expected=200" % (start, end))
         self.assertEquals(self._extract_query(result)['chxr'], [u'2,0,200'])

estimationtools/tests/hoursremaining.py

                         abs_href = Href('http://www.example.com/'),
                         perm = MockPerm(),
                         authname='anonymous')
+        self.formatter = Mock(req=self.req)
        
     def _insert_ticket(self, estimation, status='open'):
         ticket = Ticket(self.env)
         self._insert_ticket('10')
         self._insert_ticket('20')
         self._insert_ticket('30')
-        result = hoursRemaining.render_macro(self.req, "", "milestone=milestone1")
+        result = hoursRemaining.expand_macro(self.formatter, "", "milestone=milestone1")
         self.assertEqual(result, '60')
 
     def test_real(self):
         self._insert_ticket('10')
         self._insert_ticket('20.1')
         self._insert_ticket('30')
-        result = hoursRemaining.render_macro(self.req, "", "milestone=milestone1")
+        result = hoursRemaining.expand_macro(self.formatter, "", "milestone=milestone1")
         self.assertEqual(result, '60.1')
 
     def test_invalid(self):
         self._insert_ticket('20')
         self._insert_ticket('30')
         self._insert_ticket('xxx')
-        result = hoursRemaining.render_macro(self.req, "", "milestone=milestone1")
+        result = hoursRemaining.expand_macro(self.formatter, "", "milestone=milestone1")
         self.assertEqual(result, '60')
 
     def test_closed_tickets(self):
         self._insert_ticket('20.1')
         self._insert_ticket('30')
         self._insert_ticket('30', status='closed')
-        result = hoursRemaining.render_macro(self.req, "", "status!=closed, milestone=milestone1")
+        result = hoursRemaining.expand_macro(self.formatter, "", "status!=closed, milestone=milestone1")
         self.assertEqual(result, '60.1')
 
     def test_to_many_tickets(self):
         hoursRemaining = HoursRemaining(self.env)
         for _ in range(200):
             self._insert_ticket('1')
-        result = hoursRemaining.render_macro(self.req, "", "milestone=milestone1")
-        self.assertEqual(result, '200')
+        result = hoursRemaining.expand_macro(self.formatter, "", "milestone=milestone1")
+        self.assertEqual(result, '200')

estimationtools/tests/workloadchart.py

                         abs_href = Href('http://www.example.com/'),
                         perm = MockPerm(),
                         authname='anonymous')
+        self.formatter = Mock(req=self.req)
        
     def _insert_ticket(self, estimation, owner):
         ticket = Ticket(self.env)
         self._insert_ticket('10', 'A')
         self._insert_ticket('20', 'B')
         self._insert_ticket('30', 'C')
-        result = workload_chart.render_macro(self.req, "", "milestone=milestone1")
+        result = workload_chart.expand_macro(self.formatter, "", "milestone=milestone1")
         self.assertEqual(str(result), '<image src="http://chart.apis.google.com/chart?'
                 'chd=t%3A10%2C30%2C20&amp;chf=bg%2Cs%2C00000000&amp;chco=ff9900&amp;'
                 'chl=A+10h%7CC+30h%7CB+20h&amp;chs=400x100&amp;cht=p3&amp;'
         self._insert_ticket('10', 'B')
         self._insert_ticket('30', 'C')
         self._insert_ticket('xxx', 'D')
-        result = workload_chart.render_macro(self.req, "", "milestone=milestone1")
+        result = workload_chart.expand_macro(self.formatter, "", "milestone=milestone1")
         self.assertEqual(str(result), '<image src="http://chart.apis.google.com/chart?'
                 'chd=t%3A10%2C30%2C20&amp;chf=bg%2Cs%2C00000000&amp;'
                 'chco=ff9900&amp;chl=A+10h%7CC+30h%7CB+20h&amp;chs=400x100&amp;'
     def test_username_obfuscation(self):
         workload_chart = WorkloadChart(self.env)
         self._insert_ticket('10', 'user@example.org')
-        result = workload_chart.render_macro(self.req, "", "milestone=milestone1")
+        result = workload_chart.expand_macro(self.formatter, "", "milestone=milestone1")
         self.failUnless("&amp;chl=user%40%E2%80%A6+10h&amp;" in str(result))

estimationtools/workloadchart.py

     closed_states = get_closed_states()
     serverside_charts = get_serverside_charts()
 
-    def render_macro(self, req, name, content):
+    def expand_macro(self, formatter, name, content):
+        req = formatter.req
         db = self.env.get_db_cnx()
         # prepare options
         options, query_args = parse_options(db, content, copy.copy(DEFAULT_OPTIONS))