I have used pmock, but not with TurboGears. Have you seen  
turbogears.testutil? Creating in-memory sqlite databases is the  
easiest and most pleasant way to work that I've found.

The error you're getting is because you don't have a valid request  
(it's complaining about cherrypy.request not having a threadlocal  
value for your testing thread...) turbogears.testutil.create_request  
will do that for you.

Kevin

On Sep 5, 2006, at 6:38 AM, atwork wrote:

>
> Has anyone worked with pmock (http://pmock.sourceforge.net/) or any
> other mock framework?
>
> This would let me do real unit testing without the need of creating  
> any
> test data or re-run any "already tested" objects.
>
> Here's my test and controller, but I don't know how to bypass the  
> error
> below. AFAIK it fails because Root extends controllers.RootController?
> How would I mock this?
>
> test_pmock.py:
> from turbogtd.controllers import Root
> from pmock import *
>
> #Create Root
> root = Root()
>
> #Create mocks
> root.cherrypy = Mock()
> root.cherrypy.session = Mock()
>
> #set expectations
> root.cherrypy.session.expects(once()).get(eq('count'),eq(0))
>
> #call controller
> root.index()
>
> ----
>
> controllers.py:
> class Root(controllers.RootController):
>
>     @expose(template="turbogtd.templates.welcome")
>     def index(self):
>         count = cherrypy.session.get('count', 0) + 1
>         return dict()
>
> ----
>
> C:\projects\turboGTD>python turbogtd/tests/test_pmock.py
> Traceback (most recent call last):
>   File "turbogtd/tests/test_pmock.py", line 21, in ?
>     root.index()
>   File "<string>", line 3, in index
>   File
> "c:\python24\lib\site-packages\TurboGears-0.9a8-py2.4.egg\turbogears 
> \controllers.py",
> line 323, in expose
>     accept = cherrypy.request.headers.get('Accept', "").lower()
>   File
> "c:\python24\lib\site-packages\CherryPy-2.2.1-py2.4.egg\cherrypy 
> \__init__.py",
> line 42, in __getattr__
>     childobject = getattr(serving, self.__attrname__)
> AttributeError: 'thread._local' object has no attribute 'request'
>
>
> cheers,
> atwork
>
>
> >


--
Kevin Dangoor
TurboGears / Zesty News

email: [EMAIL PROTECTED]
company: http://www.BlazingThings.com
blog: http://www.BlueSkyOnMars.com




--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to