From: richard Date: Mon, 21 Jan 2002 11:05:48 +0000 (+0000) Subject: New tests for htmltemplate (well, it's a beginning) X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=00d1b4eae89cee6d7c37c094cc23e899351a5a52;p=roundup.git New tests for htmltemplate (well, it's a beginning) git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@573 57a73879-2fb5-44c3-a270-3262357dd7e2 --- diff --git a/test/__init__.py b/test/__init__.py index 006b98a..7501f98 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -15,14 +15,14 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: __init__.py,v 1.12 2002-01-14 06:53:28 richard Exp $ +# $Id: __init__.py,v 1.13 2002-01-21 11:05:48 richard Exp $ import unittest import os, tempfile os.environ['SENDMAILDEBUG'] = tempfile.mktemp() import test_dates, test_schema, test_db, test_multipart, test_mailsplit -import test_init, test_token, test_mailgw +import test_init, test_token, test_mailgw, test_htmltemplate def go(): suite = unittest.TestSuite(( @@ -34,6 +34,7 @@ def go(): test_mailsplit.suite(), test_mailgw.suite(), test_token.suite(), + test_htmltemplate.suite(), )) runner = unittest.TextTestRunner() result = runner.run(suite) @@ -41,6 +42,9 @@ def go(): # # $Log: not supported by cvs2svn $ +# Revision 1.12 2002/01/14 06:53:28 richard +# had commented out some tests +# # Revision 1.11 2002/01/14 02:20:15 richard # . changed all config accesses so they access either the instance or the # config attriubute on the db. This means that all config is obtained from diff --git a/test/test_htmltemplate.py b/test/test_htmltemplate.py new file mode 100644 index 0000000..3765aca --- /dev/null +++ b/test/test_htmltemplate.py @@ -0,0 +1,121 @@ +# +# Copyright (c) 2001 Richard Jones +# This module is free software, and you may redistribute it and/or modify +# under the same terms as Python, so long as this copyright message and +# disclaimer are retained in their original form. +# +# This module is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# +# $Id: test_htmltemplate.py,v 1.1 2002-01-21 11:05:48 richard Exp $ + +import unittest, cgi + +from roundup.htmltemplate import TemplateFunctions +from roundup import date +from roundup.hyperdb import String, 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 == 'date': + return date.Date('2000-01-01') + elif attribute == 'interval': + return date.Interval('-3d') + elif attribute == 'link': + return '1' + elif attribute == 'multilink': + return ['1', '2'] + elif attribute == 'key': + return 'the key' + elif attribute == 'html': + return 'hello, I am HTML' + def list(self): + return ['1', '2'] + def getprops(self): + return {'string': String(), 'date': Date(), 'interval': Interval(), + 'link': Link('other'), 'multilink': Multilink('other'), + 'html': String(), 'key': String()} + def labelprop(self): + return 'key' + +class Database: + classes = {'other': Class()} + def getclass(self, name): + return Class() + def __getattr(self, name): + return Class() + +class NodeCase(unittest.TestCase): + def setUp(self): + ''' Set up the harness for calling the individual tests + ''' + self.tf = tf = TemplateFunctions() + tf.nodeid = '1' + tf.cl = Class() + tf.properties = tf.cl.getprops() + tf.db = Database() + +# def do_plain(self, property, escape=0): + def testPlain_string(self): + s = 'Node 1: I am a string' + self.assertEqual(self.tf.do_plain('string'), s) + + def testPlain_html(self): + s = 'hello, I am HTML' + self.assertEqual(self.tf.do_plain('html', escape=0), s) + s = cgi.escape(s) + self.assertEqual(self.tf.do_plain('html', escape=1), s) + + def testPlain_date(self): + self.assertEqual(self.tf.do_plain('date'), '2000-01-01.00:00:00') + + def testPlain_interval(self): + self.assertEqual(self.tf.do_plain('interval'), '- 3d') + + def testPlain_link(self): + self.assertEqual(self.tf.do_plain('link'), 'the key') + + def testPlain_multilink(self): + self.assertEqual(self.tf.do_plain('multilink'), '1, 2') + + +# def do_field(self, property, size=None, height=None, showid=0): + def testField_string(self): + self.assertEqual(self.tf.do_field('string'), + '') + + def testField_html(self): + self.assertEqual(self.tf.do_field('html'), '') + + def testField_date(self): + self.assertEqual(self.tf.do_field('date'), + '') + + def testField_interval(self): + self.assertEqual(self.tf.do_field('interval'), + '') + + def testField_link(self): + self.assertEqual(self.tf.do_field('link'), '''''') + + def testField_multilink(self): + self.assertEqual(self.tf.do_field('multilink'), + '') + +def suite(): + return unittest.makeSuite(NodeCase, 'test') + + +# +# $Log: not supported by cvs2svn $ +# +# +# vim: set filetype=python ts=4 sw=4 et si