Code

start of CGI form handling tests
authorrichard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2>
Tue, 14 Jan 2003 06:15:58 +0000 (06:15 +0000)
committerrichard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2>
Tue, 14 Jan 2003 06:15:58 +0000 (06:15 +0000)
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1453 57a73879-2fb5-44c3-a270-3262357dd7e2

test/test_cgi.py [new file with mode: 0644]

diff --git a/test/test_cgi.py b/test/test_cgi.py
new file mode 100644 (file)
index 0000000..857d41d
--- /dev/null
@@ -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