[Zope3-checkins] CVS: zopeproducts/bugtracker/tests - test_xmlexportimport.py:1.1 tracker.xml:1.1 test_tracker.py:1.2 test_vocabularies.py:1.2

Stephan Richter srichter@cosmos.phy.tufts.edu
Sat, 26 Jul 2003 09:40:55 -0400


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

Modified Files:
	test_tracker.py test_vocabularies.py 
Added Files:
	test_xmlexportimport.py tracker.xml 
Log Message:
- Added XML Export/Import capabilities

- User Vocabularies now only store informational data about the principal,
  since exposing the entire principal is just too dangerous.

- Made Bug Tracker title the same attribute at the DC title and corrected
  permissions.


=== Added File zopeproducts/bugtracker/tests/test_xmlexportimport.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.
#
##############################################################################
"""XML Export/Import Tests

$Id: test_xmlexportimport.py,v 1.1 2003/07/26 13:40:49 srichter Exp $
"""
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.traversing import IContainmentRoot
from zope.app.interfaces.traversing import ITraversable, IPhysicallyLocatable
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.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.tracker import BugTracker
from zopeproducts.bugtracker.vocabulary import \
     StatusVocabulary, PriorityVocabulary, BugTypeVocabulary, ReleaseVocabulary


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)
        
        tracker = ContextWrapper(BugTracker(), Root(), name='tracker')
        file = os.path.join(os.path.split(tests.__file__)[0], 'tracker.xml')
        XMLImport(tracker).processXML(open(file))
        self.tracker = tracker

    def test_properties(self):
        tracker = self.tracker
        self.assertEqual(tracker.title, u'Bug Tracker')

    def test_bug(self):
        bug = self.tracker['1']
        self.assertEqual(bug.title, u'Bug 1')
        self.assertEqual(bug.submitter, u'anybody')
        self.assertEqual(bug.status, u'new')
        self.assertEqual(bug.priority, u'urgent')
        self.assertEqual(bug.type, u'bug')
        self.assertEqual(bug.release, u'None')
        self.assertEqual(bug.owners, [u'jim', u'srichter'])
        dc = getAdapter(bug, IZopeDublinCore)
        self.assertEqual(dc.created, parseDatetimetz(u'2003-01-01T23:00:00'))
        self.assertEqual(dc.modified, parseDatetimetz(u'2003-01-02T23:00:00'))
        self.assertEqual(bug.description, u'This is Bug 1.')

    def test_comment(self):
        comment = self.tracker['1']['comment1']
        dc = getAdapter(comment, IZopeDublinCore)
        self.assertEqual(dc.created, parseDatetimetz(u'2003-01-01T13:00:00'))
        self.assertEqual(dc.creators[0], 'srichter')
        self.assertEqual(comment.body, u'This is a comment.')

    def test_attach(self):
        attach = self.tracker['1']['document.gif']
        dc = getAdapter(attach, IZopeDublinCore)
        self.assertEqual(dc.created, parseDatetimetz(u'2003-01-01T14:00:00'))
        self.assertEqual(dc.creators[0], 'srichter')
        # Type was set to 'File'
        self.assert_(isinstance(attach, File))


class ExportTest(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)
        provideAdapter(None, ITraversable, DefaultTraversable)



        registry = getVocabularyRegistry()
        registry.register('Stati', StatusVocabulary)
        registry.register('Priorities', PriorityVocabulary)
        registry.register('BugTypes', BugTypeVocabulary)
        registry.register('Releases', ReleaseVocabulary)
        
        tracker = ContextWrapper(BugTracker(), Root(), name='tracker')
        file = os.path.join(os.path.split(tests.__file__)[0], 'tracker.xml')
        XMLImport(tracker).processXML(open(file))
        self.xml = XMLExport(tracker).getXML()

    def test_bugtracker(self):
        self.assert_('<bugtracker version="1.0" title="Bug Tracker">' in
                     self.xml)

    def test_vocabulary(self):
        self.assert_('<vocabulary name="Stati">' in self.xml)
        self.assert_('<term value="closed" title="Closed"/>' in self.xml)
        self.assert_('<term value="new" title="New"/>' in self.xml)
        self.assert_('<vocabulary name="Priorities">' in self.xml)
        self.assert_('<term value="urgent" title="Urgent"/>' in self.xml)
        self.assert_('<term value="low" title="Low"/>' in self.xml)
        self.assert_('<vocabulary name="BugTypes">' in self.xml)
        self.assert_('<term value="bug" title="Bug"/>' in self.xml)
        self.assert_('<vocabulary name="Releases">' in self.xml)
        self.assert_('<term value="None" title="(not specified)"/>' in self.xml)

    def test_bug(self):
        self.assert_('id="1"' in self.xml)
        self.assert_('title="Bug 1"' in self.xml)
        self.assert_('submitter="anybody"' in self.xml)
        self.assert_('status="new"' in self.xml)
        self.assert_('priority="urgent"' in self.xml)
        self.assert_('type="bug"' in self.xml)
        self.assert_('release="None' in self.xml)
        self.assert_('owners="jim, srichter' in self.xml)
        self.assert_('dependencies=""' in self.xml)
        self.assert_('created="Jan 1, 2003 11:00:00 PM "' in self.xml)
        self.assert_('modified="Jan 2, 2003 11:00:00 PM "' in self.xml)
        self.assert_('<description>\nThis is Bug 1.\n      </description>' in
                     self.xml)

    def test_comment(self):
        self.assert_('id="comment1"' in self.xml)
        self.assert_('created="Jan 1, 2003 1:00:00 PM "' in self.xml)
        self.assert_('creator="srichter"' in self.xml)
        self.assert_('>\nThis is a comment.\n        </comment>' in self.xml)

    def test_attachment(self):
        self.assert_('id="document.gif"' in self.xml)
        self.assert_('created="Jan 1, 2003 2:00:00 PM "' in self.xml)
        self.assert_('creator="srichter"' in self.xml)
        self.assert_('type="File"' in self.xml)
        

