Mercurial > p > roundup > code
changeset 1377:9ddb3ab23a3f
start of CGI form handling tests
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Tue, 14 Jan 2003 06:15:58 +0000 |
| parents | 0c736e2f1dd5 |
| children | 5d1fe5d51c12 |
| files | test/test_cgi.py |
| diffstat | 1 files changed, 68 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/test_cgi.py Tue Jan 14 06:15:58 2003 +0000 @@ -0,0 +1,68 @@ +# +# Copyright (c) 2003 Richard Jones, rjones@ekit-inc.com +# 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_cgi.py,v 1.1 2003-01-14 06:15:58 richard Exp $ + +import unittest, os, shutil, errno, sys, difflib, cgi + +from roundup.cgi import client +from roundup import init, instance + +def makeForm(args): + form = cgi.FieldStorage() + for k,v in args.items(): + if type(v) is type([]): + form.list.append([cgi.MiniFieldStorage(k, x) for x in v]) + else: + form.list.append(cgi.MiniFieldStorage(k, v)) + return form + +class FormTestCase(unittest.TestCase): + def setUp(self): + self.dirname = '_test_cgi_form' + try: + shutil.rmtree(self.dirname) + except OSError, error: + if error.errno not in (errno.ENOENT, errno.ESRCH): raise + # create the instance + init.install(self.dirname, 'classic', 'anydbm') + init.initialise(self.dirname, 'sekrit') + # check we can load the package + self.instance = instance.open(self.dirname) + # and open the database + self.db = self.instance.open('admin') + self.db.user.create(username='Chef', address='chef@bork.bork.bork', + realname='Bork, Chef', roles='User') + self.db.user.create(username='mary', address='mary@test', + roles='User', realname='Contrary, Mary') + + def tearDown(self): + self.db.close() + try: + shutil.rmtree(self.dirname) + except OSError, error: + if error.errno not in (errno.ENOENT, errno.ESRCH): raise + + def testParseNothing(self): + client.parsePropsFromForm(self.db, self.db.issue, makeForm({})) + + def testParseNothingWithRequired(self): + form = makeForm({':required': 'title'}) + self.assertRaises(ValueError, client.parsePropsFromForm, self.db, + self.db.issue, form) + + +def suite(): + l = [unittest.makeSuite(FormTestCase), + ] + return unittest.TestSuite(l) + + +# vim: set filetype=python ts=4 sw=4 et si
