Premiere version : mise en route du suivi.
[auf_roundup.git] / test / test_schema.py
1 #
2 # Copyright (c) 2001 Bizar Software Pty Ltd (http://www.bizarsoftware.com.au/)
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 # IN NO EVENT SHALL BIZAR SOFTWARE PTY LTD BE LIABLE TO ANY PARTY FOR
8 # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
9 # OUT OF THE USE OF THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE
10 # POSSIBILITY OF SUCH DAMAGE.
11 #
12 # BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
17 #
18 # $Id: test_schema.py,v 1.15 2004-10-16 12:43:11 a1s Exp $
19
20 import unittest, os, shutil
21
22 from roundup import configuration
23 from roundup.backends import back_anydbm
24 from roundup.hyperdb import String, Password, Link, Multilink, Date, \
25 Interval
26
27 config = configuration.CoreConfig()
28 config.DATABASE = "_test_dir"
29
30 class SchemaTestCase(unittest.TestCase):
31 def setUp(self):
32 # remove previous test, ignore errors
33 if os.path.exists(config.DATABASE):
34 shutil.rmtree(config.DATABASE)
35 os.makedirs(config.DATABASE + '/files')
36 self.db = back_anydbm.Database(config, 'admin')
37 self.db.post_init()
38 self.db.clear()
39
40 def tearDown(self):
41 self.db.close()
42 shutil.rmtree(config.DATABASE)
43
44 def testA_Status(self):
45 status = back_anydbm.Class(self.db, "status", name=String())
46 self.assert_(status, 'no class object generated')
47 status.setkey("name")
48 val = status.create(name="unread")
49 self.assertEqual(val, '1', 'expecting "1"')
50 val = status.create(name="in-progress")
51 self.assertEqual(val, '2', 'expecting "2"')
52 val = status.create(name="testing")
53 self.assertEqual(val, '3', 'expecting "3"')
54 val = status.create(name="resolved")
55 self.assertEqual(val, '4', 'expecting "4"')
56 val = status.count()
57 self.assertEqual(val, 4, 'expecting 4')
58 val = status.list()
59 self.assertEqual(val, ['1', '2', '3', '4'], 'blah')
60 val = status.lookup("in-progress")
61 self.assertEqual(val, '2', 'expecting "2"')
62 status.retire('3')
63 val = status.list()
64 self.assertEqual(val, ['1', '2', '4'], 'blah')
65
66 def testB_Issue(self):
67 issue = back_anydbm.Class(self.db, "issue", title=String(),
68 status=Link("status"))
69 self.assert_(issue, 'no class object returned')
70
71 def testC_User(self):
72 user = back_anydbm.Class(self.db, "user", username=String(),
73 password=Password())
74 self.assert_(user, 'no class object returned')
75 user.setkey("username")
76
77
78 def test_suite():
79 suite = unittest.TestSuite()
80 suite.addTest(unittest.makeSuite(SchemaTestCase))
81 return suite
82
83 if __name__ == '__main__':
84 runner = unittest.TextTestRunner()
85 unittest.main(testRunner=runner)
86
87
88 # vim: set filetype=python sts=4 sw=4 et si :