|
| 1 | +# |
| 2 | +# Copyright (c) 2003 Richard Jones, [email protected] |
| 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_cgi.py,v 1.1 2003-01-14 06:15:58 richard Exp $ |
| 12 | + |
| 13 | +import unittest, os, shutil, errno, sys, difflib, cgi |
| 14 | + |
| 15 | +from roundup.cgi import client |
| 16 | +from roundup import init, instance |
| 17 | + |
| 18 | +def makeForm(args): |
| 19 | + form = cgi.FieldStorage() |
| 20 | + for k,v in args.items(): |
| 21 | + if type(v) is type([]): |
| 22 | + form.list.append([cgi.MiniFieldStorage(k, x) for x in v]) |
| 23 | + else: |
| 24 | + form.list.append(cgi.MiniFieldStorage(k, v)) |
| 25 | + return form |
| 26 | + |
| 27 | +class FormTestCase(unittest.TestCase): |
| 28 | + def setUp(self): |
| 29 | + self.dirname = '_test_cgi_form' |
| 30 | + try: |
| 31 | + shutil.rmtree(self.dirname) |
| 32 | + except OSError, error: |
| 33 | + if error.errno not in (errno.ENOENT, errno.ESRCH): raise |
| 34 | + # create the instance |
| 35 | + init.install(self.dirname, 'classic', 'anydbm') |
| 36 | + init.initialise(self.dirname, 'sekrit') |
| 37 | + # check we can load the package |
| 38 | + self.instance = instance.open(self.dirname) |
| 39 | + # and open the database |
| 40 | + self.db = self.instance.open('admin') |
| 41 | + self. db. user. create( username='Chef', address='[email protected]', |
| 42 | + realname='Bork, Chef', roles='User') |
| 43 | + self.db.user.create(username='mary', address='mary@test', |
| 44 | + roles='User', realname='Contrary, Mary') |
| 45 | + |
| 46 | + def tearDown(self): |
| 47 | + self.db.close() |
| 48 | + try: |
| 49 | + shutil.rmtree(self.dirname) |
| 50 | + except OSError, error: |
| 51 | + if error.errno not in (errno.ENOENT, errno.ESRCH): raise |
| 52 | + |
| 53 | + def testParseNothing(self): |
| 54 | + client.parsePropsFromForm(self.db, self.db.issue, makeForm({})) |
| 55 | + |
| 56 | + def testParseNothingWithRequired(self): |
| 57 | + form = makeForm({':required': 'title'}) |
| 58 | + self.assertRaises(ValueError, client.parsePropsFromForm, self.db, |
| 59 | + self.db.issue, form) |
| 60 | + |
| 61 | + |
| 62 | +def suite(): |
| 63 | + l = [unittest.makeSuite(FormTestCase), |
| 64 | + ] |
| 65 | + return unittest.TestSuite(l) |
| 66 | + |
| 67 | + |
| 68 | +# vim: set filetype=python ts=4 sw=4 et si |
0 commit comments