KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm trying to test my webapp2 handlers. To do this, I thought it would be a good idea to send a request to the handler e.g.: request = webapp2.Request.blank('/') # Get a response for that request. response = request.get_response(main.app) The problem is, response is mostly just a bunch of HTML etc. I want to look at what was passed to my jinja2 template from the handler before it was turned into HTML. I want my test to get at the state within the handler class code. I wan't to be able to see what certain variables looked like in the response handler, and then I want to see what the dict templates looks like before it was passed to render_to_response() I want to test these variables have the correct values. Here is my test code so far, but I'm stuck because response = request.get_response() just gives me a bunch of html and not the raw variables. import unittest import main import webapp2 class DemoTestCase(unittest.TestCase): def setUp(self): pass def tearDown(self): pass def testNothing(self): self.assertEqual(42, 21 + 21) def testHomeHandler(self): # Build a request object passing the URI path to be tested. # You can also pass headers, query arguments etc. request = webapp2.Request.blank('/') # Get a response for that request. response = request.get_response(main.app) # Let's check if the response is correct. self.assertEqual(response.status_int, 200) self.assertEqual(response.body, 'Hello, world!') if __name__ == '__main__': unittest.main() and here is my handler: class HomeHandler(BaseHandler): def get(self, file_name_filter=None, category_filter=None): file_names = os.listdir('blog_posts') blogs = [] get_line = lambda file_: file_.readline().strip().replace("<!--","").replace("-->&
Tags (comma-separated)
Save Edits
Cancel