[Zope3-checkins] CVS: Products3/bugtracker/tests - placelesssetup.py:1.2 test_bug.py:1.2 test_tracker.py:1.5 test_vocabularies.py:1.3 test_xmlexportimport.py:1.4 test_xmlrpc.py:1.3 tracker.xml:1.2

Stephan Richter srichter@cosmos.phy.tufts.edu
Mon, 28 Jul 2003 13:13:56 -0400


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

Modified Files:
	placelesssetup.py test_bug.py test_tracker.py 
	test_vocabularies.py test_xmlexportimport.py test_xmlrpc.py 
	tracker.xml 
Log Message:
I dunno what bit me, but I thought that having numeric bug ids would be 
better. It turns out that a lot of the Zope 3 machinery depends on the 
names being strings, so I useually convert the names to strings anyway.
Oh well.

I also implemented default values for the vocabularies. Updated the export/
import accordingly.


=== Products3/bugtracker/tests/placelesssetup.py 1.1 => 1.2 ===
--- Products3/bugtracker/tests/placelesssetup.py:1.1	Mon Jul 28 06:21:12 2003
+++ Products3/bugtracker/tests/placelesssetup.py	Mon Jul 28 13:13:48 2003
@@ -39,12 +39,16 @@
 from zope.component.adapter import provideAdapter
 from zope.component.service import defineService, serviceManager
 from zope.component.tests.placelesssetup import PlacelessSetup as ComponentSetup
+from zope.app.context import ContextWrapper
 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.interfaces import IBug, IBugTracker
+from zopeproducts.bugtracker.interfaces import IBugDependencies
+from zopeproducts.bugtracker.interfaces import \
+  IStatusVocabulary, IPriorityVocabulary, IBugTypeVocabulary, IReleaseVocabulary
 from zopeproducts.bugtracker.tracker import BugTracker
 from zopeproducts.bugtracker.vocabulary import \
      StatusVocabulary, PriorityVocabulary, BugTypeVocabulary, ReleaseVocabulary
@@ -72,6 +76,11 @@
         provideAdapter(None, ITraverser, Traverser)
         provideAdapter(None, ITraversable, DefaultTraversable)
 
+        provideAdapter(IBugTracker, IStatusVocabulary, StatusVocabulary)
+        provideAdapter(IBugTracker, IPriorityVocabulary, PriorityVocabulary)
+        provideAdapter(IBugTracker, IReleaseVocabulary, ReleaseVocabulary)
+        provideAdapter(IBugTracker, IBugTypeVocabulary, BugTypeVocabulary)
+
         registry = getVocabularyRegistry()
         registry.register('Stati', StatusVocabulary)
         registry.register('Priorities', PriorityVocabulary)
@@ -87,8 +96,31 @@
         principalRegistry.definePrincipal(2, 'Jim Fulton', '',
                                           'jim', 'bar')
 
+
+    def generateTracker(self):
+        tracker = ContextWrapper(BugTracker(), Root(), name="tracker")
+        vocab = getAdapter(tracker, IStatusVocabulary)
+        vocab.add('new', u'New', True)
+        vocab.add('open', u'Open')
+        vocab.add('assigned', u'Assigned')
+        vocab.add('deferred', u'Deferred')
+        vocab.add('closed', u'Closed')
+        vocab = getAdapter(tracker, IBugTypeVocabulary)
+        vocab.add('bug', u'Bug', True)
+        vocab.add('feature', u'Feature')
+        vocab.add('release', u'Release')
+        vocab = getAdapter(tracker, IReleaseVocabulary)
+        vocab.add('None', u'(not specified)', True)
+        vocab.add('zope_x3', u'Zope X3')
+        vocab = getAdapter(tracker, IPriorityVocabulary)
+        vocab.add('low', u'Low')
+        vocab.add('normal', u'Normal', True)
+        vocab.add('urgent', u'Urgent')
+        vocab.add('critical', u'Critical')
+        return tracker
+        
     def generateBug(self, id=1):
-        bug = Bug()
+        bug = ContextWrapper(Bug(), self.generateTracker(), name=id)
         bug.title = u'Bug %i' %id
         bug.description = u'This is Bug %i.' %id
         dc = getAdapter(bug, IZopeDublinCore)


=== Products3/bugtracker/tests/test_bug.py 1.1 => 1.2 ===
--- Products3/bugtracker/tests/test_bug.py:1.1	Thu Jul 24 14:08:38 2003
+++ Products3/bugtracker/tests/test_bug.py	Mon Jul 28 13:13:48 2003
@@ -17,14 +17,8 @@
 """
 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 zope.app.context import ContextWrapper
+from zopeproducts.bugtracker.tests.placelesssetup import PlacelessSetup
 from zopeproducts.bugtracker.interfaces import IBug
 from zopeproducts.bugtracker.bug import Bug
 
@@ -34,14 +28,9 @@
 
     def setUp(self):
         PlacelessSetup.setUp(self)
-        classImplements(Bug, IAttributeAnnotatable)
-        provideAdapter(IAttributeAnnotatable, IAnnotations,
-                       AttributeAnnotations)
-        provideAdapter(IAttributeAnnotatable, IWriteZopeDublinCore,
-                       ZDCAnnotatableAdapter)
 
     def getBug(self):
-        return Bug()
+        return ContextWrapper(Bug(), self.generateTracker(), name=id)
 
     def test_Interface(self):
         self.failUnless(IBug.isImplementedBy(self.getBug()))
@@ -88,8 +77,8 @@
     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')
+        bug.release = u'zope_x3'
+        self.assertEqual(bug.release, u'zope_x3')
 
     def test_submitter(self):
         bug = self.getBug()


=== Products3/bugtracker/tests/test_tracker.py 1.4 => 1.5 ===
--- Products3/bugtracker/tests/test_tracker.py:1.4	Mon Jul 28 07:49:44 2003
+++ Products3/bugtracker/tests/test_tracker.py	Mon Jul 28 13:13:48 2003
@@ -48,7 +48,7 @@
             bug = Bug()
             bug.title = u"Bug %i" %name
             bug.description = u"This is bug %i." %name
-            data.append((name+1, bug))
+            data.append((str(name+1), bug))
         return data
 
     def getUnknownKey(self):


=== Products3/bugtracker/tests/test_vocabularies.py 1.2 => 1.3 ===
--- Products3/bugtracker/tests/test_vocabularies.py:1.2	Sat Jul 26 09:40:49 2003
+++ Products3/bugtracker/tests/test_vocabularies.py	Mon Jul 28 13:13:48 2003
@@ -27,13 +27,19 @@
 from zope.component.adapter import provideAdapter
 from zope.component.service import defineService, serviceManager
 from zope.component.tests.placelesssetup import PlacelessSetup
+from zope.context import ContextProperty
 from zope.interface import classImplements, implements
 from zope.schema.interfaces import ITokenizedTerm
+from zope.schema.vocabulary import getVocabularyRegistry
 from zopeproducts.bugtracker.interfaces import IManagableVocabulary
+from zopeproducts.bugtracker.interfaces import IBugTracker
 from zopeproducts.bugtracker.tracker import BugTracker
 from zopeproducts.bugtracker.vocabulary import SimpleTerm, \
      StatusVocabulary, PriorityVocabulary, BugTypeVocabulary, ReleaseVocabulary
 from zopeproducts.bugtracker.vocabulary import UserTerm, UserVocabulary
+from zopeproducts.bugtracker.vocabulary import ManagableVocabulary
+from zopeproducts.bugtracker.vocabulary import \
+     VocabularyPropertyGetter, VocabularyPropertySetter
 
 
 class Root(object):
@@ -59,6 +65,7 @@
                 '3': SimpleTerm('3', u'three'),
                 '4': SimpleTerm('4', u'four')}
         vocab.context.__annotations__[vocab.key] = data
+        vocab.context.__annotations__[vocab.key+'/default'] = '1'
         return vocab
 
     def test_contains(self):
@@ -99,11 +106,27 @@
         vocab.add('5', 'five')
         self.assertEqual(vocab.getTerm('5').value, '5')
         self.assertEqual(vocab.getTerm('5').title, 'five')
+        vocab.add('6', 'six', True)
+        self.assertEqual(vocab.getTerm('6').value, '6')
+        self.assertEqual(vocab.getTerm('6').title, 'six')
+        self.assertEqual(vocab.default.value, '6')
+        self.assertEqual(vocab.default.title, 'six')
 
     def test_delete(self):
         vocab = self.makeVocabulary()
         vocab.delete('4')
         self.assertRaises(KeyError, vocab.getTerm, ('4',))
+        vocab.default = '2'
+        self.assertRaises(ValueError, vocab.delete, '2')
+
+    def test_default(self):
+        vocab = self.makeVocabulary()
+        vocab.default = '4'
+        self.assertEqual(vocab.default.value, '4')
+        self.assertEqual(vocab.default.title, 'four')
+        vocab.default = vocab.getTerm('3')
+        self.assertEqual(vocab.default.value, '3')
+        self.assertEqual(vocab.default.title, 'three')
     
 
 class StatusVocabularyTest(ManagableVocabularyBaseTest, unittest.TestCase):
@@ -212,6 +235,58 @@
         self.assertRaises(KeyError, vocab.getTermByToken, ('3',))
 
 
+class SampleVocabulary(ManagableVocabulary):
+    key = 'vocab/values'
+    interface = IBugTracker
+    title = 'Vocabulary'
+
+class SampleObject(object):
+
+    sample = ContextProperty(VocabularyPropertyGetter('_sample', 'Vocabs'),
+                             VocabularyPropertySetter('_sample', 'Vocabs'))
+    
+
+class ManagableVocabularyBaseTest(PlacelessSetup, unittest.TestCase):
+
+    def setUp(self):
+        PlacelessSetup.setUp(self)
+        classImplements(BugTracker, IAttributeAnnotatable)
+        provideAdapter(IAttributeAnnotatable, IAnnotations,
+                       AttributeAnnotations)
+        registry = getVocabularyRegistry()
+        registry.register('Vocabs', SampleVocabulary)
+
+        tracker = ContextWrapper(BugTracker(), Root(), name="tracker")
+        vocab = SampleVocabulary(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
+        vocab.context.__annotations__[vocab.key+'/default'] = '1'
+        self.tracker = tracker
+
+    def getObject(self):
+        return ContextWrapper(SampleObject(), self.tracker, name="1")
+
+    def test_getter(self):
+        obj = self.getObject()
+        self.assertEqual(obj.sample, '1')
+        obj._sample = '2'
+        self.assertEqual(obj.sample, '2')
+
+    def test_setter(self):
+        obj = self.getObject()
+        obj.sample = '2'
+        self.assertEqual(obj.sample, '2')
+        try:
+            obj.sample = '7'
+            self.failIf(True)
+        except ValueError:
+            pass
+
+
 def test_suite():
     return unittest.TestSuite((
         unittest.makeSuite(SimpleTermTest),
@@ -221,6 +296,7 @@
         unittest.makeSuite(BugTypeVocabularyTest),
         unittest.makeSuite(UserTermTest),
         unittest.makeSuite(UserVocabularyTest),
+        unittest.makeSuite(ManagableVocabularyBaseTest),
         ))
 
 if __name__ == '__main__':


=== Products3/bugtracker/tests/test_xmlexportimport.py 1.3 => 1.4 ===
--- Products3/bugtracker/tests/test_xmlexportimport.py:1.3	Mon Jul 28 06:21:12 2003
+++ Products3/bugtracker/tests/test_xmlexportimport.py	Mon Jul 28 13:13:48 2003
@@ -91,14 +91,15 @@
     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_('<term value="new" title="New" default=""/>' 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_('<term value="low" title="Low" default=""/>' in self.xml)
         self.assert_('<vocabulary name="BugTypes">' in self.xml)
-        self.assert_('<term value="bug" title="Bug"/>' in self.xml)
+        self.assert_('<term value="bug" title="Bug" default=""/>' in self.xml)
         self.assert_('<vocabulary name="Releases">' in self.xml)
-        self.assert_('<term value="None" title="(not specified)"/>' in self.xml)
+        self.assert_(
+          '<term value="None" title="(not specified)" default=""/>' in self.xml)
 
     def test_bug(self):
         self.assert_('id="1"' in self.xml)


=== Products3/bugtracker/tests/test_xmlrpc.py 1.2 => 1.3 ===
--- Products3/bugtracker/tests/test_xmlrpc.py:1.2	Mon Jul 28 07:49:44 2003
+++ Products3/bugtracker/tests/test_xmlrpc.py	Mon Jul 28 13:13:48 2003
@@ -38,14 +38,14 @@
     def setUp(self):
         PlacelessSetup.setUp(self)
 
-        tracker = ContextWrapper(BugTracker(), Root(), name="tracker")
+        tracker = ContextWrapper(self.generateTracker(), 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])
+        self.assertEqual(list(self.methods.getBugNames()), ['1', '2'])
 
     def test_addBug(self):
         self.methods.addBug(u'Bug 3', u'This is bug 3.')
@@ -59,7 +59,7 @@
 
     def test_deleteBug(self):
         self.methods.deleteBug(2)
-        self.assertEqual(list(self.tracker), [1])
+        self.assertEqual(list(self.tracker), ['1'])
 
 
 class BugMethodsTest(PlacelessSetup, unittest.TestCase):
@@ -84,10 +84,10 @@
         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.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')
+        self.assertEqual(self.bug.release, 'zope_x3')
         
     def test_getCommentNames(self):
         self.assertEqual(self.methods.getCommentNames(), ['comment1'])


=== Products3/bugtracker/tests/tracker.xml 1.1 => 1.2 ===
--- Products3/bugtracker/tests/tracker.xml:1.1	Sat Jul 26 09:40:49 2003
+++ Products3/bugtracker/tests/tracker.xml	Mon Jul 28 13:13:48 2003
@@ -4,17 +4,17 @@
   <vocabularies>
     <vocabulary name="Stati">
       <term value="closed" title="Closed"/>
-      <term value="new" title="New"/>
+      <term value="new" title="New" default=""/>
     </vocabulary>
     <vocabulary name="Priorities">
       <term value="urgent" title="Urgent"/>
-      <term value="low" title="Low"/>
+      <term value="low" title="Low" default=""/>
     </vocabulary>
     <vocabulary name="BugTypes">
-      <term value="bug" title="Bug"/>
+      <term value="bug" title="Bug" default=""/>
     </vocabulary>
     <vocabulary name="Releases">
-      <term value="None" title="(not specified)"/>
+      <term value="None" title="(not specified)" default=""/>
     </vocabulary>
   </vocabularies>