[Zope3-checkins] CVS: zopeproducts/zwiki/tests - test_index.py:1.1 test_wikidirectives.py.~1.1.~:1.1 test_wikidirectives.pyc:1.1 test_wikimail.py:1.1 test_wikipagefile.py:1.1 test_wikipagesearchtext.py:1.1 test_sourcetype.py:1.2 test_wikidirectives.py:1.2 test_wikipagehierarchy.py:1.6
Stephan Richter
srichter@cbu.edu
Sat, 12 Apr 2003 19:05:36 -0400
Update of /cvs-repository/zopeproducts/zwiki/tests
In directory cvs.zope.org:/tmp/cvs-serv13171/tests
Modified Files:
test_sourcetype.py test_wikidirectives.py
test_wikipagehierarchy.py
Added Files:
test_index.py test_wikidirectives.py.~1.1.~
test_wikidirectives.pyc test_wikimail.py test_wikipagefile.py
test_wikipagesearchtext.py
Log Message:
- Finished a bunch of promised tests. Except for Views everything is tested
now.
- Reworked the source type registry a bit to be more flexible. Now the
actual implementation of a source type interface is also registered. I
moved the createComment() method into the source class, since this is
where it belongs. We only want one createComment() method for each source
and not for each renderer.
=== Added File zopeproducts/zwiki/tests/test_index.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.
#
##############################################################################
"""ZWiki Tests
$Id: test_index.py,v 1.1 2003/04/12 23:05:35 srichter Exp $
"""
import unittest
from zope.app.index.text.tests import test_index
from zope.app.interfaces.index.text import ISearchableText
from zope.app.services.tests.placefulsetup import PlacefulSetup
from zopeproducts.zwiki.interfaces import IWikiPage
from zopeproducts.zwiki.index import WikiTextIndex
class FakeSearchableObject:
__implements__ = ISearchableText, IWikiPage
def __init__(self):
self.texts = [u"Bruce"]
def getSearchableText(self):
return self.texts
class IndexTest(test_index.Test):
# Note: There could be some more testing, checking that only WikiPage
# objects get indexed, but we can do this later. Good enoug for
# now.
def setUp(self):
PlacefulSetup.setUp(self)
self.buildFolders()
self.index = WikiTextIndex()
self.rootFolder.setObject('myIndex', self.index)
self.object = FakeSearchableObject()
self.rootFolder.setObject('bruce', self.object)
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(IndexTest),
))
if __name__ == '__main__':
unittest.main()
=== Added File zopeproducts/zwiki/tests/test_wikidirectives.py.~1.1.~ ===
##############################################################################
#
# 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.
#
##############################################################################
"""Test the wiki ZCML namespace directives.
$Id: test_wikidirectives.py.~1.1.~,v 1.1 2003/04/12 23:05:35 srichter Exp $
"""
import os
import unittest
from cStringIO import StringIO
from zope.interface import Interface
from zope.component.tests.placelesssetup import PlacelessSetup
from zope.configuration.xmlconfig import xmlconfig, Context, XMLConfig
from zope.configuration.exceptions import ConfigurationError
from zope.component import getView
from zope.publisher.browser import BrowserView, TestRequest
import zope.configuration
import zopeproducts.zwiki
import zopeproducts.zwiki.tests
from zopeproducts.zwiki.sourcetype import SourceTypes
template = """<zopeConfigure
xmlns='http://namespaces.zope.org/zope'
xmlns:wiki='http://namespaces.zope.org/wiki'>
xmlns:test='http://www.zope.org/NS/Zope3/test'>
%s
</zopeConfigure>"""
class ITestSource(Interface):
pass
class TestRenderer(BrowserView):
__implements__ = BrowserView.__implements__
__used_for__ = ITestSource
class DirectivesTest(PlacelessSetup, unittest.TestCase):
def setUp(self):
PlacelessSetup.setUp(self)
XMLConfig('metameta.zcml', zope.configuration)()
XMLConfig('meta.zcml', zopeproducts.zwiki)()
def test_sourcetype_renderer(self):
self.assertEqual([], SourceTypes.getAllTitles())
xmlconfig(StringIO(template % (
'''
<wiki:sourcetype
title="Test Text"
interface=".test_wikidirectives.ITestSource">
<wiki:renderer
for="zope.publisher.interfaces.browser.IBrowserPresentation"
factory=".test_wikidirectives.TestRenderer" />
</wiki:sourcetype>
'''
)), None, Context([], zopeproducts.zwiki.tests))
self.assertEqual(['Test Text'], SourceTypes.getAllTitles())
self.assertEqual(
zopeproducts.zwiki.tests.test_wikidirectives.ITestSource,
SourceTypes.get('Test Text'))
obj = SourceTypes.createObject('Test Text', 'Source')
self.assertEqual(
zopeproducts.zwiki.tests.test_wikidirectives.TestRenderer,
getView(obj, None, TestRequest()).__class__)
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(DirectivesTest),
))
if __name__ == '__main__':
unittest.main()
=== Added File zopeproducts/zwiki/tests/test_wikidirectives.pyc ===
<Binary-ish file>
=== Added File zopeproducts/zwiki/tests/test_wikimail.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.
#
##############################################################################
"""ZWiki Tests
$Id: test_wikimail.py,v 1.1 2003/04/12 23:05:35 srichter Exp $
"""
import unittest
from zope.proxy.context import ContextWrapper
from zope.component.adapter import provideAdapter
from zope.component.tests.placelesssetup import PlacelessSetup
from zope.app.interfaces.annotation import IAnnotations, IAttributeAnnotatable
from zope.app.interfaces.event import ISubscriber
from zope.app.attributeannotations import AttributeAnnotations
from zopeproducts.zwiki.interfaces import IWikiPage, IWiki, IMailSubscriptions
from zopeproducts.zwiki.wikipage import WikiPage
from zopeproducts.zwiki.wikipage import MailSubscriptions, WikiMailer, mailer
from zopeproducts.zwiki.wiki import Wiki
SubscriberKey = 'http://www.zope.org/zwiki#1.0/MailSubscriptions/emails'
class MailSubscriptionTest(PlacelessSetup):
def getTestObject(self):
raise NotImplementedError
def setUp(self):
PlacelessSetup.setUp(self)
# This needs to be done, since the IAttributeAnnotable interface
# is usually set in the ZCML
WikiPage.__implements__ = (WikiPage.__implements__,
IAttributeAnnotatable)
Wiki.__implements__ = (Wiki.__implements__,
IAttributeAnnotatable)
provideAdapter(IAttributeAnnotatable, IAnnotations,
AttributeAnnotations)
self._sub = MailSubscriptions(self.getTestObject())
def test_Interface(self):
self.failUnless(IMailSubscriptions.isImplementedBy(self._sub))
def test_getSubscriptions(self):
self.assertEqual((), self._sub.getSubscriptions())
self._sub.context.__annotations__[SubscriberKey] = ('foo@bar.com',)
self.assertEqual(('foo@bar.com',), self._sub.getSubscriptions())
def test_addSubscriptions(self):
self._sub.addSubscriptions(('foo@bar.com',))
self.assertEqual(('foo@bar.com',),
self._sub.context.__annotations__[SubscriberKey])
self._sub.addSubscriptions(('blah@bar.com',))
self.assertEqual(('foo@bar.com', 'blah@bar.com'),
self._sub.context.__annotations__[SubscriberKey])
self._sub.addSubscriptions(('blah@bar.com',))
self.assertEqual(('foo@bar.com', 'blah@bar.com'),
self._sub.context.__annotations__[SubscriberKey])
self._sub.addSubscriptions(('blah@bar.com', 'doh@bar.com'))
self.assertEqual(('foo@bar.com', 'blah@bar.com', 'doh@bar.com'),
self._sub.context.__annotations__[SubscriberKey])
def test_removeSubscriptions(self):
self._sub.context.__annotations__[SubscriberKey] = (
'foo@bar.com', 'blah@bar.com', 'doh@bar.com')
self._sub.removeSubscriptions(('foo@bar.com',))
self.assertEqual(('blah@bar.com', 'doh@bar.com'),
self._sub.context.__annotations__[SubscriberKey])
self._sub.removeSubscriptions(('foo@bar.com',))
self.assertEqual(('blah@bar.com', 'doh@bar.com'),
self._sub.context.__annotations__[SubscriberKey])
self._sub.removeSubscriptions(('blah@bar.com', 'doh@bar.com'))
self.assertEqual((),
self._sub.context.__annotations__[SubscriberKey])
class WikiPageMailSubscriptionTest(MailSubscriptionTest, unittest.TestCase):
def getTestObject(self):
return WikiPage()
class WikiMailSubscriptionTest(MailSubscriptionTest, unittest.TestCase):
def getTestObject(self):
return Wiki()
class WikiMailerTest(PlacelessSetup, unittest.TestCase):
# Note: There are several other methods in this class, but they require
# mail to be sent out. One way to still write tests for these would
# be to implement a dummy smtplib.SMTP class...not now though. ;)
def setUp(self):
PlacelessSetup.setUp(self)
# This needs to be done, since the IAttributeAnnotable interface
# is usually set in the ZCML
WikiPage.__implements__ = (WikiPage.__implements__,
IAttributeAnnotatable)
Wiki.__implements__ = (Wiki.__implements__,
IAttributeAnnotatable)
provideAdapter(IWikiPage, IMailSubscriptions,
MailSubscriptions)
provideAdapter(IWiki, IMailSubscriptions,
MailSubscriptions)
WikiPage.__implements__ = (WikiPage.__implements__,
IAttributeAnnotatable)
Wiki.__implements__ = (Wiki.__implements__,
IAttributeAnnotatable)
provideAdapter(IAttributeAnnotatable, IAnnotations,
AttributeAnnotations)
def test_Interface(self):
self.failUnless(ISubscriber.isImplementedBy(mailer))
def test_getAllSubscribers(self):
wiki = Wiki()
wiki_sub = MailSubscriptions(wiki)
wiki_sub.context.__annotations__[SubscriberKey] = ('foo@bar.com',)
page = WikiPage()
page_sub = MailSubscriptions(page)
page_sub.context.__annotations__[SubscriberKey] = ('blah@bar.com',)
wiki.setObject('page1', page)
wrapped_page = ContextWrapper(page, wiki, name="page1")
self.assertEqual(('blah@bar.com', 'foo@bar.com'),
mailer.getAllSubscribers(wrapped_page))
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(WikiMailSubscriptionTest),
unittest.makeSuite(WikiPageMailSubscriptionTest),
unittest.makeSuite(WikiMailerTest),
))
if __name__ == '__main__':
unittest.main()
=== Added File zopeproducts/zwiki/tests/test_wikipagefile.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.
#
##############################################################################
"""ZWiki Tests
$Id: test_wikipagefile.py,v 1.1 2003/04/12 23:05:35 srichter Exp $
"""
import unittest
from zopeproducts.zwiki.wikipage import WikiPage
from zopeproducts.zwiki.wikipage import WikiPageReadFile, WikiPageWriteFile
class ReadFileTest(unittest.TestCase):
def setUp(self):
self._page = WikiPage()
self._page.source = u'This is the source'
self._file = WikiPageReadFile(self._page)
def test_read(self):
self.assertEqual(self._page.source, self._file.read())
def test_size(self):
self.assertEqual(len(self._page.source), self._file.size())
class WriteFileTest(unittest.TestCase):
def setUp(self):
self._page = WikiPage()
self._file = WikiPageWriteFile(self._page)
def test_read(self):
self._file.write(u'This is the source')
self.assertEqual(u'This is the source', self._page.source)
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(ReadFileTest),
unittest.makeSuite(WriteFileTest),
))
if __name__ == '__main__':
unittest.main()
=== Added File zopeproducts/zwiki/tests/test_wikipagesearchtext.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.
#
##############################################################################
"""ZWiki Tests
$Id: test_wikipagesearchtext.py,v 1.1 2003/04/12 23:05:35 srichter Exp $
"""
import unittest
from zopeproducts.zwiki.wikipage import WikiPage
from zopeproducts.zwiki.wikipage import SearchableText
class SearchableTextTest(unittest.TestCase):
def setUp(self):
self._page = WikiPage()
self._page.source = u'This is the source'
self._text = SearchableText(self._page)
def test_getSearchableText(self):
self.assertEqual([self._page.source], self._text.getSearchableText())
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(SearchableTextTest),
))
if __name__ == '__main__':
unittest.main()
=== zopeproducts/zwiki/tests/test_sourcetype.py 1.1 => 1.2 ===
--- zopeproducts/zwiki/tests/test_sourcetype.py:1.1 Tue Apr 8 00:13:22 2003
+++ zopeproducts/zwiki/tests/test_sourcetype.py Sat Apr 12 19:05:35 2003
@@ -25,24 +25,30 @@
class IFoo(Interface):
pass
+class Foo(unicode):
+ __implements__ = IFoo
+
class IFoo2(Interface):
pass
+class Foo2(unicode):
+ __implements__ = IFoo2
+
class TestGlobalWikiSourceTypeService(unittest.TestCase):
def setUp(self):
self.obj = GlobalWikiSourceTypeService()
- self.obj.provide('Foo', IFoo)
+ self.obj.provide('Foo', IFoo, Foo)
def testInterfaceConformity(self):
self.assert_(IGlobalWikiSourceTypeService.isImplementedBy(self.obj))
def test_provide(self):
service = GlobalWikiSourceTypeService()
- service.provide('Foo', IFoo)
+ service.provide('Foo', IFoo, Foo)
self.assertEqual(
- {'Foo': IFoo},
+ {'Foo': (IFoo, Foo)},
service.__dict__['_GlobalWikiSourceTypeService__types'])
def test_get(self):
@@ -55,13 +61,14 @@
self.assertRaises(KeyError, self.obj.query, ('Bar',))
def test_getAllTitles(self):
- self.obj.provide('Foo2', IFoo2)
+ self.obj.provide('Foo2', IFoo2, Foo2)
titles = self.obj.getAllTitles()
titles.sort()
self.assertEqual(['Foo', 'Foo2'], titles)
def test_createObject(self):
obj = self.obj.createObject('Foo', 'Source text')
+ self.assertEqual(Foo, obj.__class__)
self.assert_(IFoo.isImplementedBy(obj))
self.assertEqual('Source text', str(obj))
=== zopeproducts/zwiki/tests/test_wikidirectives.py 1.1 => 1.2 ===
--- zopeproducts/zwiki/tests/test_wikidirectives.py:1.1 Tue Apr 8 15:11:44 2003
+++ zopeproducts/zwiki/tests/test_wikidirectives.py Sat Apr 12 19:05:35 2003
@@ -43,6 +43,10 @@
class ITestSource(Interface):
pass
+class TestSource(unicode):
+ __implements__ = ITestSource
+
+
class TestRenderer(BrowserView):
__implements__ = BrowserView.__implements__
__used_for__ = ITestSource
@@ -61,7 +65,8 @@
'''
<wiki:sourcetype
title="Test Text"
- interface=".test_wikidirectives.ITestSource">
+ interface=".test_wikidirectives.ITestSource"
+ class=".test_wikidirectives.TestSource">
<wiki:renderer
for="zope.publisher.interfaces.browser.IBrowserPresentation"
factory=".test_wikidirectives.TestRenderer" />
=== zopeproducts/zwiki/tests/test_wikipagehierarchy.py 1.5 => 1.6 ===
--- zopeproducts/zwiki/tests/test_wikipagehierarchy.py:1.5 Wed Apr 9 17:47:17 2003
+++ zopeproducts/zwiki/tests/test_wikipagehierarchy.py Sat Apr 12 19:05:35 2003
@@ -19,11 +19,16 @@
from zopeproducts.zwiki.interfaces import IWikiPage, IWikiPageHierarchy
from zopeproducts.zwiki.wikipage import WikiPage, WikiPageHierarchyAdapter
+from zopeproducts.zwiki.wiki import Wiki
from zope.component.tests.placelesssetup import PlacelessSetup
from zope.component.adapter import provideAdapter
from zope.app.interfaces.annotation import IAnnotations, IAttributeAnnotatable
+from zope.app.interfaces.traversing import IObjectName
+
+from zope.proxy.context import ContextWrapper
from zope.app.attributeannotations import AttributeAnnotations
+from zope.app.traversing.adapters import ObjectName
class TestAnnotations(dict):
@@ -34,10 +39,15 @@
def setUp(self):
PlacelessSetup.setUp(self)
+ # This needs to be done, since the IAttributeAnnotable interface
+ # is usually set in the ZCML
WikiPage.__implements__ = (WikiPage.__implements__,
IAttributeAnnotatable)
provideAdapter(IAttributeAnnotatable, IAnnotations,
AttributeAnnotations)
+ provideAdapter(IWikiPage, IWikiPageHierarchy,
+ WikiPageHierarchyAdapter)
+ provideAdapter(None, IObjectName, ObjectName)
self.page = WikiPage()
def makeTestObject(self):
@@ -63,7 +73,44 @@
hier.reparent(('bar',))
self.assertEqual(('bar',), hier.parents)
-
+ def test_wikipath(self):
+ wiki = Wiki()
+ wiki.setObject('TopLevelPage', WikiPage())
+ wiki.setObject('SecondLevelPage', WikiPage())
+ hier = WikiPageHierarchyAdapter(
+ ContextWrapper(wiki['SecondLevelPage'], wiki,
+ name='SecondLevelPage'))
+ hier.reparent(('TopLevelPage',))
+ self.assertEqual([wiki['TopLevelPage'], wiki['SecondLevelPage']],
+ hier.path())
+
+ def test_findChildren(self):
+ wiki = Wiki()
+
+ page1 = WikiPage()
+ wiki.setObject('TopLevelPage', page1)
+ wrapped_page1 = ContextWrapper(page1, wiki, name='TopLevelPage')
+ hier1 = WikiPageHierarchyAdapter(wrapped_page1)
+
+ page2 = WikiPage()
+ wiki.setObject('SecondLevelPage', page2)
+ wrapped_page2 = ContextWrapper(page2, wiki, name='SecondLevelPage')
+ hier2 = WikiPageHierarchyAdapter(wrapped_page2)
+ hier2.reparent(('TopLevelPage',))
+
+ page3 = WikiPage()
+ wiki.setObject('ThirdLevelPage', page3)
+ wrapped_page3 = ContextWrapper(page3, wiki, name='ThirdLevelPage')
+ hier3 = WikiPageHierarchyAdapter(wrapped_page3)
+ hier3.reparent(('SecondLevelPage',))
+
+ self.assertEqual(( (wrapped_page2, ()), ),
+ hier1.findChildren(False));
+
+ self.assertEqual(((wrapped_page2, ((wrapped_page3, ()),) ),),
+ hier1.findChildren());
+
+
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(Test),