[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/DublinCore/tests - __init__.py:1.1.2.1 testZDCAnnotatableAdapter.py:1.1.2.1 testZopeDublinCore.py:1.1.2.1
Jim Fulton
jim@zope.com
Thu, 3 Oct 2002 18:16:50 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/App/DublinCore/tests
In directory cvs.zope.org:/tmp/cvs-serv27190/lib/python/Zope/App/DublinCore/tests
Added Files:
Tag: ZopeDublinCore-branch
__init__.py testZDCAnnotatableAdapter.py testZopeDublinCore.py
Log Message:
Checking in still-unfinished dublin core work on
ZopeDublinCore-branch.
To do:
- Make a number of existing tests work now that a lot of views
need to generate events. (Perhaps these will need to
be factored into adapters and views. Sigh.)
- Make object events able to compute locations for there
objects when an location hasn't been provided to the constructor.
- Add some UI for editing at least some meta data.
Handling of lists (e.g. subjects, creators) may need some more thought
as these will often want to come from standard system-provided lists.
=== Added File Zope3/lib/python/Zope/App/DublinCore/tests/__init__.py ===
##############################################################################
#
# 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.
#
##############################################################################
=== Added File Zope3/lib/python/Zope/App/DublinCore/tests/testZDCAnnotatableAdapter.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.
#
##############################################################################
"""XXX short summary goes here.
XXX longer description goes here.
$Id: testZDCAnnotatableAdapter.py,v 1.1.2.1 2002/10/03 22:16:49 jim Exp $
"""
from unittest import TestCase, TestSuite, main, makeSuite
from Zope.App.OFS.Annotation.IAnnotations import IAnnotations
from Zope.ComponentArchitecture.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')
=== Added File Zope3/lib/python/Zope/App/DublinCore/tests/testZopeDublinCore.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.
#
##############################################################################
"""XXX short summary goes here.
XXX longer description goes here.
$Id: testZopeDublinCore.py,v 1.1.2.1 2002/10/03 22:16:49 jim Exp $
"""
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')