Can you share your unit test code for tg app?

Lucas


On Jan 18, 2008 8:30 AM, Barry Hart <[EMAIL PROTECTED]> wrote:
>
> I found the answer. I was setting cherrypy.root for each test. This was
> triggering the following code in turbogears.testutil.create_request():
>
>     if not hasattr(cherrypy.root, "started"):
>         startup.startTurboGears()
>         cherrypy.root.started = True
>
> Starting TurboGears a second time doesn't work - it resets the list of
> cherrypy filters, but visit tracking knows it's already running and
> therefore did not add itself to the list of cherrypy filters:
>
>     # Bail out if this extension is already running
>     global _manager
>     if _manager:
>         return
>
>     log.info("Visit Tracking starting")
>     # How long may the visit be idle before a new visit ID is assigned?
>     # The default is 20 minutes.
>     timeout = timedelta(minutes=turbogears.config.get("visit.timeout", 20))
>     # Create the thread that manages updating the visits
>     _manager = _create_visit_manager(timeout)
>
>     filter = VisitFilter()
>     # Temporary until tg-admin can call create_extension_model
>     create_extension_model()
>     # Install Filter into the root filter chain
>     if not hasattr(cherrypy.root, "_cp_filters"):
>         cherrypy.root._cp_filters = list()
>
>     cherrypy.root._cp_filters.append(filter)
>
> Solution: set cherrypy.root *once* for the whole test run, not for each
> individual test.
>
> Barry
>
>
> ----- Original Message ----
> From: Barry Hart <[EMAIL PROTECTED]>
> To: [email protected]
> Sent: Thursday, January 17, 2008 5:54:53 PM
> Subject: [TurboGears] Writing unit tests at the TG controller level
>
>
> I've written some controller unit tests that use the class
> turbogears.testutil.BrowsingSession. When I run one test at a time,
> everything is fine. But when I run all the tests at once, the second and
> subsequent tests fail with a 403 when they hit the login URL. I added some
> debug messages to the CherryPy applyFilters() function and I see that after
> the first test, 'VisitFilter' is no longer in CherryPy's list of filters. I
> think this explains the 403, but I have no idea why the filter disappeared.
> I also added a debug message to shutdown_extension() of turbogears.visit.api
> but that's not being printed.
>
> I'm running TurboGears 1.0.3 and CherryPy 2.2.1.
>
> Any ideas what is going wrong?
>
> Thanks,
> Barry
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" 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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to