"""conftest. This file gets picked up when running py.test tests: http://pytest.org/latest/writing_plugins.html#conftest """ from os import getenv from auth.auth import GrassAuth from auth.auth import UserType import pytest from jwtauth.testing.schemas import SecretLookupInfo from tests.testutils.api_client import APIClient pytest_plugins = ["jwtauth.testing.pytest_plugin"] @pytest.fixture(scope='session') def grass_base_url() -> str: """Base URL for APIClient fixtures, proxied through ows-grass""" return getenv('BASE_QA_GRASS_URL', 'https://workstation.qaorch.com/grass') @pytest.fixture(scope='session') def grass_base_url_track(grass_base_url: str) -> str: """Base URL for APIClient fixtures, proxied through ows-grass""" return f'{grass_base_url}/track' @pytest.fixture(scope='session') def base_url() -> str: """Base URL for APIClient fixtures""" return getenv('BASE_QA_URL', 'https://qa-ows-track.theorchard.io') @pytest.fixture def tuid(): """Track ID of QA track fixture.""" return 26885740 @pytest.fixture def product_id(): """Product ID of QA product with tracks.""" return 2587640 @pytest.fixture(scope='session') def session_token(): """Initializes grass auth token at start of test session.""" return GrassAuth(UserType.WORKSTATION, 16888).grass_token @pytest.fixture def api_client(grass_base_url: str, session_token): """Creates APIClient object with QA URL and session token.""" return APIClient(grass_base_url, session_token) @pytest.fixture def tuid_for_attributes(): """Track ID of QA track fixture.""" return 8083353 @pytest.fixture(scope='session') def content_reviewer_pp_token(generate_bearer_token, jwtauth_secrets_manager) -> str: """Auth0 JWT for the PP content_reviewer test user.""" return generate_bearer_token( get_user_creds_args=SecretLookupInfo( environment='qa', service_name='ows-track-integration-test', secret_name='OWS_TRACK_CONTENT_REVIEWER_PP_USER_CREDENTIALS', ), get_auth0_creds_args=SecretLookupInfo( environment='qa', service_name='ows-track-integration-test', secret_name='OWS_TRACK_CONTENT_APP_AUTH0_CREDENTIALS', ), secrets_manager=jwtauth_secrets_manager, ) @pytest.fixture def content_reviewer_pp_client(grass_base_url: str, content_reviewer_pp_token: str): """APIClient pre-configured with the PP content_reviewer's Bearer token.""" return APIClient( base_url=grass_base_url, headers={ 'Orchard-Requestor-Service': 'graphql-content_reviewer_profile_client', 'Authorization': 'Bearer {}'.format(content_reviewer_pp_token), }, ) @pytest.fixture(scope='session') def content_reviewer_profile_token(generate_bearer_token, jwtauth_secrets_manager) -> str: """Auth0 JWT for the Profile content_reviewer test user.""" return generate_bearer_token( get_user_creds_args=SecretLookupInfo( environment='qa', service_name='ows-track-integration-test', secret_name='OWS_TRACK_CONTENT_REVIEWER_PROFILE_USER_CREDENTIALS', ), get_auth0_creds_args=SecretLookupInfo( environment='qa', service_name='ows-track-integration-test', secret_name='OWS_TRACK_CONTENT_APP_AUTH0_CREDENTIALS', ), secrets_manager=jwtauth_secrets_manager, ) @pytest.fixture def content_reviewer_profile_client(grass_base_url: str, content_reviewer_profile_token: str): """APIClient pre-configured with the Profile content_reviewer's Bearer token.""" return APIClient( base_url=grass_base_url, headers={ 'Orchard-Requestor-Service': 'graphql-content_reviewer_profile_client', 'Authorization': 'Bearer {}'.format(content_reviewer_profile_token), 'Orchard-Profile-Type': 'ContentProfile', 'Orchard-Profile-Id': '1823925803', 'Orchard-Roles': 'review_digital_audio' }, )