[Zope3-checkins] CVS: Zope3/src/zope/app/schema/tests - test_fieldfactory.py:1.1 test_fieldfactory.zcml:1.1

Sidnei da Silva sidnei at x3ng.com.br
Tue Aug 5 11:25:13 EDT 2003


Update of /cvs-repository/Zope3/src/zope/app/schema/tests
In directory cvs.zope.org:/tmp/cvs-serv14539/src/zope/app/schema/tests

Added Files:
	test_fieldfactory.py test_fieldfactory.zcml 
Log Message:
Reasonably big batch of changes. Added methods to query factories by interface. Added tests for them. Registered all fields from zope.schema as factories. Added basic tests for that. Made the contentdirective use a dottedname instead of a class as the id when an id is not provided. Cleanspace Whitening here and there.

=== Added File Zope3/src/zope/app/schema/tests/test_fieldfactory.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.
#
##############################################################################
"""

$Id: test_fieldfactory.py,v 1.1 2003/08/05 14:25:06 sidnei Exp $
"""

import unittest
from StringIO import StringIO

from zope.component.exceptions import ComponentLookupError
from zope.app.tests.placelesssetup import PlacelessSetup
from zope.security.management import newSecurityManager, system_user
from zope.security.proxy import Proxy
import zope.app.security
import zope.app.component
from zope.app.security.exceptions import UndefinedPermissionError
from zope.component import getService
from zope.app.services.servicenames import Factories
from zope.schema.interfaces import IField, IText
from zope.interface import Interface
from zope.configuration import xmlconfig

class IFoo(Interface): pass

class TestFieldFactory(PlacelessSetup, unittest.TestCase):

    def setUp(self):
        PlacelessSetup.setUp(self)
        newSecurityManager(system_user)
        context = xmlconfig.file('tests/test_fieldfactory.zcml',
                                 zope.app.schema)

    def testRegisterFields(self):
        factory = getService(None, Factories).getFactory('zope.schema._bootstrapfields.Text')
        self.assertEquals(factory.title, "Text Field")
        self.assertEquals(factory.description, "Text Field")

    def testGetFactoriesForIField(self):
        factories = getService(None, Factories).getFactoriesFor(IField)
        self.assertEqual(len(factories), 3)

    def testGetFactoriesForIText(self):
        factories = getService(None, Factories).getFactoriesFor(IText)
        self.assertEqual(len(factories), 2)

    def testGetFactoriesUnregistered(self):
        fservice = getService(None, Factories)
        self.assertRaises(ComponentLookupError, fservice.getFactoriesFor,
                          IFoo)

    def testQueryFactoriesUnregistered(self):
        fservice = getService(None, Factories)
        self.assertEqual(fservice.queryFactoriesFor(IFoo, None), None)

def test_suite():
    suite = unittest.TestSuite()
    loader = unittest.TestLoader()
    suite.addTest(loader.loadTestsFromTestCase(TestFieldFactory))
    return suite


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


=== Added File Zope3/src/zope/app/schema/tests/test_fieldfactory.zcml ===
<configure xmlns="http://namespaces.zope.org/zope"
           i18n_domain="zope">

  <include package="zope.app.component" file="meta.zcml" />
  <include package="zope.app.security" file="meta.zcml" />
  <include package="zope.app.security" file="configure.zcml" />

  <content class="zope.schema.Field">

    <factory
	permission="zope.ManageContent"
	title="Basic Field"
	description="Basic Field" />

    <!--
    <require
	permission="zope.View"
	interface="zope.schema.interfaces.IField"
	/>

    <require
	permission="zope.ManageContent"
	attributes="bind set"
	/>
    -->

    <!-- XXX put the whole interface under one permission for now -->
    <require
	permission="zope.ManageContent"
	interface="zope.schema.interfaces.IField"
	/>

  </content>

  <content class="zope.schema.Text">

    <factory
	permission="zope.ManageContent"
	title="Text Field"
	description="Text Field" />

    <require like_class="zope.schema.Field" />

  </content>

  <content class="zope.schema.TextLine">

    <factory
	permission="zope.ManageContent"
	title="Text Line Field"
	description="Text Line Field" />

    <require like_class="zope.schema.Field" />

  </content>

</configure>



More information about the Zope3-Checkins mailing list