[Zope3-checkins] CVS: zopeproducts/xslt/tests - __init__.py:1.1 test_foursuitetransformer.py:1.1 test_sheet.py:1.1

Martijn Faassen m.faassen@vet.uu.nl
Sun, 13 Apr 2003 11:58:04 -0400


Update of /cvs-repository/zopeproducts/xslt/tests
In directory cvs.zope.org:/tmp/cvs-serv23322/tests

Added Files:
	__init__.py test_foursuitetransformer.py test_sheet.py 
Log Message:
Added initial version of xslt package. This package defines a simple
(currently too simple) way to plug in different XSLT transformation engines
into Zope using a utility. One utility based on 4suite is provided.
See the xslt_examples (checked in after this) for an early example of
usage.


=== Added File zopeproducts/xslt/tests/__init__.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.
#
##############################################################################
"""
$Id: __init__.py,v 1.1 2003/04/13 15:58:03 faassen Exp $
"""


=== Added File zopeproducts/xslt/tests/test_foursuitetransformer.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.
#
##############################################################################
"""
$Id: test_foursuitetransformer.py,v 1.1 2003/04/13 15:58:03 faassen Exp $
"""

import unittest

from zope.app.interfaces.xml.source import IXMLSource
from zope.app.tests.placelesssetup import PlacelessSetup
from zope.app.content.xmldocument import XMLDocument
from zopeproducts.xslt.foursuitetransformer import FourSuiteTransformer

class FourSuiteTransformerTests(PlacelessSetup, unittest.TestCase):

    def test_transform(self):
        xslt = """\
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<transformed_doc/>
</xsl:template>
</xsl:stylesheet>"""
        xslt = XMLDocument(xslt)

        xml = "<doc/>"
        xml = XMLDocument(xml)
        
        transformer = FourSuiteTransformer()
        result = transformer.transform(xslt, xml)

        # make sure we get back an XML source
        self.assert_(IXMLSource.isImplementedBy(result))
        
        expected = """\
<?xml version="1.0" encoding="UTF-8"?>
<transformed_doc/>"""
        self.assertEqual(result.source, expected)

def test_suite():
    return unittest.makeSuite(FourSuiteTransformerTests)


=== Added File zopeproducts/xslt/tests/test_sheet.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.
#
##############################################################################
"""
$Id: test_sheet.py,v 1.1 2003/04/13 15:58:03 faassen Exp $
"""

import unittest

from zope.component import getAdapter
from zope.app.xml.schemainterface import XMLSchemaInterfaceClass
from zope.app.interfaces.xml.source import IXMLSource
from zope.app.tests.placelesssetup import PlacelessSetup
from zope.app.content.xmldocument import XMLDocument
from zopeproducts.xslt.sheet import XSLTSheet

from zopeproducts.xslt.foursuitetransformer import FourSuiteTransformer
from zopeproducts.xslt.interfaces import IXSLTTransformer
from zope.component.utility import utilityService
from zope.component.adapter import adapterService
from zope.app.component.globalinterfaceservice import interfaceService

class XSLTSheetTests(PlacelessSetup, unittest.TestCase):

    def setUp(self):
        PlacelessSetup.setUp(self)
        # we also need to provide the utility manually
        utilityService.provideUtility(IXSLTTransformer, FourSuiteTransformer())
 
    def test_transform(self):
        xslt_sheet = XSLTSheet('''\
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<transformed_doc/>
</xsl:template>
</xsl:stylesheet>''')

        xml = XMLDocument("<doc/>")
        result = xslt_sheet(xml)

        # make sure we get back an XML source
        self.assert_(IXMLSource.isImplementedBy(result))
        
        expected = '''\
<?xml version="1.0" encoding="UTF-8"?>
<transformed_doc/>'''
        self.assertEqual(result.source, expected)

    def test_as_adapter_factory(self):
        apple_uri = "http://xml.zope.org/xml_examples/apple"
        pear_uri = "http://xml.zope.org/xml_examples/pear"
        IApple = XMLSchemaInterfaceClass(apple_uri)
        IPear = XMLSchemaInterfaceClass(pear_uri)
        interfaceService.provideInterface(apple_uri, IApple)
        interfaceService.provideInterface(pear_uri, IPear)

        xslt_sheet = XSLTSheet('''\
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:template match="/">
<transformed_doc xsi:schemaLocation="http://xml.zope.org/xml_examples/pear"/>
</xsl:template>
</xsl:stylesheet>''')
        adapterService.provideAdapter(IApple, IPear, xslt_sheet)

        xml = XMLDocument('''\
<doc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://xml.zope.org/xml_examples/apple"/>''')

        result = getAdapter(xml, IPear)
        self.assert_(IPear.isImplementedBy(result))

def test_suite():
    return unittest.makeSuite(XSLTSheetTests)