def test_register_json_errors_get(self):
"""Test WEB register errors JSON works"""
with patch.dict(self.flask_app.config, {'WTF_CSRF_ENABLED': True}):
csrf = self.get_csrf('/account/register')
userdict = {'fullname': 'a', 'name': 'name',
'email_addr': None, 'password': 'p'}
res = self.app.post('/account/register', data=json.dumps(userdict),
content_type='application/json',
headers={'X-CSRFToken': csrf})
# The output should have a mime-type: application/json
errors = json.loads(res.data).get('form').get('errors')
assert res.mimetype == 'application/json', res.data
err_msg = "There should be an error with the email"
assert errors.get('email_addr'), err_msg
err_msg = "There should be an error with fullname"
assert errors.get('fullname'), err_msg
err_msg = "There should be an error with password"
assert errors.get('password'), err_msg
err_msg = "There should NOT be an error with name"
assert errors.get('name') is None, err_msg
评论列表
文章目录