[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/Services/RoleService/Views/Browser/tests - __init__.py:1.1.4.1 testAdder.py:1.1.4.1 testContents.py:1.1.4.1

Christian Theune ct@gocept.com
Sat, 25 May 2002 10:03:23 -0400


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

Added Files:
      Tag: Zope-3x-branch
	__init__.py testAdder.py testContents.py 
Log Message:
Merged the ctheune-services_move-branch to Zope-3x-branch

- Moved Zope.App.OFS.ServiceManager into the Zope.App.OFS.Services package
- Moved Zope.App.OFS.RoleService into the Zope.App.OFS.Services package



=== Added File Zope3/lib/python/Zope/App/OFS/Services/RoleService/Views/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/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.4.1 2002/05/25 14:03:21 ctheune Exp $
"""

from unittest import TestCase, TestSuite, main, makeSuite
from Zope.ComponentArchitecture import getService
from Zope.ComponentArchitecture.IFactory import IFactory
from Zope.App.OFS.Container.Exceptions import DuplicateIDError
from Zope.App.OFS.Services.ServiceManager.tests.PlacefulSetup import PlacefulSetup

class Role(object):
    __class_implements__ = IFactory

    def setId(self, id):
        self.id = id


    def getInterfaces():
        """Dummy stub."""
        pass

    def __call__():
        """A factory should always be callable."""
        pass


class Test(PlacefulSetup, 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):
        PlacefulSetup.setUp(self)
        getService(None,'Factories').provideFactory(
             "Zope.App.OFS.Services.RoleService.Role.", Role)

    def _TestView__newContext(self):
        from Zope.App.OFS.Services.RoleService.RoleService import RoleService
        return RoleService()

    def _TestView__newView(self, container):
        from Zope.App.OFS.Services.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/Services/RoleService/Views/Browser/tests/testContents.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: testContents.py,v 1.1.4.1 2002/05/25 14:03:21 ctheune Exp $
"""

import unittest

from Interface import Interface
from Zope.App.OFS.Services.RoleService.Views.Browser.Contents import Contents
from Zope.App.OFS.Services.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()