[Zope3-checkins] CVS: Products3/bugtracker/tests - placelesssetup.py:1.1 test_xmlrpc.py:1.1 test_dependencies.py:1.2 test_tracker.py:1.3 test_xmlexportimport.py:1.3

Stephan Richter srichter@cosmos.phy.tufts.edu
Mon, 28 Jul 2003 06:21:20 -0400


Update of /cvs-repository/Products3/bugtracker/tests
In directory cvs.zope.org:/tmp/cvs-serv8367/tests

Modified Files:
	test_dependencies.py test_tracker.py test_xmlexportimport.py 
Added Files:
	placelesssetup.py test_xmlrpc.py 
Log Message:
- Since it takes a lot of code to setup bug tracker tests, I moved that
  initialization to placelessetup and corrected the tests for it.

- Implemented XML-RPC methods for possible mail-in feature. Wouldn't it be 
  neat if you could send an E-mail as follows:

Title: Bug 231 - Add Comment

This is the comment...


=== Added File Products3/bugtracker/tests/placelesssetup.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 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 System PlacelessSetup

Since it requires **a lot** of basic setup for the simplest integration unit
tests between Bug Tracker and Bu, a seperate setup mixin seems very
appropriate.

$Id: placelesssetup.py,v 1.1 2003/07/28 10:21:12 srichter Exp $
"""
from datetime import datetime

from zope.app.attributeannotations import AttributeAnnotations
from zope.app.content.file import File
from zope.app.dublincore.annotatableadapter import ZDCAnnotatableAdapter
from zope.app.event.tests.placelesssetup import PlacelessSetup as EventSetup
from zope.app.interfaces.annotation import IAnnotations, IAttributeAnnotatable
from zope.app.interfaces.dublincore import IWriteZopeDublinCore
from zope.app.interfaces.dublincore import IZopeDublinCore
from zope.app.interfaces.security import IAuthenticationService
from zope.app.interfaces.traversing import IContainmentRoot, ITraverser
from zope.app.interfaces.traversing import ITraversable, IPhysicallyLocatable
from zope.app.security.registries.principalregistry import principalRegistry
from zope.app.services.servicenames import Authentication
from zope.app.traversing.adapters import DefaultTraversable, Traverser
from zope.app.traversing.adapters import WrapperPhysicallyLocatable
from zope.component import getAdapter
from zope.component.adapter import provideAdapter
from zope.component.service import defineService, serviceManager
from zope.component.tests.placelesssetup import PlacelessSetup as ComponentSetup
from zope.interface import classImplements, implements
from zope.schema.vocabulary import getVocabularyRegistry

from zopeproducts.bugtracker.bug import Bug, BugDependencyAdapter
from zopeproducts.bugtracker.comment import Comment
from zopeproducts.bugtracker.interfaces import IBug, IBugDependencies
from zopeproducts.bugtracker.tracker import BugTracker
from zopeproducts.bugtracker.vocabulary import \
     StatusVocabulary, PriorityVocabulary, BugTypeVocabulary, ReleaseVocabulary
from zopeproducts.bugtracker.vocabulary import UserVocabulary


class Root(object):
    implements(IContainmentRoot)

class PlacelessSetup(ComponentSetup, EventSetup):

    def setUp(self):
        ComponentSetup.setUp(self)
        EventSetup.setUp(self)
        classImplements(Bug, IAttributeAnnotatable)
        classImplements(BugTracker, IAttributeAnnotatable)
        classImplements(Comment, IAttributeAnnotatable)
        classImplements(File, IAttributeAnnotatable)
        provideAdapter(IAttributeAnnotatable, IAnnotations,
                       AttributeAnnotations)
        provideAdapter(IAttributeAnnotatable, IWriteZopeDublinCore,
                       ZDCAnnotatableAdapter)
        provideAdapter(IBug, IBugDependencies, BugDependencyAdapter)
        provideAdapter(None, IPhysicallyLocatable, WrapperPhysicallyLocatable)
        provideAdapter(None, ITraverser, Traverser)
        provideAdapter(None, ITraversable, DefaultTraversable)

        registry = getVocabularyRegistry()
        registry.register('Stati', StatusVocabulary)
        registry.register('Priorities', PriorityVocabulary)
        registry.register('BugTypes', BugTypeVocabulary)
        registry.register('Releases', ReleaseVocabulary)
        registry.register('Users', UserVocabulary)

        defineService(Authentication, IAuthenticationService)
        serviceManager.provideService(Authentication, principalRegistry)

        principalRegistry.definePrincipal(1, 'Stephan Richter', '',
                                          'srichter', 'foo')
        principalRegistry.definePrincipal(2, 'Jim Fulton', '',
                                          'jim', 'bar')

    def generateBug(self, id=1):
        bug = Bug()
        bug.title = u'Bug %i' %id
        bug.description = u'This is Bug %i.' %id
        dc = getAdapter(bug, IZopeDublinCore)
        dc.created = datetime(2003, 03, 02+id, 03, 00, 00)
        dc.created = datetime(2003, 03, 02+id, 04, 00, 00)
        dc.creators = [u'srichter']
        comment = Comment()
        comment.body = 'This is comment 1.'
        bug.setObject('comment1', comment)
        attach = File()
        attach.data = 'This is an attachment.'
        bug.setObject('attach.txt', attach)
        return bug


=== Added File Products3/bugtracker/tests/test_xmlrpc.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 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.
#
##############################################################################
"""XML-RPC Representation Tests

