P
P
Pavel2017-08-03 12:39:22
Software testing
Pavel, 2017-08-03 12:39:22

How to authorize for a GET/POST request?

from webtest import TestApp

class TestRest:

    def test_create(self, user, testapp):

        res = testapp.get('/api/secret', extra_environ=dict(REMOTE_USER=user.email))
        assert res.status_code == 200


Gives 401. Authentication by the test through the form with this user passes without problems.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel, 2017-08-03
@toobinks

But this is how it works

res = testapp.get('/login')
form = res.forms['loginForm']
form['email'] = user.email
form['password'] = 'password'
res = form.submit().follow()

res = testapp.get('/api/secret')
assert res.status_code == 200

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question