Flask-WTF / WTForms with Unittest fails validation, but works without Unittest

前端 未结 1 599
孤街浪徒
孤街浪徒 2020-12-16 00:14

When I run app normally and do login in browser, it works. But with Unittest it won\'t log me in .... , it returns login page again.
Both \"print rv.data\" just prints

相关标签:
1条回答
  • 2020-12-16 00:42

    You should set WTF_CSRF_ENABLED not CSRF_ENABLED - right now, Flask-WTForms is trying to validate your CSRF token, but you are not providing one:

    class TestCase(unittest.TestCase):
        def setUp(self):
            app.config['TESTING'] = True
            # Wrong key:
            # app.config['CSRF_ENABLED'] = False
            # Right key:
            app.config['WTF_CSRF_ENABLED'] = False
    
    0 讨论(0)
提交回复
热议问题