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

Philipp von Weitershausen philikon@philikon.de
Fri, 20 Jun 2003 11:11:44 -0400


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

Added Files:
	__init__.py test_foursuitetransformer.py test_sheet.py 
Log Message:
Moved the xml_examples, xslt, xslt_examples and xmldom products to one
xml product.


=== Added File zopeproducts/xml/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/06/20 15:11:43 philikon Exp $
"""


=== Added File zopeproducts/xml/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/06/20 15:11:43 philikon 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.xml.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/xml/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/06/20 15:11:43 philikon 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.xml.xslt.sheet import XSLTSheet

from zopeproducts.xml.xslt.foursuitetransformer import FourSuiteTransformer
from zopeproducts.xml.interfaces.xslt 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)