Pylons 控制器测试未通过请求参数
我们正在尝试为 Pylons 应用程序设置控制器测试。我做了一个非常简单的控制器和一个非常简单的测试。测试看起来像:
class TestMainController(TestController):
def test_index(self):
response = self.app.get(url(controller='main', action='index', var1 = '1'), params={'var2':'2'})
print response.req
assert False
同时,控制器看起来像这样:
class MainController(BaseController):
def index(self):
print request
print request.params
由于某种原因,当我们运行此代码时,我们得到以下输出:
-------------------- >> begin captured stdout << ---------------------
GET /_test_vars HTTP/1.0
Host: localhost:80
<Request at 0x36d6950 GET http://localhost/_test_vars>
UnicodeMultiDict([])
GET /main/index/?var1=1&var2=2 HTTP/1.0
Host: localhost:80
--------------------- >> end captured stdout << ----------------------
TestApp 认为它发送了正确的请求,但到达控制器的请求是错误的。有人知道这里发生了什么事吗?我们现在在测试中已经死了。
We're trying to setup controller tests for our Pylons app. I made a very simple controller and a very simple test. The tests looks like:
class TestMainController(TestController):
def test_index(self):
response = self.app.get(url(controller='main', action='index', var1 = '1'), params={'var2':'2'})
print response.req
assert False
Meanwhile, the controller looks something like this:
class MainController(BaseController):
def index(self):
print request
print request.params
For some reason, when we run this code, we get the following output:
-------------------- >> begin captured stdout << ---------------------
GET /_test_vars HTTP/1.0
Host: localhost:80
<Request at 0x36d6950 GET http://localhost/_test_vars>
UnicodeMultiDict([])
GET /main/index/?var1=1&var2=2 HTTP/1.0
Host: localhost:80
--------------------- >> end captured stdout << ----------------------
The TestApp thinks its sending the proper request, but the request that hits the controller is wrong. Anyone have any idea what's going on here? We're dead in the water on tests at the moment.
根据 Marius 的评论,事实证明我们正在做一个早期的请求来设置我们的应用程序。这个要求搞砸了。
As per Marius's comment, it turns out we were doing an earlier requset to setup a our app. That request was screwing with things.