Как я должен решить проблемы запроса, которые 'ImmutableMultiDict ([])', используя request.form? - PullRequest
0 голосов
/ 24 августа 2018

Я пишу тестовый код с помощью pytest и пытаюсь получить значения с помощью request.form. Но код возвращает ImmutableMultiDict ([]), хотя req.request.args имеет значения в app.test_request_context. Не могли бы вы дать мне советы по устранению этой ошибки?

Мой код:

def test_grant_type(app):
    path = '/oauth/token'
    payload = {'grant_type': 'client_credentials', 'scope': 'test_user'}
    auth_header = "client_id:client_secret"
    b64val = base64.b64encode(auth_header.encode('UTF-8'))
    headers = {'Authorization': 'Basic %s' % b64val.decode('UTF-8')}

    with app.test_request_context(path, method="POST") as req:
        req.request.args = payload
        req.request.headers = headers

    import pdb;
    pdb.set_trace()

    client_id = "test_user"
    assert "test_account_id"==get_grant_type(req.request, client_id)

Я получаю ошибку:

/Users/t/local/c/tests/auth.py(149)test_grant_type()
-> client_id = "test_user"
(Pdb) p req.request.form
ImmutableMultiDict([])
(Pdb) p request
<Request 'http://localhost/' [GET]>
(Pdb) p req.request
<Request 'http://localhost/oauth/token' [POST]>
(Pdb) p req.request.args
{'grant_type': 'client_credentials', 'scope': 'test_user'}
...