from __future__ import annotations import logging from collections.abc import Iterator from typing import cast import httpx import pytest from secrets_manager.python_ext import PythonSecretsManager from tests.integration import config from tests.integration.utils import ( decode_token, generate_auth_token, get_identity_uuid, login_with_email, ) logger = logging.getLogger(__name__) @pytest.fixture(scope="session") def client() -> Iterator[httpx.Client]: client = httpx.Client( base_url=config.TEST_BASE_URL, verify=False, timeout=15, follow_redirects=False, ) yield client client.close() @pytest.fixture(scope="session") def shared_password() -> str: secrets_manager_client = PythonSecretsManager() return cast( str, secrets_manager_client.get_secret(config.AUTH0_INTEGRATION_TEST_USERS_PASSWORD), ) @pytest.fixture def authenticated_client_with_email( shared_password: str, request: pytest.FixtureRequest ) -> Iterator[httpx.Client]: email = getattr(request, "param", None) if not email: raise ValueError( "authenticated_client_with_email fixture requires an 'email' param" ) login_info = login_with_email(email=email, password=shared_password) token = generate_auth_token(login_info) identity_uuid = get_identity_uuid(decode_token(token)) client = httpx.Client( base_url=config.TEST_BASE_URL, verify=False, timeout=15, headers={ "Authorization": f"Bearer {token}", "Orchard-Identity-Id": f"{identity_uuid}", "Orchard-Identity-Uuid": f"{identity_uuid}", }, ) yield client client.close()