Skip to content

pytest can't seem to access Redis session store #72

Answered by behai-nguyen
behai-nguyen asked this question in Q&A
Discussion options

You must be logged in to vote

With the helps of ChatGPT, I have the solution for it:

@pytest.mark.behai_only
def test_integration_valid_login(test_client):
    """
    Test /auth/token path with a valid credential.
    """

    try:
        login_data = {
            'username': 'behai_nguyen@hotmail.com',
            'password': 'password'
        }
        response = test_client.post(  
            '/auth/token', 
            data=login_data,
            headers={'Content-Type': 'application/x-www-form-urlencoded'}
        )

        assert response != None
        assert response.status_code == HTTPStatus.OK.value

        status = response.json()
        assert status['access_token'] == 'behai_nguyen@hotmail.com'

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by behai-nguyen
Comment options

You must be logged in to vote
1 reply
@behai-nguyen
Comment options

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