[Zope3-checkins] CVS: zopeproducts/bugtracker/tests - __init__.py:1.1 test_bug.py:1.1 test_comment.py:1.1 test_dependencies.py:1.1 test_mail.py:1.1 test_tracker.py:1.1 test_vocabularies.py:1.1

Stephan Richter srichter@cosmos.phy.tufts.edu
Thu, 24 Jul 2003 14:08:47 -0400


Update of /cvs-repository/zopeproducts/bugtracker/tests
In directory cvs.zope.org:/tmp/cvs-serv302/tests

Added Files:
	__init__.py test_bug.py test_comment.py test_dependencies.py 
	test_mail.py test_tracker.py test_vocabularies.py 
Log Message:
First Checkin of the Bug Tracker. A list of features is the README.txt file
and a to-do list is in TODO.txt.

The code features the use of vocabularies and vocabulary fields.

There is still a bit of work to do, but I am pretty close to make it usable
for us.


=== Added File zopeproducts/bugtracker/tests/__init__.py ===


=== Added File zopeproducts/bugtracker/tests/test_bug.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Bug Tests

$Id: test_bug.py,v 1.1 2003/07/24 18:08:38 srichter Exp $
"""
import unittest

from zope.app.interfaces.annotation import IAnnotations, IAttributeAnnotatable
from zope.app.interfaces.dublincore import IWriteZopeDublinCore

from zope.app.attributeannotations import AttributeAnnotations
from zope.app.dublincore.annotatableadapter import ZDCAnnotatableAdapter
from zope.component.adapter import provideAdapter
from zope.component.tests.placelesssetup import PlacelessSetup
from zope.interface import classImplements
from zopeproducts.bugtracker.interfaces import IBug
from zopeproducts.bugtracker.bug import Bug

DCkey = "zope.app.dublincore.ZopeDublinCore"

class BugTest(PlacelessSetup, unittest.TestCase):

    def setUp(self):
        PlacelessSetup.setUp(self)
        classImplements(Bug, IAttributeAnnotatable)
        provideAdapter(IAttributeAnnotatable, IAnnotations,
                       AttributeAnnotations)
        provideAdapter(IAttributeAnnotatable, IWriteZopeDublinCore,
                       ZDCAnnotatableAdapter)

    def getBug(self):
        return Bug()

    def test_Interface(self):
        self.failUnless(IBug.isImplementedBy(self.getBug()))

    def test_title(self):
        bug = self.getBug()
        self.assertEqual(bug.title, u'')
        bug.title = u'Title'
        self.assertEqual(bug.title, u'Title')
        self.assertEqual(bug.__annotations__[DCkey]['Title'], (u'Title',))

    def test_description(self):
        bug = self.getBug()
        self.assertEqual(bug.description, u'')
        bug.description = u'Description'
        self.assertEqual(bug.description, u'Description')
        self.assertEqual(bug.__annotations__[DCkey]['Description'],
                         (u'Description',))

    def test_owners(self):
        bug = self.getBug()
        self.assertEqual(bug.owners, [])
        bug.owners = [u'srichter']
        self.assertEqual(bug.owners, [u'srichter'])

    def test_status(self):
        bug = self.getBug()
        self.assertEqual(bug.status, u'new')
        bug.status = u'open'
        self.assertEqual(bug.status, u'open')

    def test_type(self):
        bug = self.getBug()
        self.assertEqual(bug.type, u'bug')
        bug.type = u'feature'
        self.assertEqual(bug.type, u'feature')

    def test_priority(self):
        bug = self.getBug()
        self.assertEqual(bug.priority, u'normal')
        bug.priority = u'urgent'
        self.assertEqual(bug.priority, u'urgent')

    def test_release(self):
        bug = self.getBug()
        self.assertEqual(bug.release, u'None')
        bug.release = u'Zope X3'
        self.assertEqual(bug.release, u'Zope X3')

    def test_submitter(self):
        bug = self.getBug()
        # Just here to create the annotations
        bug.title = u''
        self.assertEqual(bug.submitter, None)
        bug.__annotations__[DCkey]['Creator'] = ['srichter']
        self.assertEqual(bug.submitter, u'srichter')


def test_suite():
    return unittest.TestSuite((
        unittest.makeSuite(BugTest),
        ))

if __name__ == '__main__':
    unittest.main()


=== Added File zopeproducts/bugtracker/tests/test_comment.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Bug Tracker Mail Subscription and Mailer Tests

$Id: test_comment.py,v 1.1 2003/07/24 18:08:38 srichter Exp $
"""
import unittest

