[Zope3-checkins] CVS: Packages3/workflow/tests - directive_helpers.py:1.1 test_directives.py:1.1 test_importexport.py:1.1

Ulrich Eck ueck@net-labs.de
Mon, 7 Apr 2003 13:33:52 -0400


Update of /cvs-repository/Packages3/workflow/tests
In directory cvs.zope.org:/tmp/cvs-serv17691/tests

Added Files:
	directive_helpers.py test_directives.py test_importexport.py 
Log Message:
adding tests for workflow-directives, globalimportexport, xmlimportexport
updates for xmlexporttemplate to handle scripts and permissions correctly


=== Added File Packages3/workflow/tests/directive_helpers.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.
#
##############################################################################

__metaclass__ = type

from zope.app.interfaces.workflow import IProcessDefinition
from zope.app.interfaces.workflow import IGlobalProcessDefinitionImportExport
from zope.app.interfaces.workflow import IProcessDefinitionImportHandler
from zope.app.interfaces.workflow import IProcessDefinitionExportHandler



class ITestProcessDefinitionA(IProcessDefinition):
    pass

class ITestProcessDefinitionB(IProcessDefinition):
    pass


class TestImportHandlerA:

    __implements__ = IProcessDefinitionImportHandler

    def canImport(self, data):
        return bool(data == 'A')

    def doImport(self, context, data):
        return 'Imported A'


class TestImportHandlerB:

    __implements__ = IProcessDefinitionImportHandler

    def canImport(self, data):
        return bool(data == 'B')

    def doImport(self, context, data):
        return 'Imported B'



class TestExportHandlerA:

    __implements__ = IProcessDefinitionExportHandler

    def doExport(self, context, process_definition):
        return 'Exported A'


class TestExportHandlerB:

    __implements__ = IProcessDefinitionExportHandler

    def doExport(self, context, process_definition):
        return 'Exported B'


=== Added File Packages3/workflow/tests/test_directives.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.
#
##############################################################################

import unittest
import sys
import os
from cStringIO import StringIO

from zope.app.tests.placelesssetup import PlacelessSetup

from zope.configuration.xmlconfig import xmlconfig, XMLConfig

import zope.configuration
import zope.app.workflow

from zope.app.workflow import globalimportexport
from zope.app.workflow.tests import directive_helpers

gIE = globalimportexport.globalImportExport


template = """<zopeConfigure
   xmlns:test='http://namespaces.zope.org/workflow'>
   %s
   </zopeConfigure>"""


class Test(PlacelessSetup, unittest.TestCase):


    def setUp(self):
        PlacelessSetup.setUp(self)
        XMLConfig('metameta.zcml', zope.configuration)()
        XMLConfig('meta.zcml', zope.app.workflow)()

    def testImportHandler(self):

        xmlconfig(StringIO(template % (
            """
            <test:importHandler
             interface="zope.app.workflow.tests.directive_helpers.ITestProcessDefinitionA"
             factory="zope.app.workflow.tests.directive_helpers.TestImportHandlerA"
            />
            """
            )))

        self.assertEqual(directive_helpers.TestImportHandlerA,
                         gIE._importers.get(directive_helpers.ITestProcessDefinitionA))

    def testExportHandler(self):

        xmlconfig(StringIO(template % (
            """
            <test:exportHandler
             interface="zope.app.workflow.tests.directive_helpers.ITestProcessDefinitionA"
             factory="zope.app.workflow.tests.directive_helpers.TestExportHandlerA"
            />
            """
            )))

        self.assertEqual(directive_helpers.TestExportHandlerA,
                         gIE._exporters.get(directive_helpers.ITestProcessDefinitionA))


        

def test_suite():
    loader=unittest.TestLoader()
    return loader.loadTestsFromTestCase(Test)

if __name__=='__main__':
    unittest.TextTestRunner().run(test_suite())


=== Added File Packages3/workflow/tests/test_importexport.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.
#
##############################################################################

import unittest
import sys
import os
from cStringIO import StringIO

from zope.app.tests.placelesssetup import PlacelessSetup

from zope.app.workflow import globalimportexport
from zope.app.workflow.tests import directive_helpers

gIE = globalimportexport.globalImportExport
dh = directive_helpers

class PDA:

    __implements__ = dh.ITestProcessDefinitionA

class PDB:

    __implements__ = dh.ITestProcessDefinitionB




class Test(PlacelessSetup, unittest.TestCase):


    def setUp(self):
        PlacelessSetup.setUp(self)
        gIE.addImportHandler(dh.ITestProcessDefinitionA,
                             dh.TestImportHandlerA)
        gIE.addImportHandler(dh.ITestProcessDefinitionB,
                             dh.TestImportHandlerB)
        gIE.addExportHandler(dh.ITestProcessDefinitionA,
                             dh.TestExportHandlerA)
        gIE.addExportHandler(dh.ITestProcessDefinitionB,
                             dh.TestExportHandlerB)

    def testImportHandler(self):
        self.assertEqual(gIE.importProcessDefinition(None, 'A'),
                         'Imported A')
        self.assertEqual(gIE.importProcessDefinition(None, 'B'),
                         'Imported B')

    def testExportHandler(self):
        self.assertEqual(gIE.exportProcessDefinition(None, PDA()),
                         'Exported A')
        self.assertEqual(gIE.exportProcessDefinition(None, PDB()),
                         'Exported B')
        

        

def test_suite():
    loader=unittest.TestLoader()
    return loader.loadTestsFromTestCase(Test)

if __name__=='__main__':
    unittest.TextTestRunner().run(test_suite())