Mercurial > p > roundup > code
comparison test/test_htmltemplate.py @ 563:0f58d6a35a8b
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.
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Tue, 22 Jan 2002 00:12:07 +0000 |
| parents | 13df980755fa |
| children | c7ead967db85 |
comparison
equal
deleted
inserted
replaced
| 562:62febbd7ffec | 563:0f58d6a35a8b |
|---|---|
| 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.1 2002-01-21 11:05:48 richard Exp $ | 11 # $Id: test_htmltemplate.py,v 1.2 2002-01-22 00:12:07 richard Exp $ |
| 12 | 12 |
| 13 import unittest, cgi | 13 import unittest, cgi |
| 14 | 14 |
| 15 from roundup.htmltemplate import TemplateFunctions | 15 from roundup.htmltemplate import TemplateFunctions |
| 16 from roundup import date | 16 from roundup import date |
| 17 from roundup.hyperdb import String, Date, Interval, Link, Multilink | 17 from roundup import password |
| 18 from roundup.hyperdb import String, Password, Date, Interval, Link, Multilink | |
| 18 | 19 |
| 19 class Class: | 20 class Class: |
| 20 def get(self, nodeid, attribute, default=None): | 21 def get(self, nodeid, attribute, default=None): |
| 21 if attribute == 'string': | 22 if attribute == 'string': |
| 22 return 'Node %s: I am a string'%nodeid | 23 return 'Node %s: I am a string'%nodeid |
| 26 return date.Interval('-3d') | 27 return date.Interval('-3d') |
| 27 elif attribute == 'link': | 28 elif attribute == 'link': |
| 28 return '1' | 29 return '1' |
| 29 elif attribute == 'multilink': | 30 elif attribute == 'multilink': |
| 30 return ['1', '2'] | 31 return ['1', '2'] |
| 32 elif attribute == 'password': | |
| 33 return password.Password('sekrit') | |
| 31 elif attribute == 'key': | 34 elif attribute == 'key': |
| 32 return 'the key' | 35 return 'the key' |
| 33 elif attribute == 'html': | 36 elif attribute == 'html': |
| 34 return '<html>hello, I am HTML</html>' | 37 return '<html>hello, I am HTML</html>' |
| 35 def list(self): | 38 def list(self): |
| 36 return ['1', '2'] | 39 return ['1', '2'] |
| 37 def getprops(self): | 40 def getprops(self): |
| 38 return {'string': String(), 'date': Date(), 'interval': Interval(), | 41 return {'string': String(), 'date': Date(), 'interval': Interval(), |
| 39 'link': Link('other'), 'multilink': Multilink('other'), | 42 'link': Link('other'), 'multilink': Multilink('other'), |
| 40 'html': String(), 'key': String()} | 43 'password': Password(), 'html': String(), 'key': String()} |
| 41 def labelprop(self): | 44 def labelprop(self): |
| 42 return 'key' | 45 return 'key' |
| 43 | 46 |
| 44 class Database: | 47 class Database: |
| 45 classes = {'other': Class()} | 48 classes = {'other': Class()} |
| 61 # def do_plain(self, property, escape=0): | 64 # def do_plain(self, property, escape=0): |
| 62 def testPlain_string(self): | 65 def testPlain_string(self): |
| 63 s = 'Node 1: I am a string' | 66 s = 'Node 1: I am a string' |
| 64 self.assertEqual(self.tf.do_plain('string'), s) | 67 self.assertEqual(self.tf.do_plain('string'), s) |
| 65 | 68 |
| 69 def testPlain_password(self): | |
| 70 self.assertEqual(self.tf.do_plain('password'), '*encrypted*') | |
| 71 | |
| 66 def testPlain_html(self): | 72 def testPlain_html(self): |
| 67 s = '<html>hello, I am HTML</html>' | 73 s = '<html>hello, I am HTML</html>' |
| 68 self.assertEqual(self.tf.do_plain('html', escape=0), s) | 74 self.assertEqual(self.tf.do_plain('html', escape=0), s) |
| 69 s = cgi.escape(s) | 75 s = cgi.escape(s) |
| 70 self.assertEqual(self.tf.do_plain('html', escape=1), s) | 76 self.assertEqual(self.tf.do_plain('html', escape=1), s) |
| 80 | 86 |
| 81 def testPlain_multilink(self): | 87 def testPlain_multilink(self): |
| 82 self.assertEqual(self.tf.do_plain('multilink'), '1, 2') | 88 self.assertEqual(self.tf.do_plain('multilink'), '1, 2') |
| 83 | 89 |
| 84 | 90 |
| 85 # def do_field(self, property, size=None, height=None, showid=0): | 91 # def do_field(self, property, size=None, showid=0): |
| 86 def testField_string(self): | 92 def testField_string(self): |
| 87 self.assertEqual(self.tf.do_field('string'), | 93 self.assertEqual(self.tf.do_field('string'), |
| 88 '<input name="string" value="Node 1: I am a string" size="30">') | 94 '<input name="string" value="Node 1: I am a string" size="30">') |
| 95 self.assertEqual(self.tf.do_field('string', size=10), | |
| 96 '<input name="string" value="Node 1: I am a string" size="10">') | |
| 97 | |
| 98 def testField_password(self): | |
| 99 self.assertEqual(self.tf.do_field('password'), | |
| 100 '<input type="password" name="password" size="30">') | |
| 101 self.assertEqual(self.tf.do_field('password', size=10), | |
| 102 '<input type="password" name="password" size="10">') | |
| 89 | 103 |
| 90 def testField_html(self): | 104 def testField_html(self): |
| 91 self.assertEqual(self.tf.do_field('html'), '<input name="html" ' | 105 self.assertEqual(self.tf.do_field('html'), '<input name="html" ' |
| 92 'value="<html>hello, I am HTML</html>" size="30">') | 106 'value="<html>hello, I am HTML</html>" size="30">') |
| 107 self.assertEqual(self.tf.do_field('html', size=10), | |
| 108 '<input name="html" value="<html>hello, I am ' | |
| 109 'HTML</html>" size="10">') | |
| 93 | 110 |
| 94 def testField_date(self): | 111 def testField_date(self): |
| 95 self.assertEqual(self.tf.do_field('date'), | 112 self.assertEqual(self.tf.do_field('date'), |
| 96 '<input name="date" value="2000-01-01.00:00:00" size="30">') | 113 '<input name="date" value="2000-01-01.00:00:00" size="30">') |
| 114 self.assertEqual(self.tf.do_field('date', size=10), | |
| 115 '<input name="date" value="2000-01-01.00:00:00" size="10">') | |
| 97 | 116 |
| 98 def testField_interval(self): | 117 def testField_interval(self): |
| 99 self.assertEqual(self.tf.do_field('interval'), | 118 self.assertEqual(self.tf.do_field('interval'), |
| 100 '<input name="interval" value="- 3d" size="30">') | 119 '<input name="interval" value="- 3d" size="30">') |
| 120 self.assertEqual(self.tf.do_field('interval', size=10), | |
| 121 '<input name="interval" value="- 3d" size="10">') | |
| 101 | 122 |
| 102 def testField_link(self): | 123 def testField_link(self): |
| 103 self.assertEqual(self.tf.do_field('link'), '''<select name="link"> | 124 self.assertEqual(self.tf.do_field('link'), '''<select name="link"> |
| 104 <option value="-1">- no selection -</option> | 125 <option value="-1">- no selection -</option> |
| 105 <option selected value="1">the key</option> | 126 <option selected value="1">the key</option> |
| 106 <option value="2">the key</option> | 127 <option value="2">the key</option> |
| 107 </select>''') | 128 </select>''') |
| 108 | 129 |
| 109 def testField_multilink(self): | 130 def testField_multilink(self): |
| 110 self.assertEqual(self.tf.do_field('multilink'), | 131 self.assertEqual(self.tf.do_field('multilink'), |
| 132 '<input name="multilink" size="30" value="the key,the key">') | |
| 133 self.assertEqual(self.tf.do_field('multilink', size=10), | |
| 111 '<input name="multilink" size="10" value="the key,the key">') | 134 '<input name="multilink" size="10" value="the key,the key">') |
| 135 | |
| 136 # def do_menu(self, property, size=None, height=None, showid=0): | |
| 137 def testMenu_link(self): | |
| 138 self.assertEqual(self.tf.do_menu('link'), '''<select name="link"> | |
| 139 <option value="-1">- no selection -</option> | |
| 140 <option selected value="1">the key</option> | |
| 141 <option value="2">the key</option> | |
| 142 </select>''') | |
| 143 self.assertEqual(self.tf.do_menu('link', size=6), | |
| 144 '''<select name="link"> | |
| 145 <option value="-1">- no selection -</option> | |
| 146 <option selected value="1">the...</option> | |
| 147 <option value="2">the...</option> | |
| 148 </select>''') | |
| 149 self.assertEqual(self.tf.do_menu('link', showid=1), | |
| 150 '''<select name="link"> | |
| 151 <option value="-1">- no selection -</option> | |
| 152 <option selected value="1">other1: the key</option> | |
| 153 <option value="2">other2: the key</option> | |
| 154 </select>''') | |
| 155 | |
| 156 def testMenu_multilink(self): | |
| 157 self.assertEqual(self.tf.do_menu('multilink', height=10), | |
| 158 '''<select multiple name="multilink" size="10"> | |
| 159 <option selected value="1">the key</option> | |
| 160 <option selected value="2">the key</option> | |
| 161 </select>''') | |
| 162 self.assertEqual(self.tf.do_menu('multilink', size=6, height=10), | |
| 163 '''<select multiple name="multilink" size="10"> | |
| 164 <option selected value="1">the...</option> | |
| 165 <option selected value="2">the...</option> | |
| 166 </select>''') | |
| 167 self.assertEqual(self.tf.do_menu('multilink', showid=1), | |
| 168 '''<select multiple name="multilink" size="2"> | |
| 169 <option selected value="1">other1: the key</option> | |
| 170 <option selected value="2">other2: the key</option> | |
| 171 </select>''') | |
| 112 | 172 |
| 113 def suite(): | 173 def suite(): |
| 114 return unittest.makeSuite(NodeCase, 'test') | 174 return unittest.makeSuite(NodeCase, 'test') |
| 115 | 175 |
| 116 | 176 |
| 117 # | 177 # |
| 118 # $Log: not supported by cvs2svn $ | 178 # $Log: not supported by cvs2svn $ |
| 179 # Revision 1.1 2002/01/21 11:05:48 richard | |
| 180 # New tests for htmltemplate (well, it's a beginning) | |
| 181 # | |
| 119 # | 182 # |
| 120 # | 183 # |
| 121 # vim: set filetype=python ts=4 sw=4 et si | 184 # vim: set filetype=python ts=4 sw=4 et si |
