【发布时间】:2014-01-22 20:12:20
【问题描述】:
我正在对 webapp2 应用程序进行单元测试,并想编写一个模拟文件发布的测试。如何在包含文件模拟内容的单元测试中创建请求对象?
import unittest
import webapp2
import main
file_contents = """id, first, last
1, Bruce, Banner
2, Tony, Stark
"""
class TestHandlers(unittest.TestCase):
def test_hello(self):
request = webapp2.Request.blank('/')
request.method = 'POST'
# Magic needed here.
#Put file_contents into a form parameter
response = request.get_response(main.app)
#Test that the returned text contains something from the posted file
self.assertEqual(True, "Bruce" in response.body)
【问题讨论】:
标签: python google-app-engine unit-testing webapp2