How can I write a unit test for a tornado handler that authenticates a user via a secure cookie? Here is the code (and sudo code) for a dummy test that I\'d like to make pass. I
Using mock:
import mock
...
class UserAPITest(AsyncHTTPTestCase):
def get_app(self):
self.app = Application([('/', MainHandler)],
cookie_secret='asdfasdf')
return self.app
def test_user_profile_annoymous(self):
with mock.patch.object(MainHandler, 'get_secure_cookie') as m:
m.return_value = 'user_email'
response = self.fetch('/', method='GET')
self.assertEqual('sucess', to_unicode(response.body) )