Testing session in Plone 3.3

Testing session in Plone 3.3

Posted by Nejc Zupan at Jan 07, 2010 10:40 AM |
Filed under: ,

Yesterday, while I was working on LifeInLjubljana.si, I had to test if some data was correctly written to Plone's session. I couldn't use the standard ptc.FunctionalTestCase test case as it does not have a session and I would get errors like this:

(Pdb) self.context.session_data_manager
*** AttributeError: session_data_manager
(Pdb) self.context.REQUEST.SESSION
*** AttributeError: SESSION

Following a tip on the Plone-Users mailing list and some trail-and-error I have come up with a solution. Below is my test case with which I can build functional tests for sessions:

class SessionFunctionalTestCase(ptc.FunctionalTestCase):
    """ We use this base class for all the session-related tests in this package. """
    
    def afterSetUp(self):
        # Set up sessioning objects
        ztc.utils.setupCoreSessions(self.app)

    class Session(dict):
        def set(self, key, value):
            self[key] = value

    def _setup(self):
        ptc.FunctionalTestCase._setup(self)
        self.app.REQUEST['SESSION'] = self.Session()
Powered by DISQUS comment system
Filed under: ,
Twitter
RT @ iElectric: @CentrifuzijaTo bi slo :) Si prepripravljena delit stroske? :D Feb 02, 2012 09:58 AM
RT @ nzupan: Everything you need in a foreign city is a Plonista. Everything else sorts itself out. #plone #best #community #ever Feb 01, 2012 02:02 PM
RT @ iElectric: Jenkins (JVM) crashes after few minutes after start http://t.co/NSsnxmQf Jan 31, 2012 09:39 PM
RT @ iElectric: #python tip: date(time) objects have .replace() method: datetime.datetime.now().replace(hour=0, minute=0, second=0, m... Jan 31, 2012 05:56 PM
RT @ nzupan: Arrived to #barcelona! Jan 31, 2012 12:42 PM
RT @ iElectric: When #android is installed in cars, so streaming music with mpd is straightforward from my home, I'm buying one. Jan 29, 2012 05:11 PM
RT @ iElectric: OH: wordpress is an unauthenticated remote shell that, as a useful side feature, also contains a blog Jan 29, 2012 04:43 PM
RT @ iElectric: Wohoo, I can finally not lose time with my music collection - http://t.co/TZmRbv3r Jan 29, 2012 04:06 PM
RT @ iElectric: In #gentoo one can patch sw by putting patches in correctly formatted folders and they will be applied before compili... Jan 29, 2012 02:05 AM
RT @ iElectric: Stop Internet #Censorship! Sign the urgent global petition @Avaaz urging the EU Parliament to reject #ACTA: http://t.... Jan 29, 2012 02:05 AM
RT @ BCSearch: We're back online. :) Read the blog post: http://t.co/uGhsz6VW http://t.co/pAqDOobU Jan 28, 2012 08:17 PM
RT @ nzupan: If you are managing a #plone site with many users, give collective.listusers a try! Jan 28, 2012 07:12 PM
RT @ BCSearch: A maintenance downtime coming up shortly! Jan 28, 2012 06:09 PM
RT @ nzupan: niteoweb.click2sell updated to support plone.app.testing, plus moved to GitHub and http://t.co/e1WHmvMd! #plone @click2 Jan 28, 2012 06:09 PM
RT @ nzupan: Wow, I just got a 7-fold decrease in one of my buildout's run time, thanks to @rosspatterson! You rock dude! #plone Jan 28, 2012 12:17 PM