from zopeproducts.bugtracker.interfaces import IComment
from zopeproducts.bugtracker.comment import Comment

class CommentTest(unittest.TestCase):

    def setUp(self):
        self.comment = Comment()

    def test_Interface(self):
        self.failUnless(IComment.isImplementedBy(self.comment))

    def test_body(self):
        self.assertEqual(self.comment.body, u'')
        self.comment.body = u'test'
        self.assertEqual(self.comment.body, u'test')
        

def test_suite():
    return unittest.TestSuite((
        unittest.makeSuite(CommentTest),
        ))

if __name__ == '__main__':
    unittest.main()


=== Added File zopeproducts/bugtracker/tests/test_dependencies.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Bug Dependencies Tests

$Id: test_dependencies.py,v 1.1 2003/07/24 18:08:38 srichter Exp $
"""
import unittest

from zopeproducts.bugtracker.interfaces import IBug, IBugDependencies
from zopeproducts.bugtracker.bug import Bug, BugDependencyAdapter
from zopeproducts.bugtracker.tracker import BugTracker
from zope.interface import classImplements
from zope.component.tests.placelesssetup import PlacelessSetup
from zope.component.adapter import provideAdapter

from zope.app.interfaces.annotation import IAnnotations, IAttributeAnnotatable
from zope.app.interfaces.traversing import IPhysicallyLocatable

from zope.app.context import ContextWrapper
from zope.app.attributeannotations import AttributeAnnotations
from zope.app.traversing.adapters import WrapperPhysicallyLocatable


class DependencyTest(PlacelessSetup, unittest.TestCase):

    def setUp(self):
        PlacelessSetup.setUp(self)
        classImplements(Bug, IAttributeAnnotatable);
        provideAdapter(IAttributeAnnotatable, IAnnotations,
                       AttributeAnnotations)
        provideAdapter(IBug, IBugDependencies,
                       BugDependencyAdapter)
        provideAdapter(None, IPhysicallyLocatable, WrapperPhysicallyLocatable)
        self.bug = Bug()

    def makeTestObject(self):
        return BugDependencyAdapter(self.bug)

    def test_Interface(self):
        deps = self.makeTestObject()
        self.failUnless(IBugDependencies.isImplementedBy(deps))

    def test_dependencies(self):
        deps = self.makeTestObject()
        self.assertEqual((), deps.dependencies)
        deps.dependencies = ('foo',)
        self.assertEqual(('foo',), deps.dependencies)
        # Test whether the annotations stay.
        deps = self.makeTestObject()
        self.assertEqual(('foo',), deps.dependencies)

    def test_findChildren(self):
        tracker = BugTracker()

        bug1 = Bug()
        tracker.setObject('TopLevelBug', bug1)
        wrapped_bug1 = ContextWrapper(bug1, tracker, name='TopLevelbug')
        deps1 = BugDependencyAdapter(wrapped_bug1)
        deps1.dependencies = ('SecondLevelBug',)

        bug2 = Bug()
        tracker.setObject('SecondLevelBug', bug2)
        wrapped_bug2 = ContextWrapper(bug2, tracker, name='SecondLevelBug')
        deps2 = BugDependencyAdapter(wrapped_bug2)
        deps2.dependencies = ('ThirdLevelBug',)

        bug3 = Bug()
        tracker.setObject('ThirdLevelBug', bug3)
        wrapped_bug3 = ContextWrapper(bug3, tracker, name='ThirdLevelBug')
        deps3 = BugDependencyAdapter(wrapped_bug3)

        self.assertEqual(( (wrapped_bug2, ()), ),
                         deps1.findChildren(False));

        self.assertEqual(((wrapped_bug2, ((wrapped_bug3, ()),) ),),
                         deps1.findChildren());
        
    
def test_suite():
    return unittest.TestSuite((
        unittest.makeSuite(DependencyTest),
        ))

if __name__ == '__main__':
    unittest.main()


=== Added File zopeproducts/bugtracker/tests/test_mail.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Bug Tracker Mail Subscription and Mailer Tests

$Id: test_mail.py,v 1.1 2003/07/24 18:08:38 srichter Exp $
"""
import unittest

