[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/OFS/Services/Browser/tests - testComponentConfigURL.py:1.1.2.1 testNameConfigurableView.py:1.1.2.1
Marius Gedminas
mgedmin@codeworks.lt
Tue, 10 Dec 2002 14:16:01 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Services/Browser/tests
In directory cvs.zope.org:/tmp/cvs-serv28246/lib/python/Zope/App/OFS/Services/Browser/tests
Added Files:
Tag: named-component-configuration-branch
testComponentConfigURL.py testNameConfigurableView.py
Log Message:
Refactoring of configuration views:
- new interfaces INamedComponentConfiguration, INameConfigurable,
implemented in NamedComponentConfiguration, NameConfigurable, simplify
the case where configurations are identified by a name (service types,
connections, caches, queries, etc)
- common views for INamedComponentConfiguration, INameConfigurable
- refactored ServiceManager and ConnectionService to take advantage of the
new infrastructure
- incidentally wrote several unit tests for configuration classes
- removed caching from ComponentConnection.getComponent; this exposed a bug
in LocalEventService tests
=== Added File Zope3/lib/python/Zope/App/OFS/Services/Browser/tests/testComponentConfigURL.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: testComponentConfigURL.py,v 1.1.2.1 2002/12/10 19:15:59 mgedmin Exp $
"""
from unittest import TestCase, TestSuite, main, makeSuite
from Zope.App.OFS.Services.ServiceManager.tests.PlacefulSetup \
import PlacefulSetup
from Zope.App.OFS.Services.ServiceManager.ServiceManager import ServiceManager
from Zope.App.OFS.Services.ServiceManager.ServiceConfiguration \
import ServiceConfiguration
from Zope.App.Traversing import traverse
from Zope.Publisher.Browser.BrowserView import BrowserView
from Zope.Publisher.Browser.BrowserRequest import TestRequest
from Zope.App.OFS.Services.Browser.ComponentConfigURL import ComponentConfigURL
class V(BrowserView, ComponentConfigURL):
pass
class C:
pass
class TestComponentConfigURL(PlacefulSetup, TestCase):
# XXX reduce dependencies on ServiceManager package
def test(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_suite():
return TestSuite((
makeSuite(TestComponentConfigURL),
))
if __name__=='__main__':
main(defaultTest='test_suite')
=== Added File Zope3/lib/python/Zope/App/OFS/Services/Browser/tests/testNameConfigurableView.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 NameConfigurable view mixin
$Id: testNameConfigurableView.py,v 1.1.2.1 2002/12/10 19:15:59 mgedmin Exp $
"""
from unittest import TestCase, TestSuite, main, makeSuite
from Interface import Interface
from Zope.Publisher.Browser.BrowserRequest import TestRequest
from Zope.App.tests.PlacelessSetup import PlacelessSetup
from Zope.Publisher.Browser.IBrowserPresentation import IBrowserPresentation
from Zope.ComponentArchitecture.GlobalViewService import provideView
from Zope.Publisher.Browser.BrowserView import BrowserView
from Zope.App.OFS.Services.Browser.NameConfigurableView \
import NameConfigurableView
from Zope.App.Traversing.ITraversable 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 = NameConfigurableView(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')