Flask测试客户拒绝数据中的arobase?

时间:2016-01-13 12:15:06

标签: flask flask-testing

我试图在我的Flask中设置测试但由于未知原因,当我使用arobase添加参数时,Flask失败。

我在这里跟踪了片段http://flask.pocoo.org/snippets/26/并且可以成功发出请求(它有效),但是当我尝试发帖时,它失败了(有以下例外):

def test_auth_login_fail(self):
    """ Login fail """
    result = self.client.post(self._make_url("/auth/login"), data=dict(
        email="user@website.com",
        password='cxcxz'
    ))
    self.assertEqual(result.status_code, 404)

例外:

Traceback (most recent call last):
  File "/var/www/html/api/apps/auth/tests/login.py", line 20, in test_auth_login_fail
    password='cxcxz'
  File "/usr/lib/python2.7/site-packages/werkzeug/test.py", line 772, in post
    return self.open(*args, **kw)
  File "/usr/lib/python2.7/site-packages/flask/testing.py", line 108, in open
    follow_redirects=follow_redirects)
  File "/usr/lib/python2.7/site-packages/werkzeug/test.py", line 736, in open
    response = self.run_wsgi_app(environ, buffered=buffered)
  File "/usr/lib/python2.7/site-packages/werkzeug/test.py", line 659, in run_wsgi_app
    rv = run_wsgi_app(self.application, environ, buffered=buffered)
  File "/usr/lib/python2.7/site-packages/werkzeug/test.py", line 855, in run_wsgi_app
    app_iter = app(environ, start_response)
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "/var/www/html/api/utils/middlewares.py", line 55, in __call__
    return self.app(environ, start_response)
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1478, in full_dispatch_request
    response = self.make_response(rv)
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1577, in make_response
    rv = self.response_class.force_type(rv, request.environ)
  File "/usr/lib/python2.7/site-packages/werkzeug/wrappers.py", line 827, in force_type
    response = BaseResponse(*_run_wsgi_app(response, environ))
  File "/usr/lib/python2.7/site-packages/werkzeug/wrappers.py", line 57, in _run_wsgi_app
    return _run_wsgi_app(*args)
  File "/usr/lib/python2.7/site-packages/werkzeug/test.py", line 855, in run_wsgi_app
    app_iter = app(environ, start_response)
TypeError: 'tuple' object is not callable

对于信息,这不会产生异常:

def test_auth_login_fail(self):
        """ Login fail """
        result = self.client.post(self._make_url("/auth/login"), data=dict(
            email="userwebsite.com",
            password='cxcxz'
        ))
        self.assertEqual(result.status_code, 404)

(注意" @"删除)

我还删除了中间件(在追溯中表示)但没有取得多大成功。

我错过了什么?

1 个答案:

答案 0 :(得分:1)

看起来如果电子邮件是正确的,您从视图功能返回错误(元组)。当您传递格式错误的电子邮件时,您返回的值就可以了。