[Zope3-checkins] CVS: Zope3/src/zope/app/browser/services/registration/tests - test_registrationview.py:1.1

Fred L. Drake, Jr. fred at zope.com
Wed Sep 24 16:43:09 EDT 2003


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

Added Files:
	test_registrationview.py 
Log Message:
Added a new view to make it easier to support registration of objects
 that have at most one registration.


=== Added File Zope3/src/zope/app/browser/services/registration/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 2003/09/24 20:43:08 fdrake Exp $
"""

import unittest

from zope.interface import implements
from zope.publisher.browser import TestRequest
from zope.testing.doctestunit import DocTestSuite

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

from zope.app.browser.services.registration 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