Skip to content

Commit

Permalink
adding pytest fixture to get JWT token and append them to all the tes…
Browse files Browse the repository at this point in the history
…ting requests
  • Loading branch information
TaiHaDev committed Mar 12, 2024
1 parent 7943d5f commit 6ce4ac4
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

@pytest.fixture(scope='module')
def test_client():
print("hello")

# Set the Testing configuration prior to creating the Flask application
flask_app = create_app()

Expand All @@ -22,3 +20,20 @@ def test_client():
yield testing_client


@pytest.fixture(scope='module')
def auth_token(test_client):
# Login with predefined admin credentials
login_payload = { # admin account details
'email': 'admin',
'password': 'admin'
}
response = test_client.post('/authentication/login', json=login_payload)
assert response.status_code == 200, "Failed to log in with the given credential"
print(response.json)
token = response.json['access_token']
return token

# append jwt token to header of all the testing requests
@pytest.fixture(autouse=True)
def set_auth_header(test_client, auth_token):
test_client.environ_base['HTTP_AUTHORIZATION'] = f'Bearer {auth_token}'

0 comments on commit 6ce4ac4

Please sign in to comment.