|
| 1 | +# |
| 2 | +# Copyright (c) 2001 Richard Jones |
| 3 | +# This module is free software, and you may redistribute it and/or modify |
| 4 | +# under the same terms as Python, so long as this copyright message and |
| 5 | +# disclaimer are retained in their original form. |
| 6 | +# |
| 7 | +# This module is distributed in the hope that it will be useful, |
| 8 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 10 | +# |
| 11 | +# $Id: test_htmltemplate.py,v 1.1 2002-01-21 11:05:48 richard Exp $ |
| 12 | + |
| 13 | +import unittest, cgi |
| 14 | + |
| 15 | +from roundup.htmltemplate import TemplateFunctions |
| 16 | +from roundup import date |
| 17 | +from roundup.hyperdb import String, Date, Interval, Link, Multilink |
| 18 | + |
| 19 | +class Class: |
| 20 | + def get(self, nodeid, attribute, default=None): |
| 21 | + if attribute == 'string': |
| 22 | + return 'Node %s: I am a string'%nodeid |
| 23 | + elif attribute == 'date': |
| 24 | + return date.Date('2000-01-01') |
| 25 | + elif attribute == 'interval': |
| 26 | + return date.Interval('-3d') |
| 27 | + elif attribute == 'link': |
| 28 | + return '1' |
| 29 | + elif attribute == 'multilink': |
| 30 | + return ['1', '2'] |
| 31 | + elif attribute == 'key': |
| 32 | + return 'the key' |
| 33 | + elif attribute == 'html': |
| 34 | + return '<html>hello, I am HTML</html>' |
| 35 | + def list(self): |
| 36 | + return ['1', '2'] |
| 37 | + def getprops(self): |
| 38 | + return {'string': String(), 'date': Date(), 'interval': Interval(), |
| 39 | + 'link': Link('other'), 'multilink': Multilink('other'), |
| 40 | + 'html': String(), 'key': String()} |
| 41 | + def labelprop(self): |
| 42 | + return 'key' |
| 43 | + |
| 44 | +class Database: |
| 45 | + classes = {'other': Class()} |
| 46 | + def getclass(self, name): |
| 47 | + return Class() |
| 48 | + def __getattr(self, name): |
| 49 | + return Class() |
| 50 | + |
| 51 | +class NodeCase(unittest.TestCase): |
| 52 | + def setUp(self): |
| 53 | + ''' Set up the harness for calling the individual tests |
| 54 | + ''' |
| 55 | + self.tf = tf = TemplateFunctions() |
| 56 | + tf.nodeid = '1' |
| 57 | + tf.cl = Class() |
| 58 | + tf.properties = tf.cl.getprops() |
| 59 | + tf.db = Database() |
| 60 | + |
| 61 | +# def do_plain(self, property, escape=0): |
| 62 | + def testPlain_string(self): |
| 63 | + s = 'Node 1: I am a string' |
| 64 | + self.assertEqual(self.tf.do_plain('string'), s) |
| 65 | + |
| 66 | + def testPlain_html(self): |
| 67 | + s = '<html>hello, I am HTML</html>' |
| 68 | + self.assertEqual(self.tf.do_plain('html', escape=0), s) |
| 69 | + s = cgi.escape(s) |
| 70 | + self.assertEqual(self.tf.do_plain('html', escape=1), s) |
| 71 | + |
| 72 | + def testPlain_date(self): |
| 73 | + self.assertEqual(self.tf.do_plain('date'), '2000-01-01.00:00:00') |
| 74 | + |
| 75 | + def testPlain_interval(self): |
| 76 | + self.assertEqual(self.tf.do_plain('interval'), '- 3d') |
| 77 | + |
| 78 | + def testPlain_link(self): |
| 79 | + self.assertEqual(self.tf.do_plain('link'), 'the key') |
| 80 | + |
| 81 | + def testPlain_multilink(self): |
| 82 | + self.assertEqual(self.tf.do_plain('multilink'), '1, 2') |
| 83 | + |
| 84 | + |
| 85 | +# def do_field(self, property, size=None, height=None, showid=0): |
| 86 | + def testField_string(self): |
| 87 | + self.assertEqual(self.tf.do_field('string'), |
| 88 | + '<input name="string" value="Node 1: I am a string" size="30">') |
| 89 | + |
| 90 | + def testField_html(self): |
| 91 | + self.assertEqual(self.tf.do_field('html'), '<input name="html" ' |
| 92 | + 'value="<html>hello, I am HTML</html>" size="30">') |
| 93 | + |
| 94 | + def testField_date(self): |
| 95 | + self.assertEqual(self.tf.do_field('date'), |
| 96 | + '<input name="date" value="2000-01-01.00:00:00" size="30">') |
| 97 | + |
| 98 | + def testField_interval(self): |
| 99 | + self.assertEqual(self.tf.do_field('interval'), |
| 100 | + '<input name="interval" value="- 3d" size="30">') |
| 101 | + |
| 102 | + def testField_link(self): |
| 103 | + self.assertEqual(self.tf.do_field('link'), '''<select name="link"> |
| 104 | +<option value="-1">- no selection -</option> |
| 105 | +<option selected value="1">the key</option> |
| 106 | +<option value="2">the key</option> |
| 107 | +</select>''') |
| 108 | + |
| 109 | + def testField_multilink(self): |
| 110 | + self.assertEqual(self.tf.do_field('multilink'), |
| 111 | + '<input name="multilink" size="10" value="the key,the key">') |
| 112 | + |
| 113 | +def suite(): |
| 114 | + return unittest.makeSuite(NodeCase, 'test') |
| 115 | + |
| 116 | + |
| 117 | +# |
| 118 | +# $Log: not supported by cvs2svn $ |
| 119 | +# |
| 120 | +# |
| 121 | +# vim: set filetype=python ts=4 sw=4 et si |
0 commit comments