[Product-Developers] Problem with session object in Functional Testing

Taito Horiuchi taito.horiuchi at gmail.com
Wed Jul 30 12:10:36 UTC 2008


I would like to test session data objects and transient objects in
functional test, but have problem with it.
I just want to test if data submitted from form is stored as transient
objects.

I added "setupCoreSessions" to "afterSetUp" method like below to settle
session_data_manager under portal (self.app).

--------------------------------------------------------------------------------
    def afterSetUp( self ):
        # Set up sessioning objects
        ztc.utils.setupCoreSessions(self.app)
--------------------------------------------------------------------------------

Then I can find session_data_manager under app like below.

--------------------------------------------------------------------------------
   >>> app.objectIds()
    ['Control_Panel', 'plone', 'acl_users', 'temp_folder',
'browser_id_manager', 'session_data_manager']
   >>> app.session_data_manager
    <SessionDataManager at /session_data_manager>
--------------------------------------------------------------------------------

Data from template form is stored to newly created session object like
below.

--------------------------------------------------------------------------------
class MyView(BrowserView):
    """Default view
    """
    template = ViewPageTemplateFile('templates/my_view.pt')

    def __call__(self):

        form = self.request.form
        submit_botton = form.get('form.button.Submit', None) is not None

        # Defines
        context= aq_inner(self.context)
        sdm = getToolByName(context, "session_data_manager")

        if submit_button:
            session = sdm.getSessionData(create=True)
            session.set('data', form.get('data_from_form') )
            return self.template()

        else:
            return self.template()
--------------------------------------------------------------------------------

Here I expect when submit button is clicked,
session object is created if it does not exist yet, and transient object
{'data' : 'data_from_form'} is saved in the session object.
Actually it seems to do this when I test through browser,
like showing the data_from_form after clicking submit button works.

When I do functional test, weird thing happens.
Functional test says that there are no session data, but
rendered template shows the data!!

--------------------------------------------------------------------------------
    >>> browser.getControl('form.button.Submit').click()
    >>> 'data_from_form' in browser.contents
    True

    >>> sdm = getToolByName(portal, 'session_data_manager')
    >>> sdm.hasSessionData()
    True
--------------------------------------------------------------------------------

Here is the fail message.

--------------------------------------------------------------------------------
Failed example:
    sdm.hasSessionData()
Expected:
    True
Got:
    0
--------------------------------------------------------------------------------

I checked wheather there are any browse id.

--------------------------------------------------------------------------------
    >>> bim.getBrowserId(create=False)
    True
--------------------------------------------------------------------------------
Failed example:
    bim.getBrowserId(create=False)
Expected:
    True
Got nothing
--------------------------------------------------------------------------------

I'm quite confused.
Please somebody help me to find the session object and transient object
through functional test.

Regards,

Taito Horiuchi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.plone.org/pipermail/plone-product-developers/attachments/20080730/bf58b9f5/attachment-0001.html>


More information about the Product-Developers mailing list