Premiere version : mise en route du suivi.
[auf_roundup.git] / test / .svn / text-base / test_xmlrpc.py.svn-base
CommitLineData
c638d827
CR
1#
2# Copyright (C) 2007 Stefan Seefeld
3# All rights reserved.
4# For license terms see the file COPYING.txt.
5#
6
7import unittest, os, shutil, errno, sys, difflib, cgi, re
8
9from roundup.cgi.exceptions import *
10from roundup import init, instance, password, hyperdb, date
11from roundup.xmlrpc import RoundupInstance
12from roundup.backends import list_backends
13
14import db_test_base
15
16NEEDS_INSTANCE = 1
17
18class TestCase(unittest.TestCase):
19
20 backend = None
21
22 def setUp(self):
23 self.dirname = '_test_xmlrpc'
24 # set up and open a tracker
25 self.instance = db_test_base.setupTracker(self.dirname, self.backend)
26
27 # open the database
28 self.db = self.instance.open('admin')
29 self.joeid = 'user' + self.db.user.create(username='joe',
30 password=password.Password('random'), address='random@home.org',
31 realname='Joe Random', roles='User')
32
33 self.db.commit()
34 self.db.close()
35 self.db = self.instance.open('joe')
36 self.server = RoundupInstance(self.db, self.instance.actions, None)
37
38 def tearDown(self):
39 self.db.close()
40 try:
41 shutil.rmtree(self.dirname)
42 except OSError, error:
43 if error.errno not in (errno.ENOENT, errno.ESRCH): raise
44
45 def testAccess(self):
46 # Retrieve all three users.
47 results = self.server.list('user', 'id')
48 self.assertEqual(len(results), 3)
49
50 # Obtain data for 'joe'.
51 results = self.server.display(self.joeid)
52 self.assertEqual(results['username'], 'joe')
53 self.assertEqual(results['realname'], 'Joe Random')
54
55 def testChange(self):
56 # Reset joe's 'realname'.
57 results = self.server.set(self.joeid, 'realname=Joe Doe')
58 results = self.server.display(self.joeid, 'realname')
59 self.assertEqual(results['realname'], 'Joe Doe')
60
61 # check we can't change admin's details
62 self.assertRaises(Unauthorised, self.server.set, 'user1', 'realname=Joe Doe')
63
64 def testCreate(self):
65 results = self.server.create('issue', 'title=foo')
66 issueid = 'issue' + results
67 results = self.server.display(issueid, 'title')
68 self.assertEqual(results['title'], 'foo')
69
70 def testFileCreate(self):
71 results = self.server.create('file', 'content=hello\r\nthere')
72 fileid = 'file' + results
73 results = self.server.display(fileid, 'content')
74 self.assertEqual(results['content'], 'hello\r\nthere')
75
76 def testAction(self):
77 # As this action requires special previledges, we temporarily switch
78 # to 'admin'
79 self.db.setCurrentUser('admin')
80 users_before = self.server.list('user')
81 try:
82 tmp = 'user' + self.db.user.create(username='tmp')
83 self.server.action('retire', tmp)
84 finally:
85 self.db.setCurrentUser('joe')
86 users_after = self.server.list('user')
87 self.assertEqual(users_before, users_after)
88
89 def testAuthDeniedEdit(self):
90 # Wrong permissions (caught by roundup security module).
91 self.assertRaises(Unauthorised, self.server.set,
92 'user1', 'realname=someone')
93
94 def testAuthDeniedCreate(self):
95 self.assertRaises(Unauthorised, self.server.create,
96 'user', {'username': 'blah'})
97
98 def testAuthAllowedEdit(self):
99 self.db.setCurrentUser('admin')
100 try:
101 try:
102 self.server.set('user2', 'realname=someone')
103 except Unauthorised, err:
104 self.fail('raised %s'%err)
105 finally:
106 self.db.setCurrentUser('joe')
107
108 def testAuthAllowedCreate(self):
109 self.db.setCurrentUser('admin')
110 try:
111 try:
112 self.server.create('user', 'username=blah')
113 except Unauthorised, err:
114 self.fail('raised %s'%err)
115 finally:
116 self.db.setCurrentUser('joe')
117
118def test_suite():
119 suite = unittest.TestSuite()
120 for l in list_backends():
121 dct = dict(backend = l)
122 subcls = type(TestCase)('TestCase_%s'%l, (TestCase,), dct)
123 suite.addTest(unittest.makeSuite(subcls))
124 return suite
125
126if __name__ == '__main__':
127 runner = unittest.TextTestRunner()
128 unittest.main(testRunner=runner)