Reputation: 1512
Can someone please provide a multipart/form-data POST example based on:
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)
Upvotes: 1
Views: 776
Reputation: 1803
def test_submit_form(self):
app = TestApp(self.application)
response = app.post('/', { 'name': 'John' })
self.assertEqual('200 OK', response.status)
To test POST requests just use app.post()
instead of app.get()
. The second argument to app.post
is your form data.
See documentation for webtest.
Upvotes: 2