changeset 574:d41d94511170

more htmltemplate cleanups and unit tests
author Richard Jones <richard@users.sourceforge.net>
date Tue, 22 Jan 2002 22:46:22 +0000
parents f0513f650042
children 2df17627528d
files roundup/htmltemplate.py test/test_htmltemplate.py
diffstat 2 files changed, 51 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/roundup/htmltemplate.py	Tue Jan 22 22:27:43 2002 +0000
+++ b/roundup/htmltemplate.py	Tue Jan 22 22:46:22 2002 +0000
@@ -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 @@
 
         # 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 @@
         '''
         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 @@
         '''
         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 @@
 
 #
 # $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.
--- a/test/test_htmltemplate.py	Tue Jan 22 22:27:43 2002 +0000
+++ b/test/test_htmltemplate.py	Tue Jan 22 22:46:22 2002 +0000
@@ -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 @@
 #    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 @@
         self.assertEqual(self.tf.do_link('multilink'),
             '<a href="other1">the key</a>, <a href="other2">the key</a>')
 
+#    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.

Roundup Issue Tracker: http://roundup-tracker.org/