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

Stephan Richter srichter@cbu.edu
Tue, 8 Apr 2003 00:13:24 -0400


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

Added Files:
	test_sourcetype.py 
Log Message:
Implemented Source Type registry, so that it will be easy to plug in new 
rendering engines. Right now there is only support for STX and Plain Text.


=== Added File zopeproducts/zwiki/tests/test_sourcetype.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.
#
##############################################################################
"""Tests for Global Wiki Source Type Service.

$Id: test_sourcetype.py,v 1.1 2003/04/08 04:13:22 srichter Exp $
"""
import unittest

from zope.interface import Interface
from zopeproducts.zwiki.interfaces import IGlobalWikiSourceTypeService
from zopeproducts.zwiki.sourcetype import GlobalWikiSourceTypeService


class IFoo(Interface):
    pass

class IFoo2(Interface):
    pass


class TestGlobalWikiSourceTypeService(unittest.TestCase):

    def setUp(self):
        self.obj = GlobalWikiSourceTypeService()
        self.obj.provide('Foo', IFoo)

    def testInterfaceConformity(self):
        self.assert_(IGlobalWikiSourceTypeService.isImplementedBy(self.obj))

    def test_provide(self):
        service = GlobalWikiSourceTypeService()
        service.provide('Foo', IFoo)
        self.assertEqual(
            {'Foo': IFoo},
            service.__dict__['_GlobalWikiSourceTypeService__types'])

    def test_get(self):
        self.assertEqual(IFoo, self.obj.get('Foo'))
        self.assertEqual(None, self.obj.get('Bar'))
        self.assertEquals(IFoo2, self.obj.get('Bar', IFoo2))

    def test_query(self):
        self.assertEqual(IFoo, self.obj.get('Foo'))
        self.assertRaises(KeyError, self.obj.query, ('Bar',))

    def test_getAllTitles(self):
        self.obj.provide('Foo2', IFoo2)
        titles = self.obj.getAllTitles()
        titles.sort()
        self.assertEqual(['Foo', 'Foo2'], titles)
        
    def test_createObject(self):
        obj = self.obj.createObject('Foo', 'Source text')
        self.assert_(IFoo.isImplementedBy(obj))
        self.assertEqual('Source text', str(obj))


def test_suite():
    return unittest.TestSuite((
        unittest.makeSuite(TestGlobalWikiSourceTypeService),
        ))

if __name__ == '__main__':
    unittest.main()