def test_suite():
    return unittest.TestSuite((
        unittest.makeSuite(ImportTest),
        unittest.makeSuite(ExportTest),
        ))

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


=== Added File zopeproducts/bugtracker/tests/tracker.xml ===
<?xml version="1.0"?>
<bugtracker version="1.0" title="Bug Tracker">

  <vocabularies>
    <vocabulary name="Stati">
      <term value="closed" title="Closed"/>
      <term value="new" title="New"/>
    </vocabulary>
    <vocabulary name="Priorities">
      <term value="urgent" title="Urgent"/>
      <term value="low" title="Low"/>
    </vocabulary>
    <vocabulary name="BugTypes">
      <term value="bug" title="Bug"/>
    </vocabulary>
    <vocabulary name="Releases">
      <term value="None" title="(not specified)"/>
    </vocabulary>
  </vocabularies>

  <bugs>
    <bug id="1" title="Bug 1" submitter="anybody"
         status="new" priority="urgent" type="bug"
         release="None" owners="jim, srichter" dependencies=""
         created="Jan 1, 2003 11:00:00 PM "
         modified="Jan 2, 2003 11:00:00 PM ">

      <description>
This is Bug 1.
      </description>

      <comments>
        <comment created="Jan 1, 2003 1:00:00 PM "
                 id="comment1" creator="srichter">
This is a comment.
        </comment>
      </comments>

      <attachments>
        <attachment created="Jan 1, 2003 2:00:00 PM "
                    type="File" id="document.gif"
                    creator="srichter">R0lGODlhEAAQAOYAAP///////v39/vz9/fr7/Pj7+/f5+vb5+vX4+fP2+PL29/L19/D09vD09e/z
9e3y9Ovx8+rv8env8uju8ebt8OXt7+Ts7+Pr7eLq7uHq7d/o7N7o693n6tzm6tvl6dvk6dnk6Njk
59fi5tXh5tTg5dPg5dLf49Hf5NDd48/d4s/c4c7c4c3c4c3c4Mva38ra4MnZ38nY3sjY3cfY3cbX
3cbX3MTW3MTV28PU2sLU2sLT2cHT2cDS2b/R2L3R2L3Q17zP17vP1rvO1brO1bnN1LjN1LbM1LbL
07XL0rTK0bPJ0bLI0LHH0LDHz6/Gzq7Ezq3EzavDzKnCy6jByqbAyaS+yKK9x6C7xZ66xJu/zJi2
wY2uukZncwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACwA
AAAAEAAQAAAHmoAAgoOEhYRbiImIXIYAW4IBAwYLj4yFjwAECAwQmJaDWwIFCQ4RFVtcqZ+OBwoP
ExcbIFm0q1sNEBQZHSImLDJZthIWGh8jKC41OsGHGBwhJSowNjxCzKAeIictMzg+REnXglskKS81
O0BGS0/ijisxNz1DSE1RVO5bNDk/RUpOUqpcybcjyBEmUKZYwaIlH62HEN2pmkgRQCAAOw==
</attachment>
      </attachments>

    </bug>
  </bugs>

</bugtracker>


=== zopeproducts/bugtracker/tests/test_tracker.py 1.1 => 1.2 ===
--- zopeproducts/bugtracker/tests/test_tracker.py:1.1	Thu Jul 24 14:08:38 2003
+++ zopeproducts/bugtracker/tests/test_tracker.py	Sat Jul 26 09:40:49 2003
@@ -17,17 +17,32 @@
 """
 import unittest
 
+from zope.app.attributeannotations import AttributeAnnotations
 from zope.app.component.tests.test_servicemanagercontainer \
      import BaseTestServiceManagerContainer
+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
+from zope.interface import classImplements
 
 from zopeproducts.bugtracker.interfaces import IBugTracker
 from zopeproducts.bugtracker.tracker import BugTracker
 
 
-class TrackerTest(BaseTestIContainer, BaseTestServiceManagerContainer, 
-                  unittest.TestCase):
+class TrackerTest(PlacelessSetup, BaseTestIContainer,
+                  BaseTestServiceManagerContainer, unittest.TestCase):
+
+    def setUp(self):
+        PlacelessSetup.setUp(self)
+        classImplements(BugTracker, IAttributeAnnotatable)
+        provideAdapter(IAttributeAnnotatable, IAnnotations,
+                       AttributeAnnotations)
+        provideAdapter(IAttributeAnnotatable, IWriteZopeDublinCore,
+                       ZDCAnnotatableAdapter)
 
     def makeTestObject(self):
         return BugTracker()


=== zopeproducts/bugtracker/tests/test_vocabularies.py 1.1 => 1.2 ===
--- zopeproducts/bugtracker/tests/test_vocabularies.py:1.1	Thu Jul 24 14:08:38 2003
+++ zopeproducts/bugtracker/tests/test_vocabularies.py	Sat Jul 26 09:40:49 2003
@@ -164,9 +164,9 @@
         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')
+        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):
@@ -202,13 +202,13 @@
 
     def test_getTerm(self):
         self.assertEqual(self.vocab.getTerm('1').value, '1')
-        self.assertEqual(self.vocab.getTerm('1').principal.getLogin(), 'one')
+        self.assertEqual(self.vocab.getTerm('1').principal['login'], '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.assertEqual(vocab.getTermByToken('1').principal['login'], 'one')
         self.assertRaises(KeyError, vocab.getTermByToken, ('3',))