#930: Add standard way to unit test stateful/multiuser scenarios
------------------------+---------------------------------------------------
 Reporter:  thesamet    |       Owner:  anonymous                     
     Type:  defect      |      Status:  new                           
 Priority:  normal      |   Milestone:  1.0b1                         
Component:  TurboGears  |     Version:  0.9a6                         
 Severity:  normal      |    Keywords:  testing identity BroserSession
------------------------+---------------------------------------------------
 The current testing tools provided by TurboGears do not give “one
 obvious way” to test multi-user scenarios. I introduced last week a
 simple class that will emulate a browser session of a single user against
 a cherrypy server. Its only task is actually to keep track of the visit
 cookie.

 {{{
 def cookie_header(morsel):
     """Returns a dict containing cookie information to pass to a
 server."""
     return {'Cookie': morsel.output(header="")[1:]}

 class BrowserSession(object):
     def __init__(self):
         self.cookie_name = turbogears.config.get('visit.cookie.name', 'tg-
 visit')
         self.visit = None
         self.response, self.status = None, None

     def goto(self, *args, **kwargs):
         if self.visit:
             headers = kwargs.get('headers', {})
             headers.update(cookie_header(self.visit))
             kwargs['headers'] = headers
         testutil.createRequest(*args, **kwargs)
         if self.cookie_name in cherrypy.response.simple_cookie:
             self.visit = cherrypy.response.simple_cookie[self.cookie_name]
         self.response = cherrypy.response.body[0]
         self.status = cherrypy.response.status
 }}}

 Some usage examples appear in my blog post:
 [http://thesamet.com/blog/2006/05/31/testing-multi-user-turbogears-
 applications/ Testing Multi User TurboGears Applications]

-- 
Ticket URL: <http://trac.turbogears.org/turbogears/ticket/930>
TurboGears <http://www.turbogears.org/>
TurboGears front-to-back web development
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears Tickets" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears-tickets
-~----------~----~----~----~------~----~------~--~---

Reply via email to