2012-03-01 172 views
1

是否有人可以提供的multipart/form-data发布例如:WebTest的谷歌应用程序引擎

How can I unit test responses from the webapp WSGI application in Google App Engine?

import unittest 
from webtest import TestApp 
from google.appengine.ext import webapp 
import index 

class IndexTest(unittest.TestCase): 

    def setUp(self): 
    self.application = webapp.WSGIApplication([('/', index.IndexHandler)], debug=True) 

    def test_default_page(self): 
    app = TestApp(self.application) 
    response = app.get('/') 
    self.assertEqual('200 OK', response.status) 
    self.assertTrue('Hello, World!' in response) 

    def test_page_with_param(self): 
    app = TestApp(self.application) 
    response = app.get('/?name=Bob') 
    self.assertEqual('200 OK', response.status) 
    self.assertTrue('Hello, Bob!' in response) 

回答

1
def test_submit_form(self): 
    app = TestApp(self.application) 
    response = app.post('/', { 'name': 'John' }) 
    self.assertEqual('200 OK', response.status) 

要测试POST请求只是使用app.post()代替app.get()app.post的第二个参数是您的表单数据。

See documentation for webtest