[Zope3-checkins] CVS: Zope3/src/zope/app/registration/browser/tests - __init__.py:1.1 test_changeregistrations.py:1.1 test_componentpathwidget.py:1.1 test_editregistration.py:1.1 test_registrationstatuswidget.py:1.1 test_registrationview.py:1.1

Stephan Richter srichter at cosmos.phy.tufts.edu
Sat Mar 13 13:01:19 EST 2004


Update of /cvs-repository/Zope3/src/zope/app/registration/browser/tests
In directory cvs.zope.org:/tmp/cvs-serv27233/src/zope/app/registration/browser/tests

Added Files:
	__init__.py test_changeregistrations.py 
	test_componentpathwidget.py test_editregistration.py 
	test_registrationstatuswidget.py test_registrationview.py 
Log Message:


Moved registration code to zope.app.registration. Created module aliases, so
that old ZODBs work.


=== Added File Zope3/src/zope/app/registration/browser/tests/__init__.py ===
#
# This file is necessary to make this directory a package.


=== Added File Zope3/src/zope/app/registration/browser/tests/test_changeregistrations.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.
#
##############################################################################
"""Registration Change Tests

$Id: test_changeregistrations.py,v 1.1 2004/03/13 18:01:18 srichter Exp $
"""

from unittest import TestCase, TestSuite, main, makeSuite
from zope.publisher.browser import TestRequest
from zope.app.registration.tests.registrationstack \
     import TestingRegistrationStack
from zope.app.registration.browser import ChangeRegistrations

