Whenever I want to unit test the post controller it fails in the init() method of the MyApp class because the session is not instantiated:
AttributeError: 'thread._local' object has no attribute 'session'
So what is the correct way of testing the controller/action? How should I mock the post handler object?
I come from the .NET world in which with IoC/DI, you can mock the dependency of the controller (the handler, in this case) and pass it to the controller/action as a parameter.
But in this case in which the handler is instantiated inside the controller/action, how can that be done? Or should I mock the session, request and response objects themselves?
0
kevin-krac-10916 10 years ago
Great post!
Whenever I want to unit test the post controller it fails in the init() method of the MyApp class because the session is not instantiated:
AttributeError: 'thread._local' object has no attribute 'session'
So what is the correct way of testing the controller/action? How should I mock the post handler object?
I come from the .NET world in which with IoC/DI, you can mock the dependency of the controller (the handler, in this case) and pass it to the controller/action as a parameter.
But in this case in which the handler is instantiated inside the controller/action, how can that be done? Or should I mock the session, request and response objects themselves?
Thanks!