"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "test/test_xmlrpc.py" between
roundup-1.6.1.tar.gz and roundup-2.0.0.tar.gz

About: Roundup is an highly customisable issue-tracking system with command-line, web and e-mail interfaces (written in Python).

test_xmlrpc.py  (roundup-1.6.1):test_xmlrpc.py  (roundup-2.0.0)
# #
# Copyright (C) 2007 Stefan Seefeld # Copyright (C) 2007 Stefan Seefeld
# All rights reserved. # All rights reserved.
# For license terms see the file COPYING.txt. # For license terms see the file COPYING.txt.
# #
from __future__ import print_function
import unittest, os, shutil, errno, sys, difflib, cgi, re import unittest, os, shutil, errno, sys, difflib, cgi, re
from xmlrpclib import MultiCall from roundup.anypy import xmlrpc_
MultiCall = xmlrpc_.client.MultiCall
from roundup.cgi.exceptions import * from roundup.cgi.exceptions import *
from roundup import init, instance, password, hyperdb, date from roundup import init, instance, password, hyperdb, date
from roundup.xmlrpc import RoundupInstance, RoundupDispatcher from roundup.xmlrpc import RoundupInstance, RoundupDispatcher
from roundup.backends import list_backends from roundup.backends import list_backends
from roundup.hyperdb import String from roundup.hyperdb import String
from roundup.cgi import TranslationService from roundup.cgi import TranslationService
import db_test_base from . import db_test_base
from .test_mysql import skip_mysql from .test_mysql import skip_mysql
from .test_postgresql import skip_postgresql from .test_postgresql import skip_postgresql
class XmlrpcTest(object): class XmlrpcTest(object):
backend = None backend = None
def setUp(self): def setUp(self):
self.dirname = '_test_xmlrpc' self.dirname = '_test_xmlrpc'
# set up and open a tracker # set up and open a tracker
self.instance = db_test_base.setupTracker(self.dirname, self.backend) self.instance = db_test_base.setupTracker(self.dirname, self.backend)
# open the database # open the database
self.db = self.instance.open('admin') self.db = self.instance.open('admin')
print "props_only default", self.db.security.get_props_only_default() print("props_only default", self.db.security.get_props_only_default())
# Get user id (user4 maybe). Used later to get data from db. # Get user id (user4 maybe). Used later to get data from db.
self.joeid = 'user' + self.db.user.create(username='joe', self.joeid = 'user' + self.db.user.create(username='joe',
password=password.Password('random'), address='random@home.org', password=password.Password('random'), address='random@home.org',
realname='Joe Random', roles='User') realname='Joe Random', roles='User')
self.db.commit() self.db.commit()
self.db.close() self.db.close()
self.db = self.instance.open('joe') self.db = self.instance.open('joe')
self.db.tx_Source = 'web' self.db.tx_Source = 'web'
self.db.issue.addprop(tx_Source=hyperdb.String()) self.db.issue.addprop(tx_Source=hyperdb.String())
self.db.msg.addprop(tx_Source=hyperdb.String()) self.db.msg.addprop(tx_Source=hyperdb.String())
self.db.post_init() self.db.post_init()
thisdir = os.path.dirname(__file__) thisdir = os.path.dirname(__file__)
vars = {} vars = {}
execfile(os.path.join(thisdir, "tx_Source_detector.py"), vars) exec(compile(open(os.path.join(thisdir,
"tx_Source_detector.py")).read(),
os.path.join(thisdir, "tx_Source_detector.py"), 'exec'),
vars)
vars['init'](self.db) vars['init'](self.db)
self.server = RoundupInstance(self.db, self.instance.actions, None) self.server = RoundupInstance(self.db, self.instance.actions, None)
def tearDown(self): def tearDown(self):
self.db.close() self.db.close()
try: try:
shutil.rmtree(self.dirname) shutil.rmtree(self.dirname)
except OSError as error: except OSError as error:
if error.errno not in (errno.ENOENT, errno.ESRCH): raise if error.errno not in (errno.ENOENT, errno.ESRCH): raise
skipping to change at line 98 skipping to change at line 103
self.assertEqual(results['title'], 'foo') self.assertEqual(results['title'], 'foo')
self.assertEqual(self.db.issue.get('1', "tx_Source"), 'web') self.assertEqual(self.db.issue.get('1', "tx_Source"), 'web')
def testFileCreate(self): def testFileCreate(self):
results = self.server.create('file', 'content=hello\r\nthere') results = self.server.create('file', 'content=hello\r\nthere')
fileid = 'file' + results fileid = 'file' + results
results = self.server.display(fileid, 'content') results = self.server.display(fileid, 'content')
self.assertEqual(results['content'], 'hello\r\nthere') self.assertEqual(results['content'], 'hello\r\nthere')
def testSchema(self): def testSchema(self):
schema={'status': [('order', '<roundup.hyperdb.Number>'), schema={'status': [('name', '<roundup.hyperdb.String>'),
('name', '<roundup.hyperdb.String>')], ('order', '<roundup.hyperdb.Number>')],
'keyword': [('name', '<roundup.hyperdb.String>')], 'keyword': [('name', '<roundup.hyperdb.String>')],
'priority': [('order', '<roundup.hyperdb.Number>'), 'priority': [('name', '<roundup.hyperdb.String>'),
('name', '<roundup.hyperdb.String>')], ('order', '<roundup.hyperdb.Number>')],
'user': [('username', '<roundup.hyperdb.String>'), 'user': [('address', '<roundup.hyperdb.String>'),
('alternate_addresses', '<roundup.hyperdb.String>'), ('alternate_addresses', '<roundup.hyperdb.String>'),
('realname', '<roundup.hyperdb.String>'),
('roles', '<roundup.hyperdb.String>'),
('organisation', '<roundup.hyperdb.String>'), ('organisation', '<roundup.hyperdb.String>'),
('queries', '<roundup.hyperdb.Multilink to "query">'), ('password', '<roundup.hyperdb.Password>'),
('phone', '<roundup.hyperdb.String>'), ('phone', '<roundup.hyperdb.String>'),
('address', '<roundup.hyperdb.String>'), ('queries', '<roundup.hyperdb.Multilink to "query">'),
('realname', '<roundup.hyperdb.String>'),
('roles', '<roundup.hyperdb.String>'),
('timezone', '<roundup.hyperdb.String>'), ('timezone', '<roundup.hyperdb.String>'),
('password', '<roundup.hyperdb.Password>')], ('username', '<roundup.hyperdb.String>')],
'file': [('content', '<roundup.hyperdb.String>'), 'file': [('content', '<roundup.hyperdb.String>'),
('type', '<roundup.hyperdb.String>'), ('name', '<roundup.hyperdb.String>'),
('name', '<roundup.hyperdb.String>')], ('type', '<roundup.hyperdb.String>')],
'msg': [('files', '<roundup.hyperdb.Multilink to "file">'), 'msg': [('author', '<roundup.hyperdb.Link to "user">'),
('content', '<roundup.hyperdb.String>'),
('date', '<roundup.hyperdb.Date>'),
('files', '<roundup.hyperdb.Multilink to "file">'),
('inreplyto', '<roundup.hyperdb.String>'), ('inreplyto', '<roundup.hyperdb.String>'),
('tx_Source', '<roundup.hyperdb.String>'), ('messageid', '<roundup.hyperdb.String>'),
('recipients', '<roundup.hyperdb.Multilink to "user">'), ('recipients', '<roundup.hyperdb.Multilink to "user">'),
('author', '<roundup.hyperdb.Link to "user">'),
('summary', '<roundup.hyperdb.String>'), ('summary', '<roundup.hyperdb.String>'),
('content', '<roundup.hyperdb.String>'), ('tx_Source', '<roundup.hyperdb.String>'),
('messageid', '<roundup.hyperdb.String>'),
('date', '<roundup.hyperdb.Date>'),
('type', '<roundup.hyperdb.String>')], ('type', '<roundup.hyperdb.String>')],
'query': [('url', '<roundup.hyperdb.String>'), 'query': [('klass', '<roundup.hyperdb.String>'),
('private_for', '<roundup.hyperdb.Link to "user">'),
('name', '<roundup.hyperdb.String>'), ('name', '<roundup.hyperdb.String>'),
('klass', '<roundup.hyperdb.String>')], ('private_for', '<roundup.hyperdb.Link to "user">'),
'issue': [('status', '<roundup.hyperdb.Link to "status">'), ('url', '<roundup.hyperdb.String>')],
'issue': [('assignedto', '<roundup.hyperdb.Link to "user">'),
('files', '<roundup.hyperdb.Multilink to "file">'), ('files', '<roundup.hyperdb.Multilink to "file">'),
('tx_Source', '<roundup.hyperdb.String>'),
('keyword', '<roundup.hyperdb.Multilink to "keyword">' ), ('keyword', '<roundup.hyperdb.Multilink to "keyword">' ),
('title', '<roundup.hyperdb.String>'),
('nosy', '<roundup.hyperdb.Multilink to "user">'),
('messages', '<roundup.hyperdb.Multilink to "msg">'), ('messages', '<roundup.hyperdb.Multilink to "msg">'),
('nosy', '<roundup.hyperdb.Multilink to "user">'),
('priority', '<roundup.hyperdb.Link to "priority">'), ('priority', '<roundup.hyperdb.Link to "priority">'),
('assignedto', '<roundup.hyperdb.Link to "user">'), ('status', '<roundup.hyperdb.Link to "status">'),
('superseder', '<roundup.hyperdb.Multilink to "issue"> ('superseder', '<roundup.hyperdb.Multilink to "issue">
')]} '),
('title', '<roundup.hyperdb.String>'),
('tx_Source', '<roundup.hyperdb.String>')]}
results = self.server.schema() results = self.server.schema()
self.assertEqual(results, schema) self.assertEqual(results, schema)
def testLookup(self): def testLookup(self):
self.assertRaises(KeyError, self.server.lookup, 'user', '1') self.assertRaises(KeyError, self.server.lookup, 'user', '1')
results = self.server.lookup('user', 'admin') results = self.server.lookup('user', 'admin')
self.assertEqual(results, '1') self.assertEqual(results, '1')
def testAction(self): def testAction(self):
skipping to change at line 165 skipping to change at line 170
tmp = 'user' + self.db.user.create(username='tmp') tmp = 'user' + self.db.user.create(username='tmp')
self.server.action('retire', tmp) self.server.action('retire', tmp)
finally: finally:
self.db.setCurrentUser('joe') self.db.setCurrentUser('joe')
users_after = self.server.list('user') users_after = self.server.list('user')
self.assertEqual(users_before, users_after) self.assertEqual(users_before, users_after)
# test a bogus action # test a bogus action
with self.assertRaises(Exception) as cm: with self.assertRaises(Exception) as cm:
self.server.action('bogus') self.server.action('bogus')
print cm.exception print(cm.exception)
self.assertEqual(cm.exception.message, self.assertEqual(cm.exception.args[0],
'action "bogus" is not supported ') 'action "bogus" is not supported ')
def testAuthDeniedEdit(self): def testAuthDeniedEdit(self):
# Wrong permissions (caught by roundup security module). # Wrong permissions (caught by roundup security module).
self.assertRaises(Unauthorised, self.server.set, self.assertRaises(Unauthorised, self.server.set,
'user1', 'realname=someone') 'user1', 'realname=someone')
def testAuthDeniedCreate(self): def testAuthDeniedCreate(self):
self.assertRaises(Unauthorised, self.server.create, self.assertRaises(Unauthorised, self.server.create,
'user', {'username': 'blah'}) 'user', {'username': 'blah'})
skipping to change at line 208 skipping to change at line 213
def testAuthFilter(self): def testAuthFilter(self):
# this checks if we properly check for search permissions # this checks if we properly check for search permissions
self.db.security.permissions = {} self.db.security.permissions = {}
# self.db.security.set_props_only_default(props_only=False) # self.db.security.set_props_only_default(props_only=False)
self.db.security.addRole(name='User') self.db.security.addRole(name='User')
self.db.security.addRole(name='Project') self.db.security.addRole(name='Project')
self.db.security.addPermissionToRole('User', 'Web Access') self.db.security.addPermissionToRole('User', 'Web Access')
self.db.security.addPermissionToRole('Project', 'Web Access') self.db.security.addPermissionToRole('Project', 'Web Access')
# Allow viewing keyword # Allow viewing keyword
p = self.db.security.addPermission(name='View', klass='keyword') p = self.db.security.addPermission(name='View', klass='keyword')
print "View keyword class: %r"%p print("View keyword class: %r"%p)
self.db.security.addPermissionToRole('User', p) self.db.security.addPermissionToRole('User', p)
# Allow viewing interesting things (but not keyword) on issue # Allow viewing interesting things (but not keyword) on issue
# But users might only view issues where they are on nosy # But users might only view issues where they are on nosy
# (so in the real world the check method would be better) # (so in the real world the check method would be better)
p = self.db.security.addPermission(name='View', klass='issue', p = self.db.security.addPermission(name='View', klass='issue',
properties=("title", "status"), check=lambda x,y,z: True) properties=("title", "status"), check=lambda x,y,z: True)
print "View keyword class w/ props: %r"%p print("View keyword class w/ props: %r"%p)
self.db.security.addPermissionToRole('User', p) self.db.security.addPermissionToRole('User', p)
# Allow role "Project" access to whole issue # Allow role "Project" access to whole issue
p = self.db.security.addPermission(name='View', klass='issue') p = self.db.security.addPermission(name='View', klass='issue')
self.db.security.addPermissionToRole('Project', p) self.db.security.addPermissionToRole('Project', p)
# Allow all access to status: # Allow all access to status:
p = self.db.security.addPermission(name='View', klass='status') p = self.db.security.addPermission(name='View', klass='status')
self.db.security.addPermissionToRole('User', p) self.db.security.addPermissionToRole('User', p)
self.db.security.addPermissionToRole('Project', p) self.db.security.addPermissionToRole('Project', p)
keyword = self.db.keyword keyword = self.db.keyword
skipping to change at line 244 skipping to change at line 249
issue.create(title='i2', status=open, keyword=[d1]) issue.create(title='i2', status=open, keyword=[d1])
issue.create(title='i2', status=closed, keyword=[d1]) issue.create(title='i2', status=closed, keyword=[d1])
chef = self.db.user.create(username = 'chef', roles='User, Project') chef = self.db.user.create(username = 'chef', roles='User, Project')
joe = self.db.user.lookup('joe') joe = self.db.user.lookup('joe')
# Conditionally allow view of whole issue (check is False here, # Conditionally allow view of whole issue (check is False here,
# this might check for keyword owner in the real world) # this might check for keyword owner in the real world)
p = self.db.security.addPermission(name='View', klass='issue', p = self.db.security.addPermission(name='View', klass='issue',
check=lambda x,y,z: False) check=lambda x,y,z: False)
print "View issue class: %r"%p print("View issue class: %r"%p)
self.db.security.addPermissionToRole('User', p) self.db.security.addPermissionToRole('User', p)
# Allow user to search for issue.status # Allow user to search for issue.status
p = self.db.security.addPermission(name='Search', klass='issue', p = self.db.security.addPermission(name='Search', klass='issue',
properties=("status",)) properties=("status",))
print "View Search class w/ props: %r"%p print("View Search class w/ props: %r"%p)
self.db.security.addPermissionToRole('User', p) self.db.security.addPermissionToRole('User', p)
keyw = {'keyword':self.db.keyword.lookup('d1')} keyw = {'keyword':self.db.keyword.lookup('d1')}
stat = {'status':self.db.status.lookup('open')} stat = {'status':self.db.status.lookup('open')}
keygroup = keysort = [('+', 'keyword')] keygroup = keysort = [('+', 'keyword')]
self.db.commit() self.db.commit()
# Filter on keyword ignored for role 'User': # Filter on keyword ignored for role 'User':
r = self.server.filter('issue', None, keyw) r = self.server.filter('issue', None, keyw)
self.assertEqual(r, ['1', '2', '3']) self.assertEqual(r, ['1', '2', '3'])
 End of changes. 26 change blocks. 
38 lines changed or deleted 43 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)