我一直在开发烧瓶应用,但从未使用过unittest。我正在尝试编写如下测试:
import os
import unittest
from nextg_project_source import app, db, mail
TEST_DB = 'test.db'
app.config['BASEDIR'] = os.path.abspath(os.path.dirname(__file__))
class BasicTests(unittest.TestCase):
def setUp(self):
app.config['TESTING'] = True
app.config['WTF_CSRF_METHODS'] = []
app.config['DEBUG'] = True
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///'+ os.path.join(app.config['BASEDIR'], TEST_DB)
self.app = app.test_client()
db.drop_all()
db.create_all()
mail.init_app(app)
self.assertEqual(app.debug, False)
def tearDown(self):
pass
def login(self, email, password):
return self.app.post('/login', data=dict(email=email, password=password,
follow_redirects=True))
def vendor_register(self, email, password, confirm, op):
return self.app.post(
'/myregistration',
data=dict(email=email,
password= password,
confirm=confirm,
op='3'),
follow_redirects=True)
def logout(self):
return self.app.get('/logout', follow_redirects=True)
def test_main_page(self):
response = self.app.get('/', follow_redirects=True)
self.assertEqual(response.status_code, 200)
def test_valid_user_registration(self):
response = self.vendor_register('valid@gmail.com',
'password',
'password',
'3')
self.assertEqual(response.status_code, 200)
self.assertIn(b'Thanks for signing up', response.data)
def test_user_login(self):
response= self.login(‘valid@gmail.com', 'password')
self.assertEqual(response.status_code, 200)
if __name__ == "__main__":
unittest.main()
在我的烧瓶应用程序中,我正在使用Flask-Security,我已经自定义了注册表单,其中提交请求已发送到" / myregistration"还有一个额外的领域" op" 。我有几个问题
对于test_valid_user_registration给我这个:
追踪(最近一次通话): 在test_valid_user_registration中的文件" tests_basic.py",第55行 self.assertEqual(response.status_code,200) 断言错误:400!= 200
当我说断言(b'感谢您注册')时,这是否正在寻找我在重定向到/感谢新页面时使用的Flash消息?
由于