From c1453446c272a711c1e37a629d1956869ddbc226 Mon Sep 17 00:00:00 2001 From: richard Date: Tue, 22 Jan 2002 22:46:22 +0000 Subject: [PATCH] more htmltemplate cleanups and unit tests git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@586 57a73879-2fb5-44c3-a270-3262357dd7e2 --- roundup/htmltemplate.py | 28 ++++++++++++++++++++-------- test/test_htmltemplate.py | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 10 deletions(-) diff --git a/roundup/htmltemplate.py b/roundup/htmltemplate.py index 604b664..ff0276f 100644 --- a/roundup/htmltemplate.py +++ b/roundup/htmltemplate.py @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: htmltemplate.py,v 1.66 2002-01-22 06:35:40 richard Exp $ +# $Id: htmltemplate.py,v 1.67 2002-01-22 22:46:22 richard Exp $ __doc__ = """ Template engine. @@ -302,8 +302,8 @@ class TemplateFunctions: # get the value value = self.determine_value(property) - if not value: - return _('[no %(propname)s]')%{'propname':property.capitalize()} + if not value: + return _('[no %(propname)s]')%{'propname':property.capitalize()} propclass = self.properties[property] if isinstance(propclass, hyperdb.Link): @@ -342,11 +342,14 @@ class TemplateFunctions: ''' if not self.nodeid: return _('[Count: not called from item]') + propclass = self.properties[property] + if not isinstance(propclass, hyperdb.Multilink): + return _('[Count: not a Multilink]') + + # figure the length then... value = self.cl.get(self.nodeid, property) - if isinstance(propclass, hyperdb.Multilink): - return str(len(value)) - return _('[Count: not a Multilink]') + return str(len(value)) # XXX pretty is definitely new ;) def do_reldate(self, property, pretty=0): @@ -357,13 +360,19 @@ class TemplateFunctions: ''' if not self.nodeid and self.form is None: return _('[Reldate: not called from item]') + propclass = self.properties[property] - if isinstance(not propclass, hyperdb.Date): + if not isinstance(propclass, hyperdb.Date): return _('[Reldate: not a Date]') + if self.nodeid: value = self.cl.get(self.nodeid, property) else: - value = date.Date('.') + return '' + if not value: + return '' + + # figure the interval interval = value - date.Date('.') if pretty: if not self.nodeid: @@ -1038,6 +1047,9 @@ class NewItemTemplate(TemplateFunctions): # # $Log: not supported by cvs2svn $ +# Revision 1.66 2002/01/22 06:35:40 richard +# more htmltemplate tests and cleanup +# # Revision 1.65 2002/01/22 00:12:06 richard # Wrote more unit tests for htmltemplate, and while I was at it, I polished # off the implementation of some of the functions so they behave sanely. diff --git a/test/test_htmltemplate.py b/test/test_htmltemplate.py index 0285a71..3757239 100644 --- a/test/test_htmltemplate.py +++ b/test/test_htmltemplate.py @@ -8,7 +8,7 @@ # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # -# $Id: test_htmltemplate.py,v 1.3 2002-01-22 06:35:40 richard Exp $ +# $Id: test_htmltemplate.py,v 1.4 2002-01-22 22:46:22 richard Exp $ import unittest, cgi @@ -183,7 +183,7 @@ class NodeCase(unittest.TestCase): # def do_link(self, property=None, is_download=0): def testLink_novalue(self): self.assertEqual(self.tf.do_link('novalue'), - _('[no %(propname)s]')%{'propname':'novalue'.capitalize()}) + _('[no %(propname)s]')%{'propname':'novalue'.capitalize()}) def testLink_string(self): self.assertEqual(self.tf.do_link('string'), @@ -209,12 +209,41 @@ class NodeCase(unittest.TestCase): self.assertEqual(self.tf.do_link('multilink'), 'the key, the key') +# def do_count(self, property, **args): + def testCount_nonlinks(self): + s = _('[Count: not a Multilink]') + self.assertEqual(self.tf.do_count('string'), s) + self.assertEqual(self.tf.do_count('date'), s) + self.assertEqual(self.tf.do_count('interval'), s) + self.assertEqual(self.tf.do_count('password'), s) + self.assertEqual(self.tf.do_count('link'), s) + + def testCount_multilink(self): + self.assertEqual(self.tf.do_count('multilink'), '2') + +# def do_reldate(self, property, pretty=0): + def testReldate_nondate(self): + s = _('[Reldate: not a Date]') + self.assertEqual(self.tf.do_reldate('string'), s) + self.assertEqual(self.tf.do_reldate('interval'), s) + self.assertEqual(self.tf.do_reldate('password'), s) + self.assertEqual(self.tf.do_reldate('link'), s) + self.assertEqual(self.tf.do_reldate('multilink'), s) + + def testReldate_date(self): + self.assertEqual(self.tf.do_reldate('date'), '- 2y 1m') + self.assertEqual(self.tf.do_reldate('date', pretty=1), + ' 1 January 2000') + def suite(): return unittest.makeSuite(NodeCase, 'test') # # $Log: not supported by cvs2svn $ +# Revision 1.3 2002/01/22 06:35:40 richard +# more htmltemplate tests and cleanup +# # Revision 1.2 2002/01/22 00:12:07 richard # Wrote more unit tests for htmltemplate, and while I was at it, I polished # off the implementation of some of the functions so they behave sanely. -- 2.30.2