Update of /cvsroot/mailman/mailman3/src/mailman/tests
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17175

Modified Files:
      Tag: 3.0
        test_user_ops.py 
Log Message:
Little bit of cleanup.


--- NEW FILE: test_user_ops.py ---
# Copyright (C) 2004 Barry A. Warsaw
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# This program 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.  See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place - Suite 330, Boston, MA 02111-1307, USA.

"""Test backend ops on stubuserstorage which implements IUserStorage."""

import os
import unittest

import mailman
from mailman import startup
from mailman import errors
from mailman.config import configuration
from mailman.dbmgr import dbmgr
from mailman.interfaces.user import IUser
from mailman.interfaces.storages import IUserStorage
from mailman.stubbackend.stubimpl import stubuserstorage

from protocols.api import adapt



class TestUserOps(unittest.TestCase):
    def test_create_user(self):
        unless = self.failUnless
        unless(dbmgr.users)
        iuserstorage = adapt(dbmgr.users, IUserStorage)
        unless(iuserstorage)
        # Create a new user in a fake domain.
        domain = 'example.com'
        newuser = iuserstorage.create_user(domain)
        # According to the contract of create_user, this must implement IUser
        unless(newuser, 'should have a new user')
        iuser = adapt(newuser, IUser)
        unless(iuser)
        # Now that the user is created, I should be able to get it by id
        sameuser = iuserstorage.get_user(newuser.uid, domain)
        self.assertEqual(sameuser, newuser)

    def test_bad_domain(self):
        # Request a user from a bogus domain
        self.assertRaises(errors.NoUserError,
                          dbmgr.users.get_user, 12000, 'baddomain')


    def test_get_bogus_user(self):
        # Requsting a bogus user should result in a NoUserError being raised
        self.assertRaises(errors.NoUserError,
                          dbmgr.users.get_user, 12000, 'example.com')


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



if __name__ == '__main__':
    mmhere = os.path.abspath(os.path.dirname(mailman.__file__))
    mmroot = os.path.normpath(os.path.join(mmhere, os.pardir, os.pardir))
    conffile = os.path.normpath(
        os.path.join(mmroot, 'etc/backendtest.conf'))
    configuration.configure(conffile)
    # After the above line, dbmgr should know about our backend call
    # everyone's initializer.
    startup.startup()
    unittest.main()


_______________________________________________
Mailman-checkins mailing list
[EMAIL PROTECTED]
Unsubscribe: http://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org

Reply via email to