[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/OFS/Services/Browser/tests - __init__.py:1.1.2.1 testChangeConfigurations.py:1.1.2.1 testConfigurationStatusWidget.py:1.1.2.1

Jim Fulton jim@zope.com
Sat, 30 Nov 2002 07:44:28 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Services/Browser/tests
In directory cvs.zope.org:/tmp/cvs-serv30047/lib/python/Zope/App/OFS/Services/Browser/tests

Added Files:
      Tag: Zope3-Bangalore-TTW-Branch
	__init__.py testChangeConfigurations.py 
	testConfigurationStatusWidget.py 
Log Message:
Refactored the way TTW component registration is done.  There are now
separate registry objects that abstract the machinery for registering
multiple conflicting configurations and deciding which, if any are
active.  Also provided a new field and widget for the status
information.

Along the way, cleaned up and streamlined placeful testing
infrastructure a bit.

Now checking into branch. Will give file-by-file (or at least more
specific logs) when the changes are merged into the head.


=== Added File Zope3/lib/python/Zope/App/OFS/Services/Browser/tests/__init__.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.
# 
##############################################################################



=== Added File Zope3/lib/python/Zope/App/OFS/Services/Browser/tests/testChangeConfigurations.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.
#
##############################################################################
"""XXX short summary goes here.

XXX longer description goes here.

$Id: testChangeConfigurations.py,v 1.1.2.1 2002/11/30 12:44:26 jim Exp $
"""

from unittest import TestCase, TestSuite, main, makeSuite
from Zope.Publisher.Browser.BrowserRequest import TestRequest
from Zope.App.OFS.Services.tests.TestingConfigurationRegistry \
     import TestingConfigurationRegistry

class Test(TestCase):

    def test_applyUpdates_and_setPrefix(self):
        registry = TestingConfigurationRegistry('a', 'b', 'c')
        request = TestRequest()
        from Zope.App.OFS.Services.Browser.ChangeConfigurations \
             import ChangeConfigurations
        view = ChangeConfigurations(registry, request)
        view.setPrefix("Roles")

        # Make sure we don't apply updates unless asked to
        request.form = {'Roles.active': 'disable'}
        view.applyUpdates()
        self.assertEqual(registry._data, ('a', 'b', 'c'))

        # Now test disabling
        request.form = {'submit_update': '', 'Roles.active': 'disable'}
        view.applyUpdates()
        self.assertEqual(registry._data, (None, 'a', 'b', 'c'))

        # Now test enabling c
        request.form = {'submit_update': '', 'Roles.active': 'c'}
        view.applyUpdates()
        self.assertEqual(registry._data, ('c', 'a', 'b'))
        
        

def test_suite():
    return TestSuite((
        makeSuite(Test),
        ))

if __name__=='__main__':
    main(defaultTest='test_suite')


=== Added File Zope3/lib/python/Zope/App/OFS/Services/Browser/tests/testConfigurationStatusWidget.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.
#
##############################################################################
"""XXX short summary goes here.

XXX longer description goes here.

$Id: testConfigurationStatusWidget.py,v 1.1.2.1 2002/11/30 12:44:26 jim Exp $
"""

from unittest import TestCase, TestSuite, main, makeSuite
from Zope.Publisher.Browser.BrowserRequest import TestRequest
from Zope.App.OFS.Services.ConfigurationInterfaces import ConfigurationStatus
from Zope.App.OFS.Services.Browser.ConfigurationStatusWidget \
     import ConfigurationStatusWidget
from Interface import Interface


class Test(TestCase):

    def test_call(self):
        field = ConfigurationStatus(__name__="status")
        request = TestRequest()
        widget = ConfigurationStatusWidget(field, request)
        widget.setPrefix("f")

        text = ' '.join(widget().split())
        self.assertEqual(
            text,
            '<input type="radio" name="f.status" value="Unregistered" checked>'
            ' Unregistered<br />'
            '<input type="radio" name="f.status" value="Registered">'
            ' Registered<br />'
            '<input type="radio" name="f.status" value="Active">'
            ' Active'
            )
        
        request.form['f.status'] = u'Registered'
        text = ' '.join(widget().split())
        self.assertEqual(
            text,
            '<input type="radio" name="f.status" value="Unregistered">'
            ' Unregistered<br />'
            '<input type="radio" name="f.status" value="Registered" checked>'
            ' Registered<br />'
            '<input type="radio" name="f.status" value="Active">'
            ' Active'
            )

        widget.setData(u"Active")
        text = ' '.join(widget().split())
        self.assertEqual(
            text,
            '<input type="radio" name="f.status" value="Unregistered">'
            ' Unregistered<br />'
            '<input type="radio" name="f.status" value="Registered">'
            ' Registered<br />'
            '<input type="radio" name="f.status" value="Active" checked>'
            ' Active'
            )

        widget.setData(u"Unregistered")
        text = ' '.join(widget().split())
        self.assertEqual(
            text,
            '<input type="radio" name="f.status" value="Unregistered" checked>'
            ' Unregistered<br />'
            '<input type="radio" name="f.status" value="Registered">'
            ' Registered<br />'
            '<input type="radio" name="f.status" value="Active">'
            ' Active'
            )


def test_suite():
    return TestSuite((
        makeSuite(Test),
        ))

if __name__=='__main__':
    main(defaultTest='test_suite')