view test/test_xmlrpc.py @ 3945:1dd64778bc45

Mail improvements: - Implement new config option in mail-section "ignore_alternatives" to ignore alternatives in a multipart/alternative mail. The *last* text/plain part of the *first* multipart/alternative is used as the message, if ignore_alternatives is set all other alternative parts of the first multipart/alternative that contained a text/plain part are ignored. Other multipart/alternative or other multipart are attached as before. This fixes [SF#959811] "Multipart/alternative handling considered bad". Note that this also changes which text/plain part is attached as the message if there are several text/plain parts in a multipart: Previously the *first* text/plain would be attached. Now we attach the *last* one, this is more in line with rfc 2046, sec. 5.1.4. according to Philipp Gortan. - Fix bug in attachment of text parts: If there are multiple text/plain parts in a nested multipart, the previous code would attach the multipart serialisation instead of the text/plain serialisation as a file to the issue in some cases. - Add regression tests for the new config-option and bug-fixes above.
author Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
date Wed, 14 Nov 2007 14:57:47 +0000
parents 3c3077582c16
children 85cbaa50eba1
line wrap: on
line source

#
# Copyright (C) 2007 Stefan Seefeld
# All rights reserved.
# For license terms see the file COPYING.txt.
#

import unittest, os, shutil, errno, sys, difflib, cgi, re

from roundup.cgi.exceptions import *
from roundup import init, instance, password, hyperdb, date
from roundup.xmlrpc import RoundupServer

import db_test_base

NEEDS_INSTANCE = 1

class TestCase(unittest.TestCase):
    def setUp(self):
        self.dirname = '_test_xmlrpc'
        # set up and open a tracker
        self.instance = db_test_base.setupTracker(self.dirname)

        # open the database
        self.db = self.instance.open('admin')
        self.joeid = 'user' + self.db.user.create(username='joe',
            password=password.Password('random'), address='random@home.org',
            realname='Joe Random', roles='User')

        self.db.commit()
        self.db.close()

        self.server = RoundupServer(self.dirname)

    def tearDown(self):
        try:
            shutil.rmtree(self.dirname)
        except OSError, error:
            if error.errno not in (errno.ENOENT, errno.ESRCH): raise

    def testAccess(self):
        # Retrieve all three users.
        results = self.server.list('joe', 'random', 'user', 'id')
        self.assertEqual(len(results), 3)

        # Obtain data for 'joe'.
        results = self.server.display('joe', 'random', self.joeid)
        self.assertEqual(results['username'], 'joe')
        self.assertEqual(results['realname'], 'Joe Random')

    def testChange(self):
        # Reset joe's 'realname'.
        results = self.server.set('joe', 'random', self.joeid,
            'realname=Joe Doe')
        results = self.server.display('joe', 'random', self.joeid,
            'realname')
        self.assertEqual(results['realname'], 'Joe Doe')

    def testCreate(self):
        results = self.server.create('joe', 'random', 'issue', 'title=foo')
        issueid = 'issue' + results
        results = self.server.display('joe', 'random', issueid, 'title')
        self.assertEqual(results['title'], 'foo')

    def testAuthUnknown(self):
        # Unknown user (caught in XMLRPC frontend).
        self.assertRaises(Unauthorised, self.server.list,
            'nobody', 'nobody', 'user', 'id')

    def testAuthDeniedEdit(self):
        # Wrong permissions (caught by roundup security module).
        self.assertRaises(Unauthorised, self.server.set,
            'joe', 'random', 'user1', 'realname=someone')

    def testAuthDeniedCreate(self):
        self.assertRaises(Unauthorised, self.server.create,
            'joe', 'random', 'user', {'username': 'blah'})

    def testAuthAllowedEdit(self):
        try:
            self.server.set('admin', 'sekrit', 'user2', 'realname=someone')
        except Unauthorised, err:
            self.fail('raised %s'%err)

    def testAuthAllowedCreate(self):
        try:
            self.server.create('admin', 'sekrit', 'user', 'username=blah')
        except Unauthorised, err:
            self.fail('raised %s'%err)

def test_suite():
    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(TestCase))
    return suite

if __name__ == '__main__':
    runner = unittest.TextTestRunner()
    unittest.main(testRunner=runner)


Roundup Issue Tracker: http://roundup-tracker.org/