1

我正在为我在 Flask 中创建的应用程序的登录部分编写测试。但是,当我使用该test_client.post()方法传递数据时,我的测试数据没有被正确传递。

更重要的是,手动登录测试 POST 和重定向很好。

测试用例代码为:

# Ensure Login behaves correctly given the correct credentials
    def test_correct_login(self):
        tester = app.test_client(self)
        response = tester.post('/login',data= dict(username = 'bigtest', password = 'testing2'), follow_redirects = True, content_type='application/x-www-form-urlencoded')
        self.assertIn(b'Section title', response.data)

给出的响应显示用户名正确传递,但密码没有值。

这是控制台中返回的响应:

<div class="form-group required">
    <label class="control-label" for="username">username</label>
    <input class="form-control" id="username" name="username" required type="text" value="bigtest">
</div>
<div class="form-group required">
    <label class="control-label" for="password">password</label>
    <input class="form-control" id="password" name="password" required type="password" value="">

我不确定这里有什么问题。这种情况以前发生在其他人身上吗?

4

0 回答 0