Skip to content

How to test protected view with pytest ? #506

Answered by dvrg
dvrg asked this question in Q&A
Discussion options

You must be logged in to vote

i have checked several blog and tutorial and i doing this thing, but i have error that make me ask more about it.

i follow the instruction in documentation that testing configuration checklist and i create simple test to login (i'm using pytest and pytes-flask)

def test_security_login_page(client):
    rv = client.get(url_for_security("login"), follow_redirects=True)
    assert rv.status_code == HTTPStatus.OK
    assert b"Email" in rv.data
    assert b"Password" in rv.data


def test_security_login_user(client):
    rv = client.post(
        url_for_security("login"),
        data=dict(email=EMAIL, password=PASSWORD, follow_redirects=True),
    )
    assert rv.status_code == HTTPStatus.OK

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@jwag956
Comment options

@dvrg
Comment options

@jwag956
Comment options

@dvrg
Comment options

Answer selected by dvrg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants