[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/DublinCore/tests - __init__.py:1.2 testZDCAnnotatableAdapter.py:1.2 testZopeDublinCore.py:1.2

Jim Fulton jim@zope.com
Fri, 4 Oct 2002 15:05:51 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/App/DublinCore/tests
In directory cvs.zope.org:/tmp/cvs-serv26302/lib/python/Zope/App/DublinCore/tests

Added Files:
	__init__.py testZDCAnnotatableAdapter.py testZopeDublinCore.py 
Log Message:

Added initial Dublin-Core meta-data support. This inclused a number of
interfaces, including:

  - Low level interfaces for reading and writing dublin core data in
    it's full generality, including qualifiers and repeated values.

  - A clone of the CMF DublinCore query interface with a wart fixed
    (having to do with a method that Tres and I agreed should have a
    sequence value but that has a scalar value in the CMF).

  - A number of small interfaces defining properties for common
    fields. (e.g. title, description, modified, properties).
   
Also included:

  - An adapter for managing Dublin-Core data on annotatable objects.

  - A first cut at a view for editing DC data on annotatable objects.
    This needs more thought. For example, perhaps subjects should come
    from a centralized vocabulary.

    For now, it just lets you edit title and description.

  - A pair of global event subscribers that catch creation and
    modification events and set the DC created and modified
    properties.

There's still a good bit left to do, including:

  - Sorting out how elements like type, identifier, format should be
    gotten. 

  - There should be some sort of framework for instructing the DC
    adapter to get and set some elements from the content. For
    example, some meta-data, like title or type, could simply mirror
    content data or methods.




=== Zope3/lib/python/Zope/App/DublinCore/tests/__init__.py 1.1 => 1.2 ===
--- /dev/null	Fri Oct  4 15:05:51 2002
+++ Zope3/lib/python/Zope/App/DublinCore/tests/__init__.py	Fri Oct  4 15:05:51 2002
@@ -0,0 +1,13 @@
+##############################################################################
+#
+# Copyright (c) 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.
+# 
+##############################################################################


=== Zope3/lib/python/Zope/App/DublinCore/tests/testZDCAnnotatableAdapter.py 1.1 => 1.2 ===
--- /dev/null	Fri Oct  4 15:05:51 2002
+++ Zope3/lib/python/Zope/App/DublinCore/tests/testZDCAnnotatableAdapter.py	Fri Oct  4 15:05:51 2002
@@ -0,0 +1,58 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""XXX short summary goes here.
+
+XXX longer description goes here.
+
+$Id$
+"""
+
+from unittest import TestCase, TestSuite, main, makeSuite
+from Zope.App.OFS.Annotation.IAnnotations import IAnnotations
+from Zope.App.tests.PlacelessSetup import PlacelessSetup
+
+class TestAnnotations(dict):
+
+    __implements__ = IAnnotations
+    
+
+class Test(PlacelessSetup, TestCase):
+
+    def testZDCAnnotatableAdapter(self):
+
+        from Zope.App.DublinCore.ZDCAnnotatableAdapter \
+             import ZDCAnnotatableAdapter
+
+        annotations = TestAnnotations()
+        dc = ZDCAnnotatableAdapter(annotations)
+
+        self.failIf(annotations, "There shouldn't be any data yet")
+        self.assertEqual(dc.title, u'')
+        self.failIf(annotations, "There shouldn't be any data yet")
+        dc.title = u"Test title"
+        self.failUnless(annotations, "There should be data now!")
+        
+        dc = ZDCAnnotatableAdapter(annotations)
+        self.assertEqual(dc.title, u'Test title')
+        
+        
+    
+
+def test_suite():
+    return TestSuite((
+        makeSuite(Test),
+        ))
+
+if __name__=='__main__':
+    main(defaultTest='test_suite')


=== Zope3/lib/python/Zope/App/DublinCore/tests/testZopeDublinCore.py 1.1 => 1.2 ===
--- /dev/null	Fri Oct  4 15:05:51 2002
+++ Zope3/lib/python/Zope/App/DublinCore/tests/testZopeDublinCore.py	Fri Oct  4 15:05:51 2002
@@ -0,0 +1,205 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""XXX short summary goes here.
+
+XXX longer description goes here.
+
+$Id$
+"""
+
+from unittest import TestCase, TestSuite, main, makeSuite
+
+class Test(TestCase):
+
+    def testImplementa(self):
+        from Interface.Verify import verifyObject
+        from Zope.App.DublinCore.IZopeDublinCore import IZopeDublinCore
+        verifyObject(IZopeDublinCore, self.dc)
+
+    def _Test__new(self):
+        from Zope.App.DublinCore.ZopeDublinCore import ZopeDublinCore
+        return ZopeDublinCore()
+
+    def setUp(self):
+        self.dc = self._Test__new()
+
+    def __testGetQualified(self, name, values):
+        ovalues = getattr(self.dc, 'getQualified'+name)()
+
+        ivalues = list(values)
+        ivalues.sort()
+        ovalues = list(ovalues)
+        ovalues.sort()
+        self.assertEqual(ovalues, ivalues)
+
+    def __testQualified(self, name,
+                        values = [
+                           (u'', u'blah blah'),
+                           (u'old', u'bleep bleep'),
+                           (u'old', u'bleep bleep \u1111'),
+                           (u'foo\u1111', u'bleep bleep'),
+                           ]
+                        ):
+        getattr(self.dc, 'setQualified'+name)(values)
+        self.__testGetQualified(name, values)
+
+    def testOtherQualified(self):
+        for name in ('Sources', 'Relations', 'Coverages'):
+            self.__testQualified(name)
+
+            
+    def testScalars(self):
+        for qname, mname, pname in (
+            ('Titles', 'Title', 'title'),
+            ('Descriptions', 'Description', 'description'),
+            ('Publishers', 'Publisher', 'publisher'),
+            ('Types', 'Type', 'type'),
+            ('Formats', 'Format', 'format'),
+            ('Identifiers', 'Identifier', 'identifier'),
+            ('Languages', 'Language', 'language'),
+            ('Rights', 'Rights', 'rights'),
+            ):
+            self.__testQualified(qname)
+            dc = self.dc
+            self.assertEqual(getattr(dc, pname), u'blah blah')
+            self.assertEqual(getattr(dc, mname)(), u'blah blah')
+
+            self.assertRaises(Exception, setattr, dc, pname, 'foo')
+            setattr(dc, pname, u'foo')
+            self.assertEqual(getattr(dc, pname), u'foo')
+            self.assertEqual(getattr(dc, mname)(), u'foo')
+            self.__testGetQualified(qname,
+                                    [
+                                       (u'', u'foo'),
+                                       (u'old', u'bleep bleep'),
+                                       (u'old', u'bleep bleep \u1111'),
+                                       (u'foo\u1111', u'bleep bleep'),
+                                       ]
+                                    )
+            
+    def testSequences(self):
+        for qname, mname, pname in (
+            ('Creators', 'Creator', 'creators'), 
+            ('Subjects', 'Subject', 'subjects'), 
+            ('Contributors', 'Contributors', 'contributors'), 
+            ):
+            self.__testQualified(qname, [
+                                           (u'', u'foo'),
+                                           (u'', u'bar'),
+                                           (u'', u'baz'),
+                                           (u'', u'baz\u1111'),
+                                           (u'old', u'bleep bleep'),
+                                           (u'old', u'bleep bleep \u1111'),
+                                           (u'foo\u1111', u'bleep bleep'),
+                                       ]
+                                 )
+            dc = self.dc
+
+            v = getattr(dc, pname)
+            v = list(v)
+            v.sort()
+            self.assertEqual(v, [u'bar', u'baz', u'baz\u1111', u'foo'])
+
+            v = getattr(dc, mname)()
+            v = list(v)
+            v.sort()
+            self.assertEqual(v, [u'bar', u'baz', u'baz\u1111', u'foo'])
+
+
+            self.assertRaises(Exception, setattr, dc, pname, 'foo')
+            self.assertRaises(Exception, setattr, dc, pname, ['foo'])
+
+            setattr(dc, pname, [u'high', u'low', u'spam', u'eggs', u'ham', ])
+
+            v = getattr(dc, pname)
+            v = list(v)
+            v.sort()
+            self.assertEqual(v, [u'eggs', u'ham', u'high', u'low', u'spam'])
+
+            v = getattr(dc, mname)()
+            v = list(v)
+            v.sort()
+            self.assertEqual(v, [u'eggs', u'ham', u'high', u'low', u'spam'])
+
+            self.__testGetQualified(qname,
+                                    [
+                                       (u'', u'high'),
+                                       (u'', u'low'),
+                                       (u'', u'spam'),
+                                       (u'', u'eggs'),
+                                       (u'', u'ham'),
+                                       (u'old', u'bleep bleep'),
+                                       (u'old', u'bleep bleep \u1111'),
+                                       (u'foo\u1111', u'bleep bleep'),
+                                       ]
+                                    )
+
+
+
+    def testDates(self):
+        self.__testQualified('Dates', [
+            (u'', u'1990-01-01'),
+            (u'Created', u'1980-10-01T23:11:10-04:00'),
+            (u'Modified', u'2002-10-01T12:09:22-04:00'),
+            (u'Effective', u'2002-10-09T00:00:00-04:00'),
+            (u'Expires', u'2002-10-16T00:00:00-04:00'),
+            (u'xxx', u'2000-07-04'),
+            (u'xxx', u'2001-12-31'),
+            (u'foo \u1111', u'2001-12-31'),
+            ])
+
+        from Zope.Misc.DateTimeParse import parseDatetimetz
+
+        dc = self.dc
+        self.assertEqual(dc.created,
+                         parseDatetimetz('1980-10-01T23:11:10-04:00'))
+        self.assertEqual(dc.modified,
+                         parseDatetimetz('2002-10-01T12:09:22-04:00'))
+        self.assertEqual(dc.effective,
+                         parseDatetimetz('2002-10-09T00:00:00-04:00'))
+        self.assertEqual(dc.expires,
+                         parseDatetimetz('2002-10-16T00:00:00-04:00'))
+
+        self.assertEqual(dc.Date(), u'1990-01-01')
+        self.assertEqual(dc.CreationDate(), u'1980-10-01T23:11:10-04:00')
+        self.assertEqual(dc.ModificationDate(), u'2002-10-01T12:09:22-04:00')
+        self.assertEqual(dc.EffectiveDate(), u'2002-10-09T00:00:00-04:00')
+        self.assertEqual(dc.ExpirationDate(), u'2002-10-16T00:00:00-04:00')
+
+
+        dt = parseDatetimetz('2002-10-03T14:51:55-04:00')
+
+        dc.modified = dt
+
+        self.assertRaises(Exception, setattr, dc, 'modified', 'foo')
+
+        modified = [qv[1]
+                    for qv in dc.getQualifiedDates()
+                    if qv[0] == u'Modified']
+
+        self.failIf(len(modified) != 1, "should be only one: %r" % modified)
+
+        self.assertEqual(parseDatetimetz(modified[0]), dt)
+
+        modified = dc.ModificationDate()
+        self.assertEqual(parseDatetimetz(modified), dt)
+        
+
+def test_suite():
+    return TestSuite((
+        makeSuite(Test),
+        ))
+
+if __name__=='__main__':
+    main(defaultTest='test_suite')