from zope.app.interfaces.annotation import IAnnotations, IAttributeAnnotatable
from zope.app.interfaces.dublincore import IWriteZopeDublinCore
from zope.app.interfaces.event import ISubscriber
from zope.app.interfaces.mail import IMailService
from zope.app.interfaces.traversing import IPhysicallyLocatable
from zopeproducts.bugtracker.interfaces import IBug, IBugTracker
from zopeproducts.bugtracker.interfaces import IMailSubscriptions

from zope.interface import classImplements, implements
from zope.component.adapter import provideAdapter
from zope.component.service import defineService, serviceManager
from zope.component.tests.placelesssetup import PlacelessSetup
from zope.app.attributeannotations import AttributeAnnotations
from zope.app.context import ContextWrapper
from zope.app.dublincore.annotatableadapter import ZDCAnnotatableAdapter
from zope.app.event.objectevent import ObjectModifiedEvent
from zope.app.traversing.adapters import WrapperPhysicallyLocatable

from zopeproducts.bugtracker.bug import Bug
from zopeproducts.bugtracker.tracker import BugTracker
from zopeproducts.bugtracker.mail import MailSubscriptions, SubscriberKey
from zopeproducts.bugtracker.mail import Mailer, mailer

mail_result = [] 

class MailServiceStub(object):

    implements(IMailService)

    def send(self, fromaddr, toaddrs, message):
        mail_result.append((fromaddr, toaddrs, message))


class MailSubscriptionTest(PlacelessSetup, unittest.TestCase):

    def setUp(self):
        PlacelessSetup.setUp(self)
        # This needs to be done, since the IAttributeAnnotable interface
        # is usually set in the ZCML
        classImplements(Bug, IAttributeAnnotatable)
        provideAdapter(IAttributeAnnotatable, IAnnotations,
                       AttributeAnnotations)
        self._sub = MailSubscriptions(Bug())

    def test_Interface(self):
        self.failUnless(IMailSubscriptions.isImplementedBy(self._sub))

    def test_getSubscriptions(self):
        self.assertEqual((), self._sub.getSubscriptions())
        self._sub.context.__annotations__[SubscriberKey] = ('foo@bar.com',)
        self.assertEqual(('foo@bar.com',), self._sub.getSubscriptions())

    def test_addSubscriptions(self):
        self._sub.addSubscriptions(('foo@bar.com',))
        self.assertEqual(('foo@bar.com',),
                         self._sub.context.__annotations__[SubscriberKey])
        self._sub.addSubscriptions(('blah@bar.com',))
        self.assertEqual(('foo@bar.com', 'blah@bar.com'),
                         self._sub.context.__annotations__[SubscriberKey])
        self._sub.addSubscriptions(('blah@bar.com',))
        self.assertEqual(('foo@bar.com', 'blah@bar.com'),
                         self._sub.context.__annotations__[SubscriberKey])
        self._sub.addSubscriptions(('blah@bar.com', 'doh@bar.com'))
        self.assertEqual(('foo@bar.com', 'blah@bar.com', 'doh@bar.com'),
                         self._sub.context.__annotations__[SubscriberKey])

    def test_removeSubscriptions(self):
        self._sub.context.__annotations__[SubscriberKey] = (
            'foo@bar.com', 'blah@bar.com', 'doh@bar.com')
        self._sub.removeSubscriptions(('foo@bar.com',))
        self.assertEqual(('blah@bar.com', 'doh@bar.com'),
                         self._sub.context.__annotations__[SubscriberKey])
        self._sub.removeSubscriptions(('foo@bar.com',))
        self.assertEqual(('blah@bar.com', 'doh@bar.com'),
                         self._sub.context.__annotations__[SubscriberKey])
        self._sub.removeSubscriptions(('blah@bar.com', 'doh@bar.com'))
        self.assertEqual((),
                         self._sub.context.__annotations__[SubscriberKey])


