On Sat, May 27, 2006 8:52 am, Kevin Dangoor wrote:
>
> On 5/23/06, Jason Chu <[EMAIL PROTECTED] > wrote:
>
>> Our application ( http://oprius.com) uses identity extensively. I tried
>> a couple different methods to do unit tests on everything (using twill
>> and wsgi was working fine for one test/request per test module, but
>> nothing more) but never found something that worked well enough.
>>
>> The problem that I can see with create_request is that I have to create
>> cookies by hand (including authentication cookies). Do people just
>> inject values into the visit table and then reference them in cookies or
>> what?
>
> We could certainly make testing with identity easier. Just think of
> how you'd like the API to be in the ideal case... would you want to pass
> username/passwrod to create_request and have it basically log in and then
> perform the request under test?
>
> Kevin
From my preliminary research, if we made BrowserSession official,
alongside the DBTest class, things would probably be pretty sweet.
Jason
It seems like there is still an issue here with testing controllers using the testutil.call() method, rather than testutil.createRequest (). If a CherryPy method is decorated with an identity requirement, then Nadav's BrowserSession class works great. However, it does not call the controller method directly like testutil.call does(), so you are not just getting the controller's dictionary as a return value, you are getting the XML/HTML returned by the controller with the Kid template.
Currently, the testutil.call() method creates a minimal dummy CherryPy request object that can be passed to the controller, and then invokes the controller method directly. If the controller method is decorated with an @identity method, whether or not ' identity.on' is set to True, the request fails with an error:
"IdentityManagementNotEnabledException: An attempt was made to use a facility of the TurboGears Identity Management framework but identity management hasn't been enabled in the config file [via identity.on]."
It looks like this actually happens because the dummy CherryPy request does not have an 'identity' property. I've tried modifying the testutil.DummyRequest class to add an 'identity' property, but have given up because it would require complicated setup specific to the situation. What I would really like to see is a DummyRequest that just turned off identity for the call. I've tried calling turbogears.config.update to set 'identity.on' to False, but I still get the same failure.
Does anyone have any suggestions or (even better) working code?
Right now, I have to comment out the @identity decorator on the controller method to run my tests. Not very test-driven :)
Thanks,
- Bill
Bill Woodward [EMAIL PROTECTED] http://www.saifa.net
"I have more trouble with D. L. Moody than with any other man I ever met." -- D. L. Moody
s/D. L. Moody/Bill Woodward/g
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

