烧瓶单元测试返回400

时间:2019-06-26 15:08:31

标签: python unit-testing flask

我正在为烧瓶中的过滤器功能编写单元测试。

该应用在本地运行良好,但单元测试抛出400。谢谢! 另外,当我直接转到过滤器功能的URL时,我也收到错误400,并且将name = request.form ['name']标记为错误代码

这是我的.py

def filter():
    if request.method == 'POST':
        name = request.form['name']
        dozent = request.form['dozent']
        datum_von = request.form['datum_von']
        datum_bis = request.form['datum_bis']

.html

<form action="{{ url_for('.filter') }}" method="post">
    <h6>Seminarname</h6>
    <input type="text" name="name" value="{{ name }}">
    <h6>Dozentname</h6>
    <input type="text" name="dozent" value="{{ dozent }}">
    <h6>Von</h6>
    <input type="date" name="datum_von" value="{{ datum_von }}">
    <h6>Bis</h6>
    <input type="date" name="datum_bis" value="{{ datum_bis }}">
    <input type="submit" value="Filter anwenden">
</form>

单元测试

def test_filter_name_start_logged_in(test_client):
    response = test_client.post('/semlistenundbelegen/filter',
                                    data=dict(name='Sem'),
                                    follow_redirects=True)

    assert response.status_code == 200

    assert b"SeminarBeispiel" in response.data
    assert b"DozentBeispiel" in response.data

0 个答案:

没有答案