class MailerTest(PlacelessSetup, unittest.TestCase):

    def setUp(self):
        PlacelessSetup.setUp(self)
        # This needs to be done, since the IAttributeAnnotable interface
        # is usually set in the ZCML
        provideAdapter(None, IPhysicallyLocatable, WrapperPhysicallyLocatable)
        classImplements(BugTracker, IAttributeAnnotatable)
        classImplements(Bug, IAttributeAnnotatable)
        provideAdapter(IBugTracker, IMailSubscriptions, MailSubscriptions)
        provideAdapter(IBug, IMailSubscriptions, MailSubscriptions)
        provideAdapter(IAttributeAnnotatable, IAnnotations,
                       AttributeAnnotations)
        provideAdapter(IAttributeAnnotatable, IWriteZopeDublinCore,
                       ZDCAnnotatableAdapter)
        defineService('Mail', IMailService)
        serviceManager.provideService('Mail', MailServiceStub())

    def test_Interface(self):
        self.failUnless(ISubscriber.isImplementedBy(mailer))

    def test_getAllSubscribers(self):
        tracker = BugTracker()
        tracker_sub = MailSubscriptions(tracker)
        tracker_sub.context.__annotations__[SubscriberKey] = ('foo@bar.com',)
        wrapped_tracker = ContextWrapper(tracker, object(), name='tracker')
        bug = Bug()
        bug_sub = MailSubscriptions(bug)
        bug_sub.context.__annotations__[SubscriberKey] = ('blah@bar.com',)
        tracker.setObject('bug', bug)
        wrapped_bug = ContextWrapper(bug, wrapped_tracker, name="bug")
        self.assertEqual(('blah@bar.com', 'foo@bar.com'),
                         mailer.getAllSubscribers(wrapped_bug))

    def test_notify(self):
        bug = Bug()
        bug.title = u'Hello'
        bug.description = u'Hello World!'
        bug_sub = MailSubscriptions(bug)
        bug_sub.context.__annotations__[SubscriberKey] = ('foo@bar.com',)
        wrapped_bug = ContextWrapper(bug, object(), name='bug')
        event = ObjectModifiedEvent(wrapped_bug)
        mailer.notify(event)
        self.assertEqual('bugtracker@zope3.org', mail_result[0][0])
        self.assertEqual(('foo@bar.com', ), mail_result[0][1])
        self.assertEqual('Subject: Modified: Hello (bug)\n\n\nHello World!',
                         mail_result[0][2])

def test_suite():
    return unittest.TestSuite((
        unittest.makeSuite(MailSubscriptionTest),
        unittest.makeSuite(MailerTest),
        ))

if __name__ == '__main__':
    unittest.main()


=== Added File zopeproducts/bugtracker/tests/test_tracker.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Bug Tracker Mail Subscription and Mailer Tests

$Id: test_tracker.py,v 1.1 2003/07/24 18:08:38 srichter Exp $
"""
import unittest

from zope.app.component.tests.test_servicemanagercontainer \
     import BaseTestServiceManagerContainer
from zope.app.container.tests.test_icontainer import BaseTestIContainer
from zope.app.container.tests.test_icontainer import DefaultTestData

from zopeproducts.bugtracker.interfaces import IBugTracker
from zopeproducts.bugtracker.tracker import BugTracker


class TrackerTest(BaseTestIContainer, BaseTestServiceManagerContainer, 
                  unittest.TestCase):

    def makeTestObject(self):
        return BugTracker()

    def makeTestData(self):
        return DefaultTestData()

    def test_Interface(self):
        self.failUnless(IBugTracker.isImplementedBy(self.makeTestObject()))

    def test_title(self):
        tracker = self.makeTestObject()
        self.assertEqual(tracker.title, u'')
        tracker.title = u'test'
        self.assertEqual(tracker.title, u'test')
        

def test_suite():
    return unittest.TestSuite((
        unittest.makeSuite(TrackerTest),
        ))

if __name__ == '__main__':
    unittest.main()


=== Added File zopeproducts/bugtracker/tests/test_vocabularies.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Bug Tracker Vocabulary Tests

$Id: test_vocabularies.py,v 1.1 2003/07/24 18:08:38 srichter Exp $
"""
import unittest

