Update of /cvsroot/mailman/mailman3/src/mailman/berkeleydb/tests
In directory
sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31133/src/mailman/berkeleydb/tests
Added Files:
Tag: 3.0
__init__.py test_members.py
Log Message:
Initial checkin of Mailman3 source
--- NEW FILE: __init__.py ---
--- NEW FILE: test_members.py ---
# Copyright (C) 2003 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.
"""Tests for member interfaces.
"""
import os
import sha
import time
import shutil
import unittest
from mailman import utils
from mailman.config import *
from mailman.interfaces.members import IPreferences, IDeliveryStatus
from mailman.interfaces.members import IBounceInfo
from mailman.interfaces.members import DeliveryMode, DeliveryStatus
from mailman.database.bdbmembers import BDBMembers
VARDIR = 'var'
class TestMembers(unittest.TestCase):
def setUp(self):
if os.path.isdir(VARDIR):
shutil.rmtree(VARDIR)
os.mkdir(VARDIR)
self._db = BDBMembers(os.path.join(VARDIR, 'members.db'))
self._addr = '[EMAIL PROTECTED]'
def tearDown(self):
self._db.close()
shutil.rmtree(VARDIR)
def get_factory(self):
#return adapt(self._db, IProfileFactory)
return self._db
def test_create_member(self):
eq = self.assertEqual
unless = self.failUnless
profile = self.get_factory().profile(self._addr)
eq(profile.id, sha.new(self._addr).hexdigest())
eq(profile.address, self._addr)
eq(profile.realname, '')
eq(profile.aliases, [])
eq(profile.password, '')
# Test the defaults
defaults = profile.defaults
unless(IPreferences.isImplementedBy(defaults))
eq(defaults.language, DEFAULT_SERVER_LANGUAGE)
eq(defaults.mode, DeliveryMode.Regular)
eq(defaults.options, 0)
# Test the status
status = profile.status
unless(IDeliveryStatus.isImplementedBy(status))
eq(status.status, DeliveryStatus.Enabled)
# XXX Use datetimes instead
unless(status.statusChangeTime < time.time())
eq(status.vacationReturn, None)
# Bounce scores
info = profile.bounceInfo
unless(IBounceInfo.isImplementedBy(info))
eq(info.score, 0.0)
eq(info.lastBounceTime, None)
eq(info.noticesLeft, None)
eq(info.lastNoticeDate, None)
eq(info.reenableCookie, None)
# Test the listids this user is on
eq(profile.listsOn, [])
def test_set_address(self):
eq = self.assertEqual
newaddr = '[EMAIL PROTECTED]'
profile = self.get_factory().profile(self._addr)
eq(profile.id, sha.new(self._addr).hexdigest())
eq(profile.address, self._addr)
profile.address = newaddr
eq(profile.address, newaddr)
eq(profile.id, sha.new(self._addr).hexdigest())
def test_set_realname(self):
eq = self.assertEqual
profile = self.get_factory().profile(self._addr)
eq(profile.realname, '')
profile.realname = realname = 'Anne Person'
eq(profile.realname, realname)
class TestStressMembers(unittest.TestCase):
level = 2
def setUp(self):
if os.path.isdir(VARDIR):
shutil.rmtree(VARDIR)
os.mkdir(VARDIR)
self._db = BDBMembers(os.path.join(VARDIR, 'members.db'))
# Make a bunch of random, but unique names
names = {}
i = 0
while i < 1000:
addr = utils.mksyllables() + '@example.com'
if addr in names:
continue
first = utils.mksyllables(4).capitalize()
last = utils.mksyllables(8).capitalize()
names[addr] = first + ' ' + last
i += 1
self._members = zip(names.values(), names.keys())
def tearDown(self):
self._db.close()
shutil.rmtree(VARDIR)
def get_factory(self):
#return adapt(self._db, IProfileFactory)
return self._db
def test_add_10000_members_onetxn(self):
factory = self.get_factory()
txn = factory.begin()
for realname, address in self._members:
profile = factory.profile(address)
txn.commit()
def test_add_10000_members_manytxns(self):
factory = self.get_factory()
for realname, address in self._members:
profile = factory.profile(address)
def test_mass_subscribe(self):
factory = self.get_factory()
factory.massSubscribe(self._members)
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestMembers))
suite.addTest(unittest.makeSuite(TestStressMembers))
return suite
_______________________________________________
Mailman-checkins mailing list
[EMAIL PROTECTED]
Unsubscribe: http://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org