Mercurial > p > roundup > code
comparison test/test_htmltemplate.py @ 577:334ae707ebfc
more HTML template cleanup and unit tests
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Wed, 23 Jan 2002 05:47:57 +0000 |
| parents | f98f37697f4c |
| children | 50fcb1357967 |
comparison
equal
deleted
inserted
replaced
| 576:f98f37697f4c | 577:334ae707ebfc |
|---|---|
| 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.5 2002-01-23 05:10:28 richard Exp $ | 11 # $Id: test_htmltemplate.py,v 1.6 2002-01-23 05:47:57 richard Exp $ |
| 12 | 12 |
| 13 import unittest, cgi | 13 import unittest, cgi |
| 14 | 14 |
| 15 from roundup import date, password | 15 from roundup import date, password |
| 16 from roundup.htmltemplate import TemplateFunctions | 16 from roundup.htmltemplate import TemplateFunctions |
| 32 elif attribute == 'multilink': | 32 elif attribute == 'multilink': |
| 33 return ['1', '2'] | 33 return ['1', '2'] |
| 34 elif attribute == 'password': | 34 elif attribute == 'password': |
| 35 return password.Password('sekrit') | 35 return password.Password('sekrit') |
| 36 elif attribute == 'key': | 36 elif attribute == 'key': |
| 37 return 'the key' | 37 return 'the key'+nodeid |
| 38 elif attribute == 'html': | 38 elif attribute == 'html': |
| 39 return '<html>hello, I am HTML</html>' | 39 return '<html>hello, I am HTML</html>' |
| 40 def list(self): | 40 def list(self): |
| 41 return ['1', '2'] | 41 return ['1', '2'] |
| 42 def getprops(self): | 42 def getprops(self): |
| 52 def getclass(self, name): | 52 def getclass(self, name): |
| 53 return Class() | 53 return Class() |
| 54 def __getattr(self, name): | 54 def __getattr(self, name): |
| 55 return Class() | 55 return Class() |
| 56 | 56 |
| 57 class Client: | |
| 58 write = None | |
| 59 | |
| 57 class NodeCase(unittest.TestCase): | 60 class NodeCase(unittest.TestCase): |
| 58 def setUp(self): | 61 def setUp(self): |
| 59 ''' Set up the harness for calling the individual tests | 62 ''' Set up the harness for calling the individual tests |
| 60 ''' | 63 ''' |
| 61 self.tf = tf = TemplateFunctions() | 64 self.tf = tf = TemplateFunctions() |
| 84 | 87 |
| 85 def testPlain_interval(self): | 88 def testPlain_interval(self): |
| 86 self.assertEqual(self.tf.do_plain('interval'), '- 3d') | 89 self.assertEqual(self.tf.do_plain('interval'), '- 3d') |
| 87 | 90 |
| 88 def testPlain_link(self): | 91 def testPlain_link(self): |
| 89 self.assertEqual(self.tf.do_plain('link'), 'the key') | 92 self.assertEqual(self.tf.do_plain('link'), 'the key1') |
| 90 | 93 |
| 91 def testPlain_multilink(self): | 94 def testPlain_multilink(self): |
| 92 self.assertEqual(self.tf.do_plain('multilink'), '1, 2') | 95 self.assertEqual(self.tf.do_plain('multilink'), '1, 2') |
| 93 | 96 |
| 94 | 97 |
| 125 '<input name="interval" value="- 3d" size="10">') | 128 '<input name="interval" value="- 3d" size="10">') |
| 126 | 129 |
| 127 def testField_link(self): | 130 def testField_link(self): |
| 128 self.assertEqual(self.tf.do_field('link'), '''<select name="link"> | 131 self.assertEqual(self.tf.do_field('link'), '''<select name="link"> |
| 129 <option value="-1">- no selection -</option> | 132 <option value="-1">- no selection -</option> |
| 130 <option selected value="1">the key</option> | 133 <option selected value="1">the key1</option> |
| 131 <option value="2">the key</option> | 134 <option value="2">the key2</option> |
| 132 </select>''') | 135 </select>''') |
| 133 | 136 |
| 134 def testField_multilink(self): | 137 def testField_multilink(self): |
| 135 self.assertEqual(self.tf.do_field('multilink'), | 138 self.assertEqual(self.tf.do_field('multilink'), |
| 136 '<input name="multilink" size="30" value="the key,the key">') | 139 '<input name="multilink" size="30" value="the key1,the key2">') |
| 137 self.assertEqual(self.tf.do_field('multilink', size=10), | 140 self.assertEqual(self.tf.do_field('multilink', size=10), |
| 138 '<input name="multilink" size="10" value="the key,the key">') | 141 '<input name="multilink" size="10" value="the key1,the key2">') |
| 139 | 142 |
| 140 # def do_menu(self, property, size=None, height=None, showid=0): | 143 # def do_menu(self, property, size=None, height=None, showid=0): |
| 141 def testMenu_nonlinks(self): | 144 def testMenu_nonlinks(self): |
| 142 s = _('[Menu: not a link]') | 145 s = _('[Menu: not a link]') |
| 143 self.assertEqual(self.tf.do_menu('string'), s) | 146 self.assertEqual(self.tf.do_menu('string'), s) |
| 146 self.assertEqual(self.tf.do_menu('password'), s) | 149 self.assertEqual(self.tf.do_menu('password'), s) |
| 147 | 150 |
| 148 def testMenu_link(self): | 151 def testMenu_link(self): |
| 149 self.assertEqual(self.tf.do_menu('link'), '''<select name="link"> | 152 self.assertEqual(self.tf.do_menu('link'), '''<select name="link"> |
| 150 <option value="-1">- no selection -</option> | 153 <option value="-1">- no selection -</option> |
| 151 <option selected value="1">the key</option> | 154 <option selected value="1">the key1</option> |
| 152 <option value="2">the key</option> | 155 <option value="2">the key2</option> |
| 153 </select>''') | 156 </select>''') |
| 154 self.assertEqual(self.tf.do_menu('link', size=6), | 157 self.assertEqual(self.tf.do_menu('link', size=6), |
| 155 '''<select name="link"> | 158 '''<select name="link"> |
| 156 <option value="-1">- no selection -</option> | 159 <option value="-1">- no selection -</option> |
| 157 <option selected value="1">the...</option> | 160 <option selected value="1">the...</option> |
| 158 <option value="2">the...</option> | 161 <option value="2">the...</option> |
| 159 </select>''') | 162 </select>''') |
| 160 self.assertEqual(self.tf.do_menu('link', showid=1), | 163 self.assertEqual(self.tf.do_menu('link', showid=1), |
| 161 '''<select name="link"> | 164 '''<select name="link"> |
| 162 <option value="-1">- no selection -</option> | 165 <option value="-1">- no selection -</option> |
| 163 <option selected value="1">other1: the key</option> | 166 <option selected value="1">other1: the key1</option> |
| 164 <option value="2">other2: the key</option> | 167 <option value="2">other2: the key2</option> |
| 165 </select>''') | 168 </select>''') |
| 166 | 169 |
| 167 def testMenu_multilink(self): | 170 def testMenu_multilink(self): |
| 168 self.assertEqual(self.tf.do_menu('multilink', height=10), | 171 self.assertEqual(self.tf.do_menu('multilink', height=10), |
| 169 '''<select multiple name="multilink" size="10"> | 172 '''<select multiple name="multilink" size="10"> |
| 170 <option selected value="1">the key</option> | 173 <option selected value="1">the key1</option> |
| 171 <option selected value="2">the key</option> | 174 <option selected value="2">the key2</option> |
| 172 </select>''') | 175 </select>''') |
| 173 self.assertEqual(self.tf.do_menu('multilink', size=6, height=10), | 176 self.assertEqual(self.tf.do_menu('multilink', size=6, height=10), |
| 174 '''<select multiple name="multilink" size="10"> | 177 '''<select multiple name="multilink" size="10"> |
| 175 <option selected value="1">the...</option> | 178 <option selected value="1">the...</option> |
| 176 <option selected value="2">the...</option> | 179 <option selected value="2">the...</option> |
| 177 </select>''') | 180 </select>''') |
| 178 self.assertEqual(self.tf.do_menu('multilink', showid=1), | 181 self.assertEqual(self.tf.do_menu('multilink', showid=1), |
| 179 '''<select multiple name="multilink" size="2"> | 182 '''<select multiple name="multilink" size="2"> |
| 180 <option selected value="1">other1: the key</option> | 183 <option selected value="1">other1: the key1</option> |
| 181 <option selected value="2">other2: the key</option> | 184 <option selected value="2">other2: the key2</option> |
| 182 </select>''') | 185 </select>''') |
| 183 | 186 |
| 184 # def do_link(self, property=None, is_download=0): | 187 # def do_link(self, property=None, is_download=0): |
| 185 def testLink_novalue(self): | 188 def testLink_novalue(self): |
| 186 self.assertEqual(self.tf.do_link('novalue'), | 189 self.assertEqual(self.tf.do_link('novalue'), |
| 202 self.assertEqual(self.tf.do_link('interval'), | 205 self.assertEqual(self.tf.do_link('interval'), |
| 203 '<a href="test_class1">- 3d</a>') | 206 '<a href="test_class1">- 3d</a>') |
| 204 | 207 |
| 205 def testLink_link(self): | 208 def testLink_link(self): |
| 206 self.assertEqual(self.tf.do_link('link'), | 209 self.assertEqual(self.tf.do_link('link'), |
| 207 '<a href="other1">the key</a>') | 210 '<a href="other1">the key1</a>') |
| 208 | 211 |
| 209 def testLink_multilink(self): | 212 def testLink_multilink(self): |
| 210 self.assertEqual(self.tf.do_link('multilink'), | 213 self.assertEqual(self.tf.do_link('multilink'), |
| 211 '<a href="other1">the key</a>, <a href="other2">the key</a>') | 214 '<a href="other1">the key1</a>, <a href="other2">the key2</a>') |
| 212 | 215 |
| 213 # def do_count(self, property, **args): | 216 # def do_count(self, property, **args): |
| 214 def testCount_nonlinks(self): | 217 def testCount_nonlinks(self): |
| 215 s = _('[Count: not a Multilink]') | 218 s = _('[Count: not a Multilink]') |
| 216 self.assertEqual(self.tf.do_count('string'), s) | 219 self.assertEqual(self.tf.do_count('string'), s) |
| 258 self.assertEqual(self.tf.do_download('interval'), | 261 self.assertEqual(self.tf.do_download('interval'), |
| 259 '<a href="test_class1/- 3d">- 3d</a>') | 262 '<a href="test_class1/- 3d">- 3d</a>') |
| 260 | 263 |
| 261 def testDownload_link(self): | 264 def testDownload_link(self): |
| 262 self.assertEqual(self.tf.do_download('link'), | 265 self.assertEqual(self.tf.do_download('link'), |
| 263 '<a href="other1/the key">the key</a>') | 266 '<a href="other1/the key1">the key1</a>') |
| 264 | 267 |
| 265 def testDownload_multilink(self): | 268 def testDownload_multilink(self): |
| 266 self.assertEqual(self.tf.do_download('multilink'), | 269 self.assertEqual(self.tf.do_download('multilink'), |
| 267 '<a href="other1/the key">the key</a>, ' | 270 '<a href="other1/the key1">the key1</a>, ' |
| 268 '<a href="other2/the key">the key</a>') | 271 '<a href="other2/the key2">the key2</a>') |
| 272 | |
| 273 # def do_checklist(self, property, reverse=0): | |
| 274 def testChecklink_nonlinks(self): | |
| 275 s = _('[Checklist: not a link]') | |
| 276 self.assertEqual(self.tf.do_checklist('string'), s) | |
| 277 self.assertEqual(self.tf.do_checklist('date'), s) | |
| 278 self.assertEqual(self.tf.do_checklist('interval'), s) | |
| 279 self.assertEqual(self.tf.do_checklist('password'), s) | |
| 280 | |
| 281 def testChecklink_link(self): | |
| 282 self.assertEqual(self.tf.do_checklist('link'), | |
| 283 '''the key1:<input type="checkbox" checked name="link" value="the key1"> | |
| 284 the key2:<input type="checkbox" name="link" value="the key2"> | |
| 285 [unselected]:<input type="checkbox" name="link" value="-1">''') | |
| 286 | |
| 287 def testChecklink_multilink(self): | |
| 288 self.assertEqual(self.tf.do_checklist('multilink'), | |
| 289 '''the key1:<input type="checkbox" checked name="multilink" value="the key1"> | |
| 290 the key2:<input type="checkbox" checked name="multilink" value="the key2">''') | |
| 291 | |
| 292 # def do_note(self, rows=5, cols=80): | |
| 293 def testNote(self): | |
| 294 self.assertEqual(self.tf.do_note(), '<textarea name="__note" ' | |
| 295 'wrap="hard" rows=5 cols=80></textarea>') | |
| 296 | |
| 297 # def do_list(self, property, reverse=0): | |
| 298 def testList_nonlinks(self): | |
| 299 s = _('[List: not a Multilink]') | |
| 300 self.assertEqual(self.tf.do_list('string'), s) | |
| 301 self.assertEqual(self.tf.do_list('date'), s) | |
| 302 self.assertEqual(self.tf.do_list('interval'), s) | |
| 303 self.assertEqual(self.tf.do_list('password'), s) | |
| 304 self.assertEqual(self.tf.do_list('link'), s) | |
| 305 | |
| 306 def testList_multilink(self): | |
| 307 # TODO: test this (needs to have lots and lots of support! | |
| 308 #self.assertEqual(self.tf.do_list('multilink'),'') | |
| 309 pass | |
| 269 | 310 |
| 270 def suite(): | 311 def suite(): |
| 271 return unittest.makeSuite(NodeCase, 'test') | 312 return unittest.makeSuite(NodeCase, 'test') |
| 272 | 313 |
| 273 | 314 |
| 274 # | 315 # |
| 275 # $Log: not supported by cvs2svn $ | 316 # $Log: not supported by cvs2svn $ |
| 317 # Revision 1.5 2002/01/23 05:10:28 richard | |
| 318 # More HTML template cleanup and unit tests. | |
| 319 # - download() now implemented correctly, replacing link(is_download=1) [fixed in the | |
| 320 # templates, but link(is_download=1) will still work for existing templates] | |
| 321 # | |
| 276 # Revision 1.4 2002/01/22 22:46:22 richard | 322 # Revision 1.4 2002/01/22 22:46:22 richard |
| 277 # more htmltemplate cleanups and unit tests | 323 # more htmltemplate cleanups and unit tests |
| 278 # | 324 # |
| 279 # Revision 1.3 2002/01/22 06:35:40 richard | 325 # Revision 1.3 2002/01/22 06:35:40 richard |
| 280 # more htmltemplate tests and cleanup | 326 # more htmltemplate tests and cleanup |