from zope.app.attributeannotations import AttributeAnnotations
from zope.app.context import ContextWrapper
from zope.app.interfaces.annotation import IAnnotations, IAttributeAnnotatable
from zope.app.interfaces.security import IAuthenticationService
from zope.app.interfaces.traversing import IContainmentRoot
from zope.app.services.pluggableauth import SimplePrincipal
from zope.app.services.auth import AuthenticationService, User
from zope.component.adapter import provideAdapter
from zope.component.service import defineService, serviceManager
from zope.component.tests.placelesssetup import PlacelessSetup
from zope.interface import classImplements, implements
from zope.schema.interfaces import ITokenizedTerm
from zopeproducts.bugtracker.interfaces import IManagableVocabulary
from zopeproducts.bugtracker.tracker import BugTracker
from zopeproducts.bugtracker.vocabulary import SimpleTerm, \
     StatusVocabulary, PriorityVocabulary, BugTypeVocabulary, ReleaseVocabulary
from zopeproducts.bugtracker.vocabulary import UserTerm, UserVocabulary


class Root(object):
    implements(IContainmentRoot)

class ManagableVocabularyBaseTest(PlacelessSetup):

    def setUp(self):
        PlacelessSetup.setUp(self)
        classImplements(BugTracker, IAttributeAnnotatable)
        provideAdapter(IAttributeAnnotatable, IAnnotations,
                       AttributeAnnotations)

    def getVocabularyClass(self):
        return NotImplemented

    def makeVocabulary(self):
        tracker = ContextWrapper(BugTracker(), Root(), name="tracker")
        vocab = self.getVocabularyClass()(tracker)
        vocab.context.__annotations__ = {}
        data = {'1': SimpleTerm('1', u'one'),
                '2': SimpleTerm('2', u'two'),
                '3': SimpleTerm('3', u'three'),
                '4': SimpleTerm('4', u'four')}
        vocab.context.__annotations__[vocab.key] = data
        return vocab

    def test_contains(self):
        vocab = self.makeVocabulary()
        self.assertEqual(vocab.__contains__('2'), True)
        self.assertEqual(vocab.__contains__('6'), False)

    def test_iter(self):
        vocab = self.makeVocabulary()
        self.assertEqual('2' in map(lambda x: x.value, vocab.__iter__()), True)
        self.assertEqual('6' in map(lambda x: x.value, vocab.__iter__()), False)
        self.assertEqual('2' in map(lambda x: x.value, iter(vocab)), True)
        self.assertEqual('6' in map(lambda x: x.value, iter(vocab)), False)

    def test_len(self):
        vocab = self.makeVocabulary()
        self.assertEqual(vocab.__len__(), 4)
        self.assertEqual(len(vocab), 4)

    def test_getQuery(self):
        vocab = self.makeVocabulary()
        self.assertEqual(vocab.getQuery(), None)

    def test_getTerm(self):
        vocab = self.makeVocabulary()
        self.assertEqual(vocab.getTerm('1').value, '1')
        self.assertEqual(vocab.getTerm('1').title, 'one')
        self.assertRaises(KeyError, vocab.getTerm, ('6',))

    def test_getTermByToken(self):
        vocab = self.makeVocabulary()
        self.assertEqual(vocab.getTermByToken('1').value, '1')
        self.assertEqual(vocab.getTermByToken('1').title, 'one')
        self.assertRaises(KeyError, vocab.getTermByToken, ('6',))

    def test_add(self):
        vocab = self.makeVocabulary()
        vocab.add('5', 'five')
        self.assertEqual(vocab.getTerm('5').value, '5')
        self.assertEqual(vocab.getTerm('5').title, 'five')

    def test_delete(self):
        vocab = self.makeVocabulary()
        vocab.delete('4')
        self.assertRaises(KeyError, vocab.getTerm, ('4',))
    

class StatusVocabularyTest(ManagableVocabularyBaseTest, unittest.TestCase):

    def getVocabularyClass(self):
        return StatusVocabulary


