Code

start of CGI form handling tests
[roundup.git] / test / test_cgi.py
1 #
2 # Copyright (c) 2003 Richard Jones, rjones@ekit-inc.com
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 $
13 import unittest, os, shutil, errno, sys, difflib, cgi
15 from roundup.cgi import client
16 from roundup import init, instance
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
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='chef@bork.bork.bork',
42             realname='Bork, Chef', roles='User')
43         self.db.user.create(username='mary', address='mary@test',
44             roles='User', realname='Contrary, Mary')
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
53     def testParseNothing(self):
54         client.parsePropsFromForm(self.db, self.db.issue, makeForm({}))
56     def testParseNothingWithRequired(self):
57         form = makeForm({':required': 'title'})
58         self.assertRaises(ValueError, client.parsePropsFromForm, self.db,
59             self.db.issue, form)
62 def suite():
63     l = [unittest.makeSuite(FormTestCase),
64     ]
65     return unittest.TestSuite(l)
68 # vim: set filetype=python ts=4 sw=4 et si