From: richard Date: Tue, 22 Jan 2002 06:35:40 +0000 (+0000) Subject: more htmltemplate tests and cleanup X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=9cea867f637193e32bd0e1f43be61cfbc272bc1a;p=roundup.git more htmltemplate tests and cleanup git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@580 57a73879-2fb5-44c3-a270-3262357dd7e2 --- diff --git a/roundup/htmltemplate.py b/roundup/htmltemplate.py index 6c59c94..604b664 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.65 2002-01-22 00:12:06 richard Exp $ +# $Id: htmltemplate.py,v 1.66 2002-01-22 06:35:40 richard Exp $ __doc__ = """ Template engine. @@ -299,19 +299,18 @@ class TemplateFunctions: ''' if not self.nodeid and self.form is None: return _('[Link: not called from item]') + + # get the value + value = self.determine_value(property) + if not value: + return _('[no %(propname)s]')%{'propname':property.capitalize()} + propclass = self.properties[property] - if self.nodeid: - value = self.cl.get(self.nodeid, property) - else: - if isinstance(propclass, hyperdb.Multilink): value = [] - elif isinstance(propclass, hyperdb.Link): value = None - else: value = '' if isinstance(propclass, hyperdb.Link): linkname = propclass.classname - if value is None: return '[no %s]'%property.capitalize() linkcl = self.db.classes[linkname] k = linkcl.labelprop() - linkvalue = linkcl.get(value, k) + linkvalue = cgi.escape(linkcl.get(value, k)) if is_download: return '%s'%(linkname, value, linkvalue, linkvalue) @@ -321,11 +320,9 @@ class TemplateFunctions: linkname = propclass.classname linkcl = self.db.classes[linkname] k = linkcl.labelprop() - if not value: - return _('[no %(propname)s]')%{'propname': property.capitalize()} l = [] for value in value: - linkvalue = linkcl.get(value, k) + linkvalue = cgi.escape(linkcl.get(value, k)) if is_download: l.append('%s'%(linkname, value, linkvalue, linkvalue)) @@ -333,8 +330,6 @@ class TemplateFunctions: l.append('%s'%(linkname, value, linkvalue)) return ', '.join(l) - if isinstance(propclass, hyperdb.String) and value == '': - return _('[no %(propname)s]')%{'propname': property.capitalize()} if is_download: return '%s'%(self.classname, self.nodeid, value, value) @@ -1043,6 +1038,10 @@ class NewItemTemplate(TemplateFunctions): # # $Log: not supported by cvs2svn $ +# 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. +# # Revision 1.64 2002/01/21 03:25:59 richard # oops # diff --git a/test/test_htmltemplate.py b/test/test_htmltemplate.py index 3c7143b..0285a71 100644 --- a/test/test_htmltemplate.py +++ b/test/test_htmltemplate.py @@ -8,19 +8,21 @@ # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # -# $Id: test_htmltemplate.py,v 1.2 2002-01-22 00:12:07 richard Exp $ +# $Id: test_htmltemplate.py,v 1.3 2002-01-22 06:35:40 richard Exp $ import unittest, cgi +from roundup import date, password from roundup.htmltemplate import TemplateFunctions -from roundup import date -from roundup import password +from roundup.i18n import _ from roundup.hyperdb import String, Password, Date, Interval, Link, Multilink class Class: def get(self, nodeid, attribute, default=None): if attribute == 'string': return 'Node %s: I am a string'%nodeid + elif attribute == 'filename': + return 'file.foo' elif attribute == 'date': return date.Date('2000-01-01') elif attribute == 'interval': @@ -40,7 +42,8 @@ class Class: def getprops(self): return {'string': String(), 'date': Date(), 'interval': Interval(), 'link': Link('other'), 'multilink': Multilink('other'), - 'password': Password(), 'html': String(), 'key': String()} + 'password': Password(), 'html': String(), 'key': String(), + 'novalue': String(), 'filename': String()} def labelprop(self): return 'key' @@ -58,6 +61,7 @@ class NodeCase(unittest.TestCase): self.tf = tf = TemplateFunctions() tf.nodeid = '1' tf.cl = Class() + tf.classname = 'test_class' tf.properties = tf.cl.getprops() tf.db = Database() @@ -134,6 +138,12 @@ class NodeCase(unittest.TestCase): '') # def do_menu(self, property, size=None, height=None, showid=0): + def testMenu_nonlinks(self): + self.assertEqual(self.tf.do_menu('string'), _('[Menu: not a link]')) + self.assertEqual(self.tf.do_menu('date'), _('[Menu: not a link]')) + self.assertEqual(self.tf.do_menu('interval'), _('[Menu: not a link]')) + self.assertEqual(self.tf.do_menu('password'), _('[Menu: not a link]')) + def testMenu_link(self): self.assertEqual(self.tf.do_menu('link'), '''''') +# 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()}) + + def testLink_string(self): + self.assertEqual(self.tf.do_link('string'), + 'Node 1: I am a string') + + def testLink_file(self): + self.assertEqual(self.tf.do_link('filename', is_download=1), + 'file.foo') + + def testLink_date(self): + self.assertEqual(self.tf.do_link('date'), + '2000-01-01.00:00:00') + + def testLink_interval(self): + self.assertEqual(self.tf.do_link('interval'), + '- 3d') + + def testLink_link(self): + self.assertEqual(self.tf.do_link('link'), + 'the key') + + def testLink_multilink(self): + self.assertEqual(self.tf.do_link('multilink'), + 'the key, the key') + def suite(): return unittest.makeSuite(NodeCase, 'test') # # $Log: not supported by cvs2svn $ +# 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. +# # Revision 1.1 2002/01/21 11:05:48 richard # New tests for htmltemplate (well, it's a beginning) #