Coverage for tests/tests_api/auth.py: 100%
13 statements
« prev ^ index » next coverage.py v7.6.2, created at 2024-10-10 03:02 +0300
« prev ^ index » next coverage.py v7.6.2, created at 2024-10-10 03:02 +0300
1import config
2import pytest
3import requests
4from app import app
5from starlette.testclient import TestClient
8@pytest.fixture(scope="session")
9def token():
10 response = requests.post(
11 f"{config.KeycloakConfig.SERVER_URL}realms/SotransDev/protocol/openid-connect/token",
12 data={
13 "username": "testy_jux@mail.com",
14 "password": "fsdfsdfs3rt32r2423423",
15 "grant_type": "password",
16 "client_id": config.KeycloakConfig.CLIENT_ID,
17 "client_secret": config.KeycloakConfig.CLIENT_SECRET,
18 },
19 )
20 return response.json()["access_token"]
23@pytest.fixture(scope="session")
24def test_client(token):
25 with TestClient(
26 app, headers={"Authorization": f"Bearer {token}"}
27 ) as test_client:
28 yield test_client