If you benefit from web2py hope you feel encouraged to pay it forward by contributing back to society in whatever form you choose!


  • 0
    kevin-krac-10916  10 years ago

    How do you unit test the controller/action?

    def index():
        post = Post('list_all')
        return post.render("mytheme/listposts")

     

    My first thought would be to mock the post handler Post('list_all') but not sure how this is done since the object is instantiated inside the action and is not injected via a method or constructor. So when I unit test this it fails when trying to access the session object downstream, when the handler instantiates the MyApp class.

    I come from the .NET world where it is common to mock the dependencies of the class under test, and that's it.

    But I'm not sure how to do it in this case? Could you help out?

     

    Thanks!

Commented on:

Create your datamodels in modules

Hosting graciously provided by:
Python Anywhere