Mercurial > p > roundup > code
comparison test/test_htmltemplate.py @ 568:c7ead967db85
more htmltemplate tests and cleanup
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Tue, 22 Jan 2002 06:35:40 +0000 |
| parents | 0f58d6a35a8b |
| children | d41d94511170 |
comparison
equal
deleted
inserted
replaced
| 567:9ca63f7332a7 | 568:c7ead967db85 |
|---|---|
| 6 # | 6 # |
| 7 # This module is distributed in the hope that it will be useful, | 7 # This module is distributed in the hope that it will be useful, |
| 8 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 8 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 10 # | 10 # |
| 11 # $Id: test_htmltemplate.py,v 1.2 2002-01-22 00:12:07 richard Exp $ | 11 # $Id: test_htmltemplate.py,v 1.3 2002-01-22 06:35:40 richard Exp $ |
| 12 | 12 |
| 13 import unittest, cgi | 13 import unittest, cgi |
| 14 | 14 |
| 15 from roundup import date, password | |
| 15 from roundup.htmltemplate import TemplateFunctions | 16 from roundup.htmltemplate import TemplateFunctions |
| 16 from roundup import date | 17 from roundup.i18n import _ |
| 17 from roundup import password | |
| 18 from roundup.hyperdb import String, Password, Date, Interval, Link, Multilink | 18 from roundup.hyperdb import String, Password, Date, Interval, Link, Multilink |
| 19 | 19 |
| 20 class Class: | 20 class Class: |
| 21 def get(self, nodeid, attribute, default=None): | 21 def get(self, nodeid, attribute, default=None): |
| 22 if attribute == 'string': | 22 if attribute == 'string': |
| 23 return 'Node %s: I am a string'%nodeid | 23 return 'Node %s: I am a string'%nodeid |
| 24 elif attribute == 'filename': | |
| 25 return 'file.foo' | |
| 24 elif attribute == 'date': | 26 elif attribute == 'date': |
| 25 return date.Date('2000-01-01') | 27 return date.Date('2000-01-01') |
| 26 elif attribute == 'interval': | 28 elif attribute == 'interval': |
| 27 return date.Interval('-3d') | 29 return date.Interval('-3d') |
| 28 elif attribute == 'link': | 30 elif attribute == 'link': |
| 38 def list(self): | 40 def list(self): |
| 39 return ['1', '2'] | 41 return ['1', '2'] |
| 40 def getprops(self): | 42 def getprops(self): |
| 41 return {'string': String(), 'date': Date(), 'interval': Interval(), | 43 return {'string': String(), 'date': Date(), 'interval': Interval(), |
| 42 'link': Link('other'), 'multilink': Multilink('other'), | 44 'link': Link('other'), 'multilink': Multilink('other'), |
| 43 'password': Password(), 'html': String(), 'key': String()} | 45 'password': Password(), 'html': String(), 'key': String(), |
| 46 'novalue': String(), 'filename': String()} | |
| 44 def labelprop(self): | 47 def labelprop(self): |
| 45 return 'key' | 48 return 'key' |
| 46 | 49 |
| 47 class Database: | 50 class Database: |
| 48 classes = {'other': Class()} | 51 classes = {'other': Class()} |
| 56 ''' Set up the harness for calling the individual tests | 59 ''' Set up the harness for calling the individual tests |
| 57 ''' | 60 ''' |
| 58 self.tf = tf = TemplateFunctions() | 61 self.tf = tf = TemplateFunctions() |
| 59 tf.nodeid = '1' | 62 tf.nodeid = '1' |
| 60 tf.cl = Class() | 63 tf.cl = Class() |
| 64 tf.classname = 'test_class' | |
| 61 tf.properties = tf.cl.getprops() | 65 tf.properties = tf.cl.getprops() |
| 62 tf.db = Database() | 66 tf.db = Database() |
| 63 | 67 |
| 64 # def do_plain(self, property, escape=0): | 68 # def do_plain(self, property, escape=0): |
| 65 def testPlain_string(self): | 69 def testPlain_string(self): |
| 132 '<input name="multilink" size="30" value="the key,the key">') | 136 '<input name="multilink" size="30" value="the key,the key">') |
| 133 self.assertEqual(self.tf.do_field('multilink', size=10), | 137 self.assertEqual(self.tf.do_field('multilink', size=10), |
| 134 '<input name="multilink" size="10" value="the key,the key">') | 138 '<input name="multilink" size="10" value="the key,the key">') |
| 135 | 139 |
| 136 # def do_menu(self, property, size=None, height=None, showid=0): | 140 # def do_menu(self, property, size=None, height=None, showid=0): |
| 141 def testMenu_nonlinks(self): | |
| 142 self.assertEqual(self.tf.do_menu('string'), _('[Menu: not a link]')) | |
| 143 self.assertEqual(self.tf.do_menu('date'), _('[Menu: not a link]')) | |
| 144 self.assertEqual(self.tf.do_menu('interval'), _('[Menu: not a link]')) | |
| 145 self.assertEqual(self.tf.do_menu('password'), _('[Menu: not a link]')) | |
| 146 | |
| 137 def testMenu_link(self): | 147 def testMenu_link(self): |
| 138 self.assertEqual(self.tf.do_menu('link'), '''<select name="link"> | 148 self.assertEqual(self.tf.do_menu('link'), '''<select name="link"> |
| 139 <option value="-1">- no selection -</option> | 149 <option value="-1">- no selection -</option> |
| 140 <option selected value="1">the key</option> | 150 <option selected value="1">the key</option> |
| 141 <option value="2">the key</option> | 151 <option value="2">the key</option> |
| 168 '''<select multiple name="multilink" size="2"> | 178 '''<select multiple name="multilink" size="2"> |
| 169 <option selected value="1">other1: the key</option> | 179 <option selected value="1">other1: the key</option> |
| 170 <option selected value="2">other2: the key</option> | 180 <option selected value="2">other2: the key</option> |
| 171 </select>''') | 181 </select>''') |
| 172 | 182 |
| 183 # def do_link(self, property=None, is_download=0): | |
| 184 def testLink_novalue(self): | |
| 185 self.assertEqual(self.tf.do_link('novalue'), | |
| 186 _('[no %(propname)s]')%{'propname':'novalue'.capitalize()}) | |
| 187 | |
| 188 def testLink_string(self): | |
| 189 self.assertEqual(self.tf.do_link('string'), | |
| 190 '<a href="test_class1">Node 1: I am a string</a>') | |
| 191 | |
| 192 def testLink_file(self): | |
| 193 self.assertEqual(self.tf.do_link('filename', is_download=1), | |
| 194 '<a href="test_class1/file.foo">file.foo</a>') | |
| 195 | |
| 196 def testLink_date(self): | |
| 197 self.assertEqual(self.tf.do_link('date'), | |
| 198 '<a href="test_class1">2000-01-01.00:00:00</a>') | |
| 199 | |
| 200 def testLink_interval(self): | |
| 201 self.assertEqual(self.tf.do_link('interval'), | |
| 202 '<a href="test_class1">- 3d</a>') | |
| 203 | |
| 204 def testLink_link(self): | |
| 205 self.assertEqual(self.tf.do_link('link'), | |
| 206 '<a href="other1">the key</a>') | |
| 207 | |
| 208 def testLink_multilink(self): | |
| 209 self.assertEqual(self.tf.do_link('multilink'), | |
| 210 '<a href="other1">the key</a>, <a href="other2">the key</a>') | |
| 211 | |
| 173 def suite(): | 212 def suite(): |
| 174 return unittest.makeSuite(NodeCase, 'test') | 213 return unittest.makeSuite(NodeCase, 'test') |
| 175 | 214 |
| 176 | 215 |
| 177 # | 216 # |
| 178 # $Log: not supported by cvs2svn $ | 217 # $Log: not supported by cvs2svn $ |
| 218 # Revision 1.2 2002/01/22 00:12:07 richard | |
| 219 # Wrote more unit tests for htmltemplate, and while I was at it, I polished | |
| 220 # off the implementation of some of the functions so they behave sanely. | |
| 221 # | |
| 179 # Revision 1.1 2002/01/21 11:05:48 richard | 222 # Revision 1.1 2002/01/21 11:05:48 richard |
| 180 # New tests for htmltemplate (well, it's a beginning) | 223 # New tests for htmltemplate (well, it's a beginning) |
| 181 # | 224 # |
| 182 # | 225 # |
| 183 # | 226 # |