class PriorityVocabularyTest(ManagableVocabularyBaseTest, unittest.TestCase):

    def getVocabularyClass(self):
        return PriorityVocabulary


class ReleaseVocabularyTest(ManagableVocabularyBaseTest, unittest.TestCase):

    def getVocabularyClass(self):
        return ReleaseVocabulary


class BugTypeVocabularyTest(ManagableVocabularyBaseTest, unittest.TestCase):

    def getVocabularyClass(self):
        return BugTypeVocabulary


class SimpleTermTest(unittest.TestCase):

    def setUp(self):
        self.term = SimpleTerm('foo', 'bar')

    def test_Interface(self):
        self.failUnless(ITokenizedTerm.isImplementedBy(self.term))

    def test_token(self):
        self.assertEqual(self.term.token, 'foo')
        self.assertEqual(self.term.getToken(), 'foo')

    def test_value_title(self):
        self.assertEqual(self.term.value, 'foo')
        self.assertEqual(self.term.title, 'bar')


class UserTermTest(unittest.TestCase):

    def setUp(self):
        principal = SimplePrincipal('srichter', 'blah', 'Stephan', 'Nothing') 
        principal.id = '0'
        self.term = UserTerm(principal)

    def test_Interface(self):
        self.failUnless(ITokenizedTerm.isImplementedBy(self.term))

    def test_token(self):
        self.assertEqual(self.term.token, '0')

    def test_value(self):
        self.assertEqual(self.term.value, '0')

    def test_principal(self):
        self.assertEqual(self.term.principal.id, '0')
        self.assertEqual(self.term.principal.login, 'srichter')
        self.assertEqual(self.term.principal.title, 'Stephan')


class UserVocabularyTest(PlacelessSetup, unittest.TestCase):

    def setUp(self):
        PlacelessSetup.setUp(self)
        defineService('Authentication', IAuthenticationService)
        service = AuthenticationService()
        service.setObject('0', User('0', 'title0', 'desc0', 'zero', 'pass0'))
        service.setObject('1', User('1', 'title1', 'desc1', 'one', 'pass1'))
        service.setObject('2', User('2', 'title2', 'desc2', 'two', 'pass2'))
        serviceManager.provideService('Authentication', service)

        self.vocab = UserVocabulary(None)

    def test_contains(self):
        self.assertEqual(self.vocab.__contains__('0'), True)
        self.assertEqual(self.vocab.__contains__('3'), False)

    def test_iter(self):
        vocab = self.vocab
        self.assertEqual('0' in map(lambda x: x.value, vocab.__iter__()), True)
        self.assertEqual('3' in map(lambda x: x.value, vocab.__iter__()), False)
        self.assertEqual('0' in map(lambda x: x.value, iter(vocab)), True)
        self.assertEqual('3' in map(lambda x: x.value, iter(vocab)), False)

    def test_len(self):
        self.assertEqual(self.vocab.__len__(), 3)
        self.assertEqual(len(self.vocab), 3)

    def test_getQuery(self):
        self.assertEqual(self.vocab.getQuery(), None)

    def test_getTerm(self):
        self.assertEqual(self.vocab.getTerm('1').value, '1')
        self.assertEqual(self.vocab.getTerm('1').principal.getLogin(), 'one')
        self.assertRaises(KeyError, self.vocab.getTerm, ('3',))

    def test_getTermByToken(self):
        vocab = self.vocab
        self.assertEqual(vocab.getTermByToken('1').value, '1')
        self.assertEqual(vocab.getTermByToken('1').principal.getLogin(), 'one')
        self.assertRaises(KeyError, vocab.getTermByToken, ('3',))


def test_suite():
    return unittest.TestSuite((
        unittest.makeSuite(SimpleTermTest),
        unittest.makeSuite(StatusVocabularyTest),
        unittest.makeSuite(PriorityVocabularyTest),
        unittest.makeSuite(ReleaseVocabularyTest),
        unittest.makeSuite(BugTypeVocabularyTest),
        unittest.makeSuite(UserTermTest),
        unittest.makeSuite(UserVocabularyTest),
        ))

if __name__ == '__main__':
    unittest.main()