[Zope3-checkins] CVS: Zope3/src/zope/app/browser/services/configuration/tests - __init__.py:1.1 test_changeconfigurations.py:1.1 test_configurationstatuswidget.py:1.1 test_editconfiguration.py:1.1 test_namecomponentconfigurableview.py:1.1
Jim Fulton
jim@zope.com
Fri, 21 Mar 2003 16:09:35 -0500
Update of /cvs-repository/Zope3/src/zope/app/browser/services/configuration/tests
In directory cvs.zope.org:/tmp/cvs-serv20505/src/zope/app/browser/services/configuration/tests
Added Files:
__init__.py test_changeconfigurations.py
test_configurationstatuswidget.py test_editconfiguration.py
test_namecomponentconfigurableview.py
Log Message:
Refactored the module layout for general configuration views.
Moved the implementation into a separate configuration package.
=== Added File Zope3/src/zope/app/browser/services/configuration/tests/__init__.py ===
#
# This file is necessary to make this directory a package.
=== Added File Zope3/src/zope/app/browser/services/configuration/tests/test_changeconfigurations.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: test_changeconfigurations.py,v 1.1 2003/03/21 21:09:34 jim Exp $
"""
from unittest import TestCase, TestSuite, main, makeSuite
from zope.publisher.browser import TestRequest
from zope.app.services.tests.configurationregistry \
import TestingConfigurationRegistry
from zope.app.browser.services.configuration import ChangeConfigurations
class Test(TestCase):
def test_applyUpdates_and_setPrefix(self):
registry = TestingConfigurationRegistry('a', 'b', 'c')
request = TestRequest()
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/src/zope/app/browser/services/configuration/tests/test_configurationstatuswidget.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: test_configurationstatuswidget.py,v 1.1 2003/03/21 21:09:34 jim Exp $
"""
from unittest import TestCase, TestSuite, main, makeSuite
from zope.publisher.browser import TestRequest
from zope.app.interfaces.services.configuration import ConfigurationStatus
from zope.app.browser.services.configuration import ConfigurationStatusWidget
from zope.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,
'<label><input type="radio" name="f.status" value="Unregistered"'
' checked>'
' Unregistered</label> '
'<label><input type="radio" name="f.status" value="Registered">'
' Registered</label> '
'<label><input type="radio" name="f.status" value="Active">'
' Active</label>'
)
request.form['f.status'] = u'Registered'
text = ' '.join(widget().split())
self.assertEqual(
text,
'<label><input type="radio" name="f.status" value="Unregistered">'
' Unregistered</label> '
'<label><input type="radio" name="f.status" value="Registered"'
' checked>'
' Registered</label> '
'<label><input type="radio" name="f.status" value="Active">'
' Active</label>'
)
widget.setData(u"Active")
text = ' '.join(widget().split())
self.assertEqual(
text,
'<label><input type="radio" name="f.status" value="Unregistered">'
' Unregistered</label> '
'<label><input type="radio" name="f.status" value="Registered">'
' Registered</label> '
'<label><input type="radio" name="f.status" value="Active"'
' checked>'
' Active</label>'
)
widget.setData(u"Unregistered")
text = ' '.join(widget().split())
self.assertEqual(
text,
'<label><input type="radio" name="f.status" value="Unregistered"'
' checked>'
' Unregistered</label> '
'<label><input type="radio" name="f.status" value="Registered">'
' Registered</label> '
'<label><input type="radio" name="f.status" value="Active">'
' Active</label>'
)
def test_suite():
return TestSuite((
makeSuite(Test),
))
if __name__=='__main__':
main(defaultTest='test_suite')
=== Added File Zope3/src/zope/app/browser/services/configuration/tests/test_editconfiguration.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: test_editconfiguration.py,v 1.1 2003/03/21 21:09:34 jim Exp $
"""
__metaclass__ = type
from unittest import TestCase, TestSuite, main, makeSuite
from zope.app.browser.services.configuration import EditConfiguration
from zope.app.container.zopecontainer import ZopeContainerAdapter
from zope.app.event.tests.placelesssetup import getEvents
from zope.app.interfaces.container import IContainer
from zope.app.interfaces.container import IZopeContainer
from zope.app.interfaces.event import IObjectModifiedEvent
from zope.app.interfaces.event import IObjectRemovedEvent
from zope.app.interfaces.services.configuration import Unregistered
from zope.app.interfaces.services.configuration import Registered, Active
from zope.app.interfaces.traversing import IContainmentRoot
from zope.app.services.tests.placefulsetup import PlacefulSetup
from zope.component.adapter import provideAdapter
from zope.component.view import provideView
from zope.interface import Interface
from zope.publisher.browser import BrowserView
from zope.publisher.browser import TestRequest
from zope.publisher.interfaces.browser import IBrowserPresentation
class Container(dict):
__implements__ = IContainer, IContainmentRoot
class I(Interface):
pass
class C:
__implements__ = I
status = Active
class Test(PlacefulSetup, TestCase):
def test_remove_objects(self):
provideAdapter(IContainer, IZopeContainer, ZopeContainerAdapter)
c1 = C()
c2 = C()
c7 = C()
d = Container({'1': c1, '2': c2, '7': c7})
view = EditConfiguration(d, TestRequest())
view.remove_objects(['2', '7'])
self.assertEqual(d, {'1': c1})
self.failUnless(
getEvents(IObjectRemovedEvent,
filter = lambda event: event.object == c2),
)
self.failUnless(
getEvents(IObjectRemovedEvent,
filter = lambda event: event.object == c7)
)
self.failUnless(
getEvents(IObjectModifiedEvent,
filter = lambda event: event.object == d)
)
def test_configInfo(self):
class V(BrowserView):
def setPrefix(self, p):
self._prefix = p
provideView(I, 'ItemEdit', IBrowserPresentation, V)
c1 = C()
c2 = C()
c7 = C()
d = Container({'1': c1, '2': c2, '7': c7})
view = EditConfiguration(d, TestRequest())
info = view.configInfo()
self.assertEqual(len(info), 3)
self.assertEqual(info[0]['name'], '1')
self.assertEqual(info[1]['name'], '2')
self.assertEqual(info[2]['name'], '7')
def test_suite():
return TestSuite((
makeSuite(Test),
))
if __name__=='__main__':
main(defaultTest='test_suite')
=== Added File Zope3/src/zope/app/browser/services/configuration/tests/test_namecomponentconfigurableview.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.
#
##############################################################################
"""Unit test for the generic NameComponentConfigurable view mixin
$Id: test_namecomponentconfigurableview.py,v 1.1 2003/03/21 21:09:34 jim Exp $
"""
from unittest import TestCase, TestSuite, main, makeSuite
from zope.interface import Interface
from zope.publisher.browser import TestRequest
from zope.app.tests.placelesssetup import PlacelessSetup
from zope.publisher.interfaces.browser import IBrowserPresentation
from zope.component.view import provideView
from zope.publisher.browser import BrowserView
from zope.app.browser.services.configuration \
import NameComponentConfigurableView
from zope.app.interfaces.traversing import ITraversable
class SM:
def __init__(self, **data):
self._data = data
def listConfigurationNames(self):
return self._data.keys()
def queryConfigurations(self, name):
return self._data[name]
class I(Interface): pass
class Registry:
__implements__ = I
def __init__(self, active):
self._active = active
def active(self):
return self._active
class ITestConfiguration(Interface): pass
class Configuration:
__implements__ = ITestConfiguration, ITraversable
def __init__(self, path):
self.componentPath = path
def traverse(self, name, parameters, original_name, furtherPath):
return self
class V(BrowserView):
_update = 0
def setPrefix(self, p):
self._prefix = p
def update(self):
self._update += 1
class AU(BrowserView):
def __str__(self):
return "/" + self.context.componentPath
class Test(PlacelessSetup, TestCase):
def test_update(self):
provideView(I, 'ChangeConfigurations', IBrowserPresentation, V)
provideView(ITestConfiguration, 'absolute_url', IBrowserPresentation,
AU)
r1 = Registry(None)
r2 = Registry(Configuration('1'))
r3 = Registry(Configuration('1'))
sm = SM(test1=r1, test2=r2, test3=r3)
services = NameComponentConfigurableView(sm, TestRequest()).update()
self.assertEqual(len(services), 3)
self.assertEqual(services[0]['name'], 'test1')
self.assertEqual(services[0]['active'], False)
self.assertEqual(services[0]['inactive'], True)
self.assertEqual(services[0]['view'].context, r1)
self.assertEqual(services[0]['view']._prefix, "test1")
self.assertEqual(services[0]['view']._update, 1)
self.assertEqual(services[0]['url'], None)
self.assertEqual(services[1]['name'], 'test2')
self.assertEqual(services[1]['active'], True)
self.assertEqual(services[1]['inactive'], False)
self.assertEqual(services[1]['view'].context, r2)
self.assertEqual(services[1]['view']._prefix, "test2")
self.assertEqual(services[1]['view']._update, 1)
self.assertEqual(services[1]['url'], '/1')
self.assertEqual(services[2]['name'], 'test3')
self.assertEqual(services[2]['active'], True)
self.assertEqual(services[2]['inactive'], False)
self.assertEqual(services[2]['view'].context, r3)
self.assertEqual(services[2]['view']._prefix, "test3")
self.assertEqual(services[2]['view']._update, 1)
self.assertEqual(services[2]['url'], '/1')
def test_suite():
return TestSuite((
makeSuite(Test),
))
if __name__=='__main__':
main(defaultTest='test_suite')