$Id: test_xmlrpc.py,v 1.1 2003/07/28 10:21:12 srichter Exp $
"""
import unittest
import base64

from zope.app.interfaces.container import IContainer
from zope.app.interfaces.context import IZopeContextWrapper
from zope.app.container.zopecontainer import ZopeContainerDecorator
from zope.app.content.file import File
from zope.app.context import ContextWrapper
from zope.publisher.xmlrpc import TestRequest

from zopeproducts.bugtracker.bug import Bug
from zopeproducts.bugtracker.comment import Comment
from zopeproducts.bugtracker.tracker import BugTracker
from zopeproducts.bugtracker.tests.placelesssetup import PlacelessSetup, Root
from zopeproducts.bugtracker.xmlrpc import \
     BugTrackerMethods, BugMethods, CommentMethods, AttachmentMethods


class TrackerMethodsTest(PlacelessSetup, unittest.TestCase):

    def setUp(self):
        PlacelessSetup.setUp(self)

        tracker = ContextWrapper(BugTracker(), Root(), name="tracker")
        tracker.setObject('1', self.generateBug(1))
        tracker.setObject('2', self.generateBug(2))
        self.tracker = tracker
        self.methods = BugTrackerMethods(tracker, TestRequest())

    def test_getBugNames(self):
        self.assertEqual(list(self.methods.getBugNames()), ['1', '2'])

    def test_addBug(self):
        self.methods.addBug(u'Bug 3', u'This is bug 3.')
        self.assertEqual(self.tracker['3'].title, u'Bug 3')
        self.assertEqual(self.tracker['3'].description, u'This is bug 3.')
        self.assertEqual(self.tracker['3'].status, u'new')
        self.methods.addBug(u'Bug 4', u'This is bug 4.', owners=[u'jim'],
                            dependencies=['3'])
        self.assertEqual(self.tracker['4'].dependencies, [u'3'])
        self.assertEqual(self.tracker['4'].owners, [2])

    def test_deleteBug(self):
        self.methods.deleteBug('2')
        self.assertEqual(list(self.tracker), ['1'])


class BugMethodsTest(PlacelessSetup, unittest.TestCase):

    def setUp(self):
        PlacelessSetup.setUp(self)
        self.bug = self.generateBug(3)
        self.methods = BugMethods(self.bug, TestRequest())

    def test_getProperties(self):
        props = self.methods.getProperties()
        self.assertEqual(props['title'], 'Bug 3')
        self.assertEqual(props['description'], 'This is Bug 3.')
        self.assertEqual(props['type'], 'bug')
        self.assertEqual(props['status'], 'new')
        self.assertEqual(props['priority'], 'normal')
        self.assertEqual(props['release'], 'None')
        self.assertEqual(props['dependencies'], ())
        self.assertEqual(props['owners'], [])

    def test_setProperties(self):
        self.methods.setProperties(type='feature')
        self.assertEqual(self.bug.type, 'feature')
        self.assertEqual(self.bug.status, 'new')
        self.methods.setProperties(status='closed', release='zope_X3')
        self.assertEqual(self.bug.type, 'feature')
        self.assertEqual(self.bug.status, 'closed')
        self.assertEqual(self.bug.release, 'zope_X3')
        
    def test_getCommentNames(self):
        self.assertEqual(self.methods.getCommentNames(), ['comment1'])

    def test_addComment(self):
        self.methods.addComment('This is comment 2.')
        self.assertEqual(self.bug['comment2'].body, 'This is comment 2.')

    def test_deleteComment(self):
        self.methods.deleteComment('comment1')
        self.assert_('comment1' not in self.bug.keys())

    def test_addAttachment(self):
        self.methods.addAttachment('hw.txt',
                                   base64.encodestring('Hello World.'))
        self.assertEqual(self.bug['hw.txt'].data, 'Hello World.')

    def test_deleteAttachment(self):
        self.methods.deleteAttachment('attach.txt')
        self.assert_('attach.txt' not in self.bug.keys())


class CommentMethodsTest(PlacelessSetup, unittest.TestCase):

    def setUp(self):
        PlacelessSetup.setUp(self)
        self.comment = Comment()
        self.comment.body = 'Comment 1'
        self.methods = CommentMethods(self.comment, TestRequest())

    def test_getBody(self):
        self.assertEqual(self.methods.getBody(), 'Comment 1')

    def test_setBody(self):
        self.methods.setBody('C1')
        self.assertEqual(self.comment.body, 'C1')


class AttachmentMethodsTest(PlacelessSetup, unittest.TestCase):

    def setUp(self):
        PlacelessSetup.setUp(self)
        self.attach = File()
        self.attach.data = 'Data 1'
        self.methods = AttachmentMethods(self.attach, TestRequest())

    def test_getData(self):
        self.assertEqual(base64.decodestring(self.methods.getData()),
                         'Data 1')

    def test_setData(self):
        self.methods.setData(base64.encodestring('Data 1'))
        self.assertEqual(self.attach.data, 'Data 1')
        

def test_suite():
    return unittest.TestSuite((
        unittest.makeSuite(TrackerMethodsTest),
        unittest.makeSuite(BugMethodsTest),
        unittest.makeSuite(CommentMethodsTest),
        unittest.makeSuite(AttachmentMethodsTest),
        ))

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


=== Products3/bugtracker/tests/test_dependencies.py 1.1 => 1.2 ===
--- Products3/bugtracker/tests/test_dependencies.py:1.1	Thu Jul 24 14:08:38 2003
+++ Products3/bugtracker/tests/test_dependencies.py	Mon Jul 28 06:21:12 2003
@@ -64,21 +64,20 @@
         tracker = BugTracker()
 
         bug1 = Bug()
-        tracker.setObject('TopLevelBug', bug1)
-        wrapped_bug1 = ContextWrapper(bug1, tracker, name='TopLevelbug')
+        name1 = tracker.setObject('', bug1)
+        wrapped_bug1 = ContextWrapper(bug1, tracker, name=name1)
         deps1 = BugDependencyAdapter(wrapped_bug1)
-        deps1.dependencies = ('SecondLevelBug',)
 
         bug2 = Bug()
-        tracker.setObject('SecondLevelBug', bug2)
-        wrapped_bug2 = ContextWrapper(bug2, tracker, name='SecondLevelBug')
+        name2 = tracker.setObject('', bug2)
+        wrapped_bug2 = ContextWrapper(bug2, tracker, name=name2)
         deps2 = BugDependencyAdapter(wrapped_bug2)
-        deps2.dependencies = ('ThirdLevelBug',)
+        deps1.dependencies = (name2,)
 
         bug3 = Bug()
-        tracker.setObject('ThirdLevelBug', bug3)
-        wrapped_bug3 = ContextWrapper(bug3, tracker, name='ThirdLevelBug')
-        deps3 = BugDependencyAdapter(wrapped_bug3)
+        name3 = tracker.setObject('', bug3)
+        wrapped_bug3 = ContextWrapper(bug3, tracker, name=name3)
+        deps2.dependencies = (name3,)
 
         self.assertEqual(( (wrapped_bug2, ()), ),
                          deps1.findChildren(False));


=== Products3/bugtracker/tests/test_tracker.py 1.2 => 1.3 ===
--- Products3/bugtracker/tests/test_tracker.py:1.2	Sat Jul 26 09:40:49 2003
+++ Products3/bugtracker/tests/test_tracker.py	Mon Jul 28 06:21:12 2003
@@ -23,7 +23,6 @@
 from zope.app.dublincore.annotatableadapter import ZDCAnnotatableAdapter
 from zope.app.interfaces.annotation import IAnnotations, IAttributeAnnotatable
 from zope.app.interfaces.dublincore import IWriteZopeDublinCore
-from zope.app.container.tests.test_icontainer import BaseTestIContainer
 from zope.app.container.tests.test_icontainer import DefaultTestData
 from zope.component.adapter import provideAdapter
 from zope.component.tests.placelesssetup import PlacelessSetup
@@ -33,8 +32,8 @@
 from zopeproducts.bugtracker.tracker import BugTracker
 
 
-class TrackerTest(PlacelessSetup, BaseTestIContainer,
-                  BaseTestServiceManagerContainer, unittest.TestCase):
+class TrackerTest(PlacelessSetup, BaseTestServiceManagerContainer,
+                  unittest.TestCase):
 
     def setUp(self):
         PlacelessSetup.setUp(self)


=== Products3/bugtracker/tests/test_xmlexportimport.py 1.2 => 1.3 ===
--- Products3/bugtracker/tests/test_xmlexportimport.py:1.2	Sat Jul 26 18:46:46 2003
+++ Products3/bugtracker/tests/test_xmlexportimport.py	Mon Jul 28 06:21:12 2003
@@ -18,74 +18,24 @@
 import unittest, os
 from datetime import datetime
 
-from zope.app.attributeannotations import AttributeAnnotations
 from zope.app.content.file import File
 from zope.app.context import ContextWrapper
 from zope.app.datetimeutils import parseDatetimetz
-from zope.app.dublincore.annotatableadapter import ZDCAnnotatableAdapter
 from zope.app.interfaces.dublincore import IZopeDublinCore
-from zope.app.interfaces.annotation import IAnnotations, IAttributeAnnotatable
-from zope.app.interfaces.dublincore import IWriteZopeDublinCore
-from zope.app.interfaces.security import IAuthenticationService
-from zope.app.interfaces.traversing import IContainmentRoot
-from zope.app.interfaces.traversing import ITraversable, IPhysicallyLocatable
-from zope.app.security.registries.principalregistry \
-             import principalRegistry
-from zope.app.services.servicenames import Authentication
-from zope.app.traversing.adapters import DefaultTraversable
-from zope.app.traversing.adapters import WrapperPhysicallyLocatable
 from zope.component import getAdapter
-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.vocabulary import getVocabularyRegistry
 
 from zopeproducts.bugtracker import tests
 from zopeproducts.bugtracker.bug import Bug, BugDependencyAdapter
-from zopeproducts.bugtracker.comment import Comment
 from zopeproducts.bugtracker.exportimport import XMLExport, XMLImport
 from zopeproducts.bugtracker.interfaces import IBug, IBugDependencies
+from zopeproducts.bugtracker.tests.placelesssetup import PlacelessSetup, Root
 from zopeproducts.bugtracker.tracker import BugTracker
-from zopeproducts.bugtracker.vocabulary import \
-     StatusVocabulary, PriorityVocabulary, BugTypeVocabulary, ReleaseVocabulary
-from zopeproducts.bugtracker.vocabulary import UserVocabulary
 
 
-
-class Root(object):
-    implements(IContainmentRoot)
-
 class ImportTest(PlacelessSetup, unittest.TestCase):
 
     def setUp(self):
         PlacelessSetup.setUp(self)
-        classImplements(Bug, IAttributeAnnotatable)
-        classImplements(BugTracker, IAttributeAnnotatable)
-        classImplements(Comment, IAttributeAnnotatable)
-        classImplements(File, IAttributeAnnotatable)
-        provideAdapter(IAttributeAnnotatable, IAnnotations,
-                       AttributeAnnotations)
-        provideAdapter(IAttributeAnnotatable, IWriteZopeDublinCore,
-                       ZDCAnnotatableAdapter)
-        provideAdapter(IBug, IBugDependencies,
-                       BugDependencyAdapter)
-        provideAdapter(None, IPhysicallyLocatable, WrapperPhysicallyLocatable)
-        registry = getVocabularyRegistry()
-        registry.register('Stati', StatusVocabulary)
-        registry.register('Priorities', PriorityVocabulary)
-        registry.register('BugTypes', BugTypeVocabulary)
-        registry.register('Releases', ReleaseVocabulary)
-        registry.register('Users', UserVocabulary)
-
-        defineService(Authentication, IAuthenticationService)
-        serviceManager.provideService(Authentication, principalRegistry)
-
-        principalRegistry.definePrincipal(1, 'Stephan Richter', '',
-                                          'srichter', 'foo')
-        principalRegistry.definePrincipal(2, 'Jim Fulton', '',
-                                          'jim', 'bar')
-        
         tracker = ContextWrapper(BugTracker(), Root(), name='tracker')
         file = os.path.join(os.path.split(tests.__file__)[0], 'tracker.xml')
         XMLImport(tracker).processXML(open(file))
@@ -129,33 +79,6 @@
 
     def setUp(self):
         PlacelessSetup.setUp(self)
-        classImplements(Bug, IAttributeAnnotatable)
-        classImplements(BugTracker, IAttributeAnnotatable)
-        classImplements(Comment, IAttributeAnnotatable)
-        classImplements(File, IAttributeAnnotatable)
-        provideAdapter(IAttributeAnnotatable, IAnnotations,
-                       AttributeAnnotations)
-        provideAdapter(IAttributeAnnotatable, IWriteZopeDublinCore,
-                       ZDCAnnotatableAdapter)
-        provideAdapter(IBug, IBugDependencies, BugDependencyAdapter)
-        provideAdapter(None, IPhysicallyLocatable, WrapperPhysicallyLocatable)
-        provideAdapter(None, ITraversable, DefaultTraversable)
-
-        defineService(Authentication, IAuthenticationService)
-        serviceManager.provideService(Authentication, principalRegistry)
-
-        principalRegistry.definePrincipal(1, 'Stephan Richter', '',
-                                          'srichter', 'foo')
-        principalRegistry.definePrincipal(2, 'Jim Fulton', '',
-                                          'jim', 'bar')
-
-        registry = getVocabularyRegistry()
-        registry.register('Stati', StatusVocabulary)
-        registry.register('Priorities', PriorityVocabulary)
-        registry.register('BugTypes', BugTypeVocabulary)
-        registry.register('Releases', ReleaseVocabulary)
-        registry.register('Users', UserVocabulary)
-        
         tracker = ContextWrapper(BugTracker(), Root(), name='tracker')
         file = os.path.join(os.path.split(tests.__file__)[0], 'tracker.xml')
         XMLImport(tracker).processXML(open(file))