[Zope3-checkins] CVS: Zope3/src/zope/app/browser/services/tests - __init__.py:1.1.2.1 test_addservicecontainer.py:1.1.2.1 test_changeconfigurations.py:1.1.2.1 test_componentconfigurl.py:1.1.2.1 test_configurationstatuswidget.py:1.1.2.1 test_editconfiguration.py:1.1.2.1 test_field_widget.py:1.1.2.1 test_namecomponentconfigurableview.py:1.1.2.1 test_rolecontents.py:1.1.2.1
Jim Fulton
jim@zope.com
Mon, 23 Dec 2002 14:31:16 -0500
Update of /cvs-repository/Zope3/src/zope/app/browser/services/tests
In directory cvs.zope.org:/tmp/cvs-serv19908/zope/app/browser/services/tests
Added Files:
Tag: NameGeddon-branch
__init__.py test_addservicecontainer.py
test_changeconfigurations.py test_componentconfigurl.py
test_configurationstatuswidget.py test_editconfiguration.py
test_field_widget.py test_namecomponentconfigurableview.py
test_rolecontents.py
Log Message:
Initial renaming before debugging
=== Added File Zope3/src/zope/app/browser/services/tests/__init__.py ===
#
# This file is necessary to make this directory a package.
=== Added File Zope3/src/zope/app/browser/services/tests/test_addservicecontainer.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_addservicecontainer.py,v 1.1.2.1 2002/12/23 19:31:14 jim Exp $
"""
from unittest import TestCase, TestSuite, main, makeSuite
from zope.app.services.tests.placefulsetup \
import PlacefulSetup
from zope.component.service import defineService
from zope.interface import Interface
from zope.app.services.service import ServiceManager
from zope.component import getServiceManager
from zope.app.browser.services.service \
import AddServiceConfiguration
from zope.publisher.browser import TestRequest
from zope.app.browser.services.service import ComponentAdding
from zope.app.browser.services.package \
import PackagesContents
from zope.component import getService
from zope.component.exceptions import ComponentLookupError
from zope.app.browser.absoluteurl \
import AbsoluteURL, SiteAbsoluteURL
from zope.publisher.interfaces.browser import IBrowserPresentation
from zope.app.content.folder import IRootFolder
from zope.component.adapter import provideAdapter
from zope.app.interfaces.container import IZopeContainer
from zope.app.interfaces.container import IContainer
from zope.app.container.zope import ZopeContainerAdapter
from zope.app.interfaces.annotation import IAnnotatable
from zope.app.interfaces.annotation \
import IAttributeAnnotatable
from zope.app.attributeannotations import AttributeAnnotations
from zope.app.interfaces.annotation import IAnnotations
from zope.app.interfaces.dependable import IDependable
from zope.app.dependable import Dependable
from Zope.App.Traversing import traverse
from zope.component.view import provideView
from zope.component.view import setDefaultViewName
from zope.app.interfaces.services.configuration import IConfigurationStatus
from zope.app.browser.services.configurationstatuswidget \
import ConfigurationStatusWidget
from zope.schema.interfaces import IField, ITextLine, IText
from zope.app.browser.form.widget import TextWidget, TextAreaWidget
class I1(Interface): pass
class C: __implements__ = IAttributeAnnotatable, I1
class Test(PlacefulSetup, TestCase):
def setUp(self):
PlacefulSetup.setUp(self)
provideAdapter(IContainer, IZopeContainer, ZopeContainerAdapter)
provideAdapter(IAttributeAnnotatable,
IAnnotations, AttributeAnnotations)
provideAdapter(IAnnotatable, IDependable, Dependable)
self.buildFolders()
defineService('s1', I1)
self.folder1_1.setServiceManager(ServiceManager())
self.__Packages = traverse(
self.rootFolder, "folder1/folder1_1/++etc++Services/Packages")
self.__default = traverse(self.__Packages, 'default')
setDefaultViewName(IField, IBrowserPresentation, 'edit')
provideView(IConfigurationStatus, 'edit', IBrowserPresentation,
ConfigurationStatusWidget)
provideView(ITextLine, 'edit', IBrowserPresentation, TextWidget)
provideView(IText, 'edit', IBrowserPresentation, TextAreaWidget)
def test_services(self):
class I2(Interface): pass
class I3(Interface): pass
defineService('s2', I2)
defineService('s3', I3)
request = TestRequest()
view = AddServiceConfiguration(
ComponentAdding(self.__default, request), request)
# We need the ContentAdding to have a contentName. It normally
# gets set during traversal, but we aren't traversing here.
view.context.contentName = 'sd1'
services = list(view.services())
services.sort()
self.failUnless((('s1' in services) and
('s2' in services) and
('s3' in services)), services)
def test_components(self):
request = TestRequest(service_type='s1')
packages = self.__Packages
PackagesContents(packages, request).addPackage('p1')
PackagesContents(packages, request).addPackage('p2')
packages['default'].setObject('cd1', C())
packages['default'].setObject('cd2', C())
packages['p1'].setObject('c11', C())
packages['p2'].setObject('c21', C())
packages['p2'].setObject('c22', C())
view = AddServiceConfiguration(
ComponentAdding(self.__default, request), request)
# We need the ContentAdding to have a contentName. It normally
# gets set during traversal, but we aren't traversing here.
view.context.contentName = 'sd1'
components = list(view.components())
components.sort()
self.assertEqual(
components,
['/folder1/folder1_1/++etc++Services/Packages/default/cd1',
'/folder1/folder1_1/++etc++Services/Packages/default/cd2',
'/folder1/folder1_1/++etc++Services/Packages/p1/c11',
'/folder1/folder1_1/++etc++Services/Packages/p2/c21',
'/folder1/folder1_1/++etc++Services/Packages/p2/c22'])
def test_action_unregistered(self):
request = TestRequest()
self.__default.setObject('cd1', C())
view = AddServiceConfiguration(
ComponentAdding(self.__default, request), request)
# We need the ContentAdding to have a contentName. It normally
# gets set during traversal, but we aren't traversing here.
view.context.contentName = 'sd1'
view.action('s1',
'/folder1/folder1_1/++etc++Services/Packages/default/cd1',
)
self.assertRaises(ComponentLookupError,
getService, self.folder1_1_1, 's1')
def test_action_active(self):
service = C()
self.__default.setObject('cd1', service)
request = TestRequest()
view = AddServiceConfiguration(
ComponentAdding(self.__default, request), request)
# We need the ContentAdding to have a contentName. It normally
# gets set during traversal, but we aren't traversing here.
view.context.contentName = 'sd1'
request.form["field.status"] = u"Active"
view.action('s1',
'/folder1/folder1_1/++etc++Services/Packages/default/cd1')
self.assertEqual(getService(self.folder1_1_1, 's1'), service)
def test_action_register(self):
service = C()
self.__default.setObject('cd1', service)
request = TestRequest()
view = AddServiceConfiguration(
ComponentAdding(self.__default, request), request)
# We need the ContentAdding to have a contentName. It normally
# gets set during traversal, but we aren't traversing here.
view.context.contentName = 'sd1'
request.form["field.status"] = u"Active"
view.action('s1',
'/folder1/folder1_1/++etc++Services/Packages/default/cd1')
view.context.contentName = 'sd2'
self.__default.setObject('cd2', C())
request.form["field.status"] = u"Registered"
view.action('s1',
'/folder1/folder1_1/++etc++Services/Packages/default/cd2')
self.assertEqual(getService(self.folder1_1_1, 's1'), service)
def test_suite():
return makeSuite(Test)
if __name__=='__main__':
main(defaultTest='test_suite')
=== Added File Zope3/src/zope/app/browser/services/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.2.1 2002/12/23 19:31:14 jim Exp $
"""
from unittest import TestCase, TestSuite, main, makeSuite
from zope.publisher.browser import TestRequest
from zope.app.services.tests.testingconfigurationregistry \
import TestingConfigurationRegistry
class Test(TestCase):
def test_applyUpdates_and_setPrefix(self):
registry = TestingConfigurationRegistry('a', 'b', 'c')
request = TestRequest()
from zope.app.browser.services.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/src/zope/app/browser/services/tests/test_componentconfigurl.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.
#
##############################################################################
"""Tests for ComponentConfigURL
$Id: test_componentconfigurl.py,v 1.1.2.1 2002/12/23 19:31:14 jim Exp $
"""
from unittest import TestCase, TestSuite, main, makeSuite
from zope.app.services.tests.placefulsetup \
import PlacefulSetup
from zope.app.services.service import ServiceManager
from zope.app.services.service \
import ServiceConfiguration
from Zope.App.Traversing import traverse
from zope.publisher.browser import BrowserView
from zope.publisher.browser import TestRequest
from zope.app.browser.services.componentconfigurl import ComponentConfigURL
from zope.security.proxy import Proxy
from zope.security.checker import selectChecker
class V(BrowserView, ComponentConfigURL):
pass
class C:
pass
class ContextStub:
def __init__(self, path):
self.componentPath = path
class TestComponentConfigURL(PlacefulSetup, TestCase):
# XXX reduce dependencies on ServiceManager package
def test_componentURL(self):
self.buildFolders()
self.rootFolder.setServiceManager(ServiceManager())
default = traverse(
self.rootFolder,
'++etc++Services/Packages/default',
)
default.setObject('c', C())
traverse(default, 'configure').setObject(
'',
ServiceConfiguration('test_service',
'/++etc++Services/Packages/default/c')
)
config = traverse(default, 'configure/1')
view = V(config, TestRequest())
self.assertEqual(view.componentURL(),
'http://127.0.0.1/++etc++Services/Packages/default/c')
def test_componentPath(self):
context = ContextStub('/path/to/me')
view = V(context, TestRequest())
self.assertEqual(view.componentPath(), '/path/to/me')
context = ContextStub(('', 'path', 'to', 'me'))
view = V(context, TestRequest())
self.assertEqual(view.componentPath(), '/path/to/me')
path = ('', 'path', 'to', 'me')
wrapped_path = Proxy(path, selectChecker(path))
context = ContextStub(wrapped_path)
view = V(context, TestRequest())
self.assertEqual(view.componentPath(), '/path/to/me')
def test_suite():
return TestSuite((
makeSuite(TestComponentConfigURL),
))
if __name__=='__main__':
main(defaultTest='test_suite')
=== Added File Zope3/src/zope/app/browser/services/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.2.1 2002/12/23 19:31:14 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.configurationstatuswidget \
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/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.2.1 2002/12/23 19:31:14 jim Exp $
"""
__metaclass__ = type
from unittest import TestCase, TestSuite, main, makeSuite
from zope.interface import Interface
from zope.app.browser.services.service \
import EditConfiguration
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.component.adapter import provideAdapter
from zope.publisher.browser import BrowserView
from zope.app.event.tests.placelesssetup import getEvents
from zope.app.interfaces.event import IObjectRemovedEvent
from zope.app.interfaces.event import IObjectModifiedEvent
from zope.app.interfaces.container import IContainer
from zope.app.interfaces.container import IZopeContainer
from zope.app.container.zope import ZopeContainerAdapter
class Container(dict):
__implements__ = IContainer
class I(Interface):
pass
class C:
__implements__ = I
class Test(PlacelessSetup, 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]['key'], '1')
self.assertEqual(info[1]['key'], '2')
self.assertEqual(info[2]['key'], '7')
self.assertEqual(info[0]['view'].__class__, V)
self.assertEqual(info[0]['view'].context, c1)
self.assertEqual(info[0]['view']._prefix, 'config1')
self.assertEqual(info[1]['view'].__class__, V)
self.assertEqual(info[1]['view'].context, c2)
self.assertEqual(info[1]['view']._prefix, 'config2')
self.assertEqual(info[2]['view'].__class__, V)
self.assertEqual(info[2]['view'].context, c7)
self.assertEqual(info[2]['view']._prefix, 'config7')
def test_suite():
return TestSuite((
makeSuite(Test),
))
if __name__=='__main__':
main(defaultTest='test_suite')
=== Added File Zope3/src/zope/app/browser/services/tests/test_field_widget.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.
#
##############################################################################
"""ComponentLocationWidget tests.
$Id: test_field_widget.py,v 1.1.2.1 2002/12/23 19:31:14 jim Exp $
"""
from unittest import TestCase, TestSuite, main, makeSuite
from zope.app.services.tests.placefulsetup \
import PlacefulSetup
from Zope.App.Traversing import traverse
from zope.interface import Interface
from zope.app.services.service import ServiceManager
from zope.publisher.browser import TestRequest
from zope.app.browser.services.field import ComponentLocationWidget
class FakeComponentLocation:
default = None
def __init__(self, context, type):
self.context = context
self.type = type
def validate(self, value): pass
__name__ = 'X'
class I1(Interface): pass
class I2(Interface): pass
class C:
__implements__ = I1
class D:
__implements__ = I2
class Test(PlacefulSetup, TestCase):
def test(self):
self.buildFolders()
self.rootFolder.setServiceManager(ServiceManager())
default = traverse(self.rootFolder,
'++etc++Services/Packages/default')
default.setObject('c1', C())
default.setObject('c2', C())
default.setObject('c3', C())
default.setObject('d1', D())
default.setObject('d2', D())
default.setObject('d3', D())
request = TestRequest()
fake = FakeComponentLocation(default, I1)
widget = ComponentLocationWidget(fake, request)
expected = (
'<select name="field.X">\n'
'<option></option>\n'
'<option>/++etc++Services/Packages/default/c1</option>\n'
'<option>/++etc++Services/Packages/default/c2</option>\n'
'<option>/++etc++Services/Packages/default/c3</option>\n'
'</select>'
)
self.assertEqual(widget(), expected)
request.form['field.X'] = u'/++etc++Services/Packages/default/c2'
expected = (
'<select name="field.X">\n'
'<option></option>\n'
'<option>/++etc++Services/Packages/default/c1</option>\n'
'<option selected>/++etc++Services/Packages/default/c2</option>\n'
'<option>/++etc++Services/Packages/default/c3</option>\n'
'</select>'
)
self.assertEqual(widget(), expected)
def test_convert(self):
request = TestRequest()
fake = FakeComponentLocation(None, I1)
widget = ComponentLocationWidget(fake, request)
self.assertEqual(widget._convert(u''), None)
self.assertEqual(widget._convert(u'/a'), u'/a')
def test_suite():
return TestSuite((
makeSuite(Test),
))
if __name__=='__main__':
main(defaultTest='test_suite')
=== Added File Zope3/src/zope/app/browser/services/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.2.1 2002/12/23 19:31:14 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.namecomponentconfigurableview \
import NameComponentConfigurableView
from zope.app.interfaces.traversing.traversable 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')
=== Added File Zope3/src/zope/app/browser/services/tests/test_rolecontents.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_rolecontents.py,v 1.1.2.1 2002/12/23 19:31:14 jim Exp $
"""
import unittest
from zope.interface import Interface
from zope.app.browser.services.role import Contents
from zope.app.services.role import RoleService
from zope.app.browser.container.tests.test_contents \
import BaseTestContentsBrowserView
class IDummy(Interface):
pass
class Dummy:
__implements__ = IDummy
class Test(BaseTestContentsBrowserView, unittest.TestCase):
def _TestView__newContext(self):
return RoleService()
def _TestView__newView(self, container):
from zope.publisher.browser import TestRequest
return Contents(container, TestRequest())
def test_suite():
loader = unittest.TestLoader()
return loader.loadTestsFromTestCase( Test )
if __name__=='__main__':
unittest.main()