[Zope3-checkins] CVS: zopeproducts/zwiki/tests - test_wikidirectives.py:1.1

Stephan Richter srichter@cbu.edu
Tue, 8 Apr 2003 15:11:44 -0400


Update of /cvs-repository/zopeproducts/zwiki/tests
In directory cvs.zope.org:/tmp/cvs-serv10177/tests

Added Files:
	test_wikidirectives.py 
Log Message:
Added a test for the wiki directives.


=== Added File zopeproducts/zwiki/tests/test_wikidirectives.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.
#
##############################################################################
"""Test the wiki ZCML namespace directives.

$Id: test_wikidirectives.py,v 1.1 2003/04/08 19:11:44 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()