class Test(TestCase):

    def test_applyUpdates_and_setPrefix(self):
        registry = TestingRegistrationStack('a', 'b', 'c')
        request = TestRequest()
        view = ChangeRegistrations(registry, request)
        view.setPrefix("Pigs")

        # Make sure we don't apply updates unless asked to
        request.form = {'Pigs.active': 'disable'}
        view.applyUpdates()
        self.assertEqual(registry._data, ('a', 'b', 'c'))

        # Now test disabling
        request.form = {'submit_update': '', 'Pigs.active': 'disable'}
        view.applyUpdates()
        self.assertEqual(registry._data, (None, 'a', 'b', 'c'))

        # Now test enabling c
        request.form = {'submit_update': '', 'Pigs.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/registration/browser/tests/test_componentpathwidget.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.
#
##############################################################################
"""ComponentPathWidget tests.

$Id: test_componentpathwidget.py,v 1.1 2004/03/13 18:01:18 srichter Exp $
"""
import unittest
from zope.app.tests import ztapi
from zope.app.registration.browser import ComponentPathWidget
from zope.app.registration.interfaces import IComponentRegistration
from zope.app.interfaces.traversing import IPhysicallyLocatable
from zope.app.interfaces.traversing import ITraverser, ITraversable
from zope.app.services.field import ComponentPath
from zope.app.location import LocationPhysicallyLocatable
from zope.app.traversing.adapters import Traverser, DefaultTraversable
from zope.app.tests import ztapi
from zope.component.tests.placelesssetup import PlacelessSetup
from zope.interface import implements, Interface
from zope.publisher.browser import TestRequest, BrowserView
from zope.app.container.contained import Contained

class Component(object):
    implements(Interface)

class SiteManagementFolder(object):
    foo = Component()

class RegistrationManager(object):
    pass

class Registration(Contained):
    implements(IComponentRegistration)

    path = 'foo'


class AbsoluteURL(BrowserView):

    def __str__(self):
        return 'something'
    

class ComponentPathWidgetTest(PlacelessSetup, unittest.TestCase):

    def setUp(self):
        super(ComponentPathWidgetTest, self).setUp()
        ztapi.provideAdapter(None, ITraverser, Traverser)
        ztapi.provideAdapter(None, ITraversable, DefaultTraversable)
        ztapi.provideAdapter(None, IPhysicallyLocatable,
                             LocationPhysicallyLocatable)
        ztapi.browserView(Interface, "absolute_url", AbsoluteURL)

        field = ComponentPath(None, title=u"Path")
        field.__name__ = u'path'

        folder = SiteManagementFolder()
        rm = RegistrationManager(); rm.__parent__ = folder
        reg = Registration(); reg.__parent__ = rm
        field = field.bind(reg)
        self.widget = ComponentPathWidget(field, TestRequest())

    def test_hidden(self):
        self.assertEqual(self.widget.hidden(), '')

    def test_hasInput(self):
        self.assertEqual(self.widget.hasInput(), True)
        self.widget.request.form['field.path'] = 'foo'
        self.assertEqual(self.widget.hasInput(), True)

    def test_getInputValue(self):
        self.assertEqual(self.widget.getInputValue(), 'foo')
        comp = Component()
        comp.__name__ = "path2"
        self.widget.context.context = comp
        self.assertEqual(self.widget.getInputValue(), 'path2')

    def test_call(self):
        self.assertEqual(
            self.widget(),
            '<a href="something/@@SelectedManagementView.html">foo</a>')
        comp = Component()
        comp.__name__ = "path2"
        self.widget.context.context = comp
        self.assertEqual(
            self.widget(),
            '<a href="something/@@SelectedManagementView.html">path2</a>')

    

def test_suite():
    return unittest.makeSuite(ComponentPathWidgetTest)

if __name__=='__main__':
    unittest.main(defaultTest='test_suite')


=== Added File Zope3/src/zope/app/registration/browser/tests/test_editregistration.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.
#
##############################################################################
"""Registration Editing Tests

$Id: test_editregistration.py,v 1.1 2004/03/13 18:01:18 srichter Exp $
"""
from zope.app.tests import ztapi
from unittest import TestCase, TestSuite, main, makeSuite
from zope.app.registration.browser import EditRegistration
from zope.app.container.interfaces import IContainer
from zope.app.container.interfaces import IObjectRemovedEvent
from zope.app.registration.interfaces import ActiveStatus
from zope.app.interfaces.traversing import IContainmentRoot
from zope.app.site.tests.placefulsetup import PlacefulSetup
from zope.interface import Interface, implements
from zope.publisher.browser import BrowserView
from zope.publisher.browser import TestRequest
from zope.app.container.contained import Contained

class Container(dict):
    implements(IContainer, IContainmentRoot)

class I(Interface):
    pass

class C(Contained):
    implements(I)
    status = ActiveStatus


class Test(PlacefulSetup, TestCase):

    def test_remove_objects(self):
        c1 = C()
        c2 = C()
        c7 = C()
        d = Container({'1': c1, '2': c2, '7': c7})
        view = EditRegistration(d, TestRequest())
        view.remove_objects(['2', '7'])
        self.assertEqual(d, {'1': c1})

    def test_configInfo(self):

        class V(BrowserView):
            def setPrefix(self, p):
                self._prefix = p

        ztapi.browserView(I, 'ItemEdit', V)

        c1 = C()
        c2 = C()
        c7 = C()
        d = Container({'1': c1, '2': c2, '7': c7})
        c1.__parent__ = d; c1.__name__ = '1'
        c2.__parent__ = d; c2.__name__ = '2'
        c7.__parent__ = d; c7.__name__ = '7'

        view = EditRegistration(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/registration/browser/tests/test_registrationstatuswidget.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.
#
##############################################################################
"""Registration Widget Tests

$Id: test_registrationstatuswidget.py,v 1.1 2004/03/13 18:01:18 srichter Exp $
"""
from unittest import TestCase, TestSuite, main, makeSuite
from zope.publisher.browser import TestRequest
from zope.app.registration.interfaces import RegistrationStatus
from zope.app.registration.browser import RegistrationStatusWidget
from zope.app.tests.placelesssetup import PlacelessSetup


class Test(PlacelessSetup, TestCase):

    def setUp(self):
        super(Test, self).setUp()
        
    def test_call(self):
        field = RegistrationStatus(__name__="status")
        request = TestRequest()
        widget = RegistrationStatusWidget(field, request)
        widget.setPrefix("f")

        text = ' '.join(widget().split())
        self.assertEqual(
            text,
            u'<input class="radioType" checked="checked" id="f.status.0" '
            u'name="f.status" type="radio" value="Unregistered" />'
            u'<label for="f.status.0">Unregistered</label>&nbsp;&nbsp;'
            u'<input class="radioType" id="f.status.1" name="f.status" '
            u'type="radio" value="Registered" />'
            u'<label for="f.status.1">Registered</label>&nbsp;&nbsp;'
            u'<input class="radioType" id="f.status.2" name="f.status" '
            u'type="radio" value="Active" />'
            u'<label for="f.status.2">Active</label>')

        request.form['f.status'] = u'Registered'
        text = ' '.join(widget().split())
        self.assertEqual(
            text,
            u'<input class="radioType" id="f.status.0" name="f.status" '
            u'type="radio" value="Unregistered" /><label '
            u'for="f.status.0">Unregistered</label>'
            u'&nbsp;&nbsp;'
            u'<input class="radioType" checked="checked" id="f.status.1" '
            u'name="f.status" type="radio" value="Registered" /><label '
            u'for="f.status.1">Registered</label>'
            u'&nbsp;&nbsp;'
            u'<input class="radioType" id="f.status.2" name="f.status" '
            u'type="radio" value="Active" /><label '
            u'for="f.status.2">Active</label>')

        widget.setRenderedValue("Active")
        text = ' '.join(widget().split())
        self.assertEqual(
            text,
            u'<input class="radioType" id="f.status.0" name="f.status" '
            u'type="radio" value="Unregistered" />'
            u'<label for="f.status.0">Unregistered</label>'
            u'&nbsp;&nbsp;'
            u'<input class="radioType" id="f.status.1" name="f.status" '
            u'type="radio" value="Registered" />'
            u'<label for="f.status.1">Registered</label>'
            u'&nbsp;&nbsp;'
            u'<input class="radioType" checked="checked" id="f.status.2" '
            u'name="f.status" type="radio" value="Active" />'
            u'<label for="f.status.2">Active</label>'
            )

        widget.setRenderedValue(u"Unregistered")
        text = ' '.join(widget().split())
        self.assertEqual(
            text,
            u'<input class="radioType" checked="checked" id="f.status.0" '
            u'name="f.status" type="radio" value="Unregistered" />'
            u'<label for="f.status.0">Unregistered</label>&nbsp;&nbsp;'
            u'<input class="radioType" id="f.status.1" name="f.status" '
            u'type="radio" value="Registered" />'
            u'<label for="f.status.1">Registered</label>&nbsp;&nbsp;'
            u'<input class="radioType" id="f.status.2" name="f.status" '
            u'type="radio" value="Active" />'
            u'<label for="f.status.2">Active</label>')


def test_suite():
    return TestSuite((
        makeSuite(Test),
        ))

if __name__=='__main__':
    main(defaultTest='test_suite')


=== Added File Zope3/src/zope/app/registration/browser/tests/test_registrationview.py ===
##############################################################################
#
# Copyright (c) 2003 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 the RegistrationView view class.

$Id: test_registrationview.py,v 1.1 2004/03/13 18:01:18 srichter Exp $
"""
from zope.interface import implements
from zope.publisher.browser import TestRequest
from zope.testing.doctestunit import DocTestSuite

from zope.app.registration.interfaces import IRegistered
from zope.app.registration.interfaces import RegisteredStatus
from zope.app.registration.interfaces import ActiveStatus

from zope.app.registration.browser import RegistrationView


def test():
    """
    >>> request = TestRequest()

    Check results when using an unregisted object:

    >>> view = RegistrationView(FakeRegisterable([]), request)
    >>> view.registered()
    0

    Returns for the active() and registration() methods are undefined
    for unregistred objects.

    The update() method shouldn't do anything with an action specified
    in the form:

    >>> request.response.setStatus(200)
    >>> view.update()
    >>> view.registered()
    0
    >>> request.response.getStatus()
    200

    This simulates submitting the form using the 'Activate' button:

    >>> request.form['activate'] = 'Activate'
    >>> view.update()
    >>> request.response.getStatus()
    302
    >>> request.response.getHeader('location')
    'addRegistration.html'

    Let's look at the case when the object has a single registration
    to begin with:

    >>> request = TestRequest()
    >>> reg = FakeRegistration(RegisteredStatus)
    >>> view = RegistrationView(FakeRegisterable([reg]), request)
    >>> view.active()
    0
    >>> view.registered()
    1
    >>> view.registration() is reg
    1

    Make sure calling update() without an action doesn't change the
    registration:

    >>> request.response.setStatus(200)
    >>> view.update()
    >>> request.response.getStatus()
    200
    >>> view.active()
    0
    >>> view.registered()
    1
    >>> view.registration() is reg
    1

    Now test activating the object:

    >>> request.form['activate'] = 'Activate'
    >>> request.response.setStatus(200)
    >>> view.update()
    >>> request.response.getStatus()
    200
    >>> view.active()
    1
    >>> view.registered()
    1
    >>> view.registration() is reg
    1
    >>> reg.status == ActiveStatus
    1

    Now test deactivating an active object:

    >>> request.form = {'deactivate': 'Deactivate'}
    >>> request.response.setStatus(200)
    >>> view.update()
    >>> request.response.getStatus()
    200
    >>> view.active()
    0
    >>> view.registered()
    1
    >>> view.registration() is reg
    1
    >>> reg.status == RegisteredStatus
    1
    """

def test_multiple_registrations():
    """
    >>> request = TestRequest()
    >>> reg1 = FakeRegistration(RegisteredStatus)
    >>> reg2 = FakeRegistration(ActiveStatus)
    >>> view = RegistrationView(FakeRegisterable([reg1, reg2]), request)
    >>> view.active()
    0
    >>> view.registered()
    1
    >>> view.registration() is reg1
    1

    Now make sure this view redirects us to the advanced registrations
    form since we have more than one registraion:

    >>> request.response.setStatus(200)
    >>> view.update()
    >>> request.response.getStatus()
    302

    """


class FakeRegisterable:
    implements(IRegistered)

    def __init__(self, usages):
        self._usages = usages

    def registrations(self):
        return self._usages

class FakeRegistration:

    def __init__(self, status):
        self.status = status


def test_suite():
    return DocTestSuite()




More information about the Zope3-Checkins mailing list