[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/RoleService/Views/Browser/tests - __init__.py:1.1.2.1 testAdder.py:1.1.2.1 testContents.py:1.1.2.1
Jim Fulton
jim@zope.com
Mon, 4 Mar 2002 17:19:29 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/RoleService/Views/Browser/tests
In directory cvs.zope.org:/tmp/cvs-serv32696/RoleService/Views/Browser/tests
Added Files:
Tag: Zope-3x-branch
__init__.py testAdder.py testContents.py
Log Message:
Added first-cut role service
=== Added File Zope3/lib/python/Zope/App/OFS/RoleService/Views/Browser/tests/__init__.py ===
=== Added File Zope3/lib/python/Zope/App/OFS/RoleService/Views/Browser/tests/testAdder.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
#
##############################################################################
"""
Revision information:
$Id: testAdder.py,v 1.1.2.1 2002/03/04 22:19:28 jim Exp $
"""
from unittest import TestCase, TestSuite, main, makeSuite
from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
from Zope.ComponentArchitecture import provideFactory
from Zope.ComponentArchitecture.IFactory import IFactory
from Zope.App.OFS.Container.Exceptions import DuplicateIDError
class Role(object):
__class_implements__ = IFactory
def setId(self, id):
self.id = id
class Test(CleanUp, TestCase):
"""Base adding tests
Subclasses need to define a method, '_TestView__newContext', that
takes no arguments and that returns a new test view context.
Subclasses need to define a method, '_TestView__newView', that
takes a context object and that returns a new test view.
Subclasses need to define a method, '_TestAdderView__registry', that
returns the appropriate registry.
"""
def setUp(self):
provideFactory("Zope.App.OFS.RoleService.Role.", Role)
def _TestView__newContext(self):
from Zope.App.OFS.RoleService.RoleService import RoleService
return RoleService()
def _TestView__newView(self, container):
from Zope.App.OFS.RoleService.Views.Browser.Adder import Adder
return Adder(container)
def testAdding(self):
"""
Does addition of a new object with the same ID as an existing
object fail?
"""
container = self._TestView__newContext()
fa = self._TestView__newView( container )
fa.action(id='foo' )
self.assertEquals(len(container.objectIds()), 1)
self.assertEquals(container.objectIds()[0], 'foo')
self.assertEquals(len(container.objectValues()), 1)
self.assertEquals(container.objectValues()[0].__class__, Role)
def testDuplicates( self ):
"""
Does addition of a new object with the same ID as an existing
object fail?
"""
container = self._TestView__newContext()
fa = self._TestView__newView(container)
fa.action(id='foo')
self.assertRaises(DuplicateIDError, fa.action, id='foo')
def test_suite():
return TestSuite([makeSuite(Test)])
if __name__=='__main__':
main(defaultTest='test_suite')
=== Added File Zope3/lib/python/Zope/App/OFS/RoleService/Views/Browser/tests/testContents.py ===
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 1.1 (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: testContents.py,v 1.1.2.1 2002/03/04 22:19:28 jim Exp $
"""
import unittest
from Interface import Interface
from Zope.App.OFS.RoleService.Views.Browser.Contents import Contents
from Zope.App.OFS.RoleService.RoleService import RoleService
from Zope.App.OFS.Container.Views.Browser.tests.testContents \
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):
return Contents(container)
def test_suite():
loader = unittest.TestLoader()
return loader.loadTestsFromTestCase( Test )
if __name__=='__main__':
unittest.main()