"""conftest for test product digital.""" from os import getenv from auth.auth import GrassAuth from auth.auth import UserType import pytest from jwtauth.testing.schemas import SecretLookupInfo from tests.integration.client import OwsProductDigital from tests.utils.api_client.api_client import APIClient pytest_plugins = ["jwtauth.testing.pytest_plugin"] # --------------------------------------------------------------------------- # Legacy fixtures (used by existing GrassAuth-based tests — do not remove) # --------------------------------------------------------------------------- @pytest.fixture() def d3_user(): """Return data of d3 user.""" return {'user_id': 19453, 'vendor_id': 16055} @pytest.fixture(scope='session') def test_user(): """Return data for workstation user.""" return {'user_id': 38271, 'vendor_id': 7123} @pytest.fixture() def d3_subaccount_1_user(): """Return data of d3 sub account 1 user.""" return {'user_id': 19897, 'vendor_id': 16055, 'subaccount_id': 1} @pytest.fixture() def d3_subaccount_2_user(): """Return data of d3 sub account 2 user.""" return {'user_id': 20139, 'vendor_id': 16055, 'subaccount_id': 2} @pytest.fixture def project_id_sub_1_proj1(): """Return a Project ID from QA belonging to sub account 1.""" return 3957506 @pytest.fixture def project_id_sub_1_proj2(): """Return a 2nd Project ID from QA belonging to sub account 1.""" return 3958209 @pytest.fixture def project_id_sub_2(): """Return a Project ID from QA belonging to sub account 2.""" return 3957507 def unsubmit_product_id(): """Return product ID for unsubmit test.""" return 2544106 def unsubmit_ec_product_id(): """Return error correction product ID for unsubmit test.""" return 2544110 @pytest.fixture() def product_in_error_correction(test_user): """Ensure unsubmit_ec_product_id() is in error_correction before the test and after.""" workstation_client = APIClient( getenv('BASE_QA_WORKSTATION_URL'), GrassAuth(UserType.WORKSTATION, test_user['user_id']).grass_token, ) product_id = unsubmit_ec_product_id() def _ensure_status(): get_response = workstation_client.get(product_id) assert get_response.status_code == 200, \ 'Setup GET failed with {}'.format(get_response.status_code) if get_response.json()['release_status'] != 'error_correction': unsubmit_response = workstation_client.unsubmit(product_id) assert unsubmit_response.status_code == 200, \ 'Setup unsubmit failed with {}'.format(unsubmit_response.status_code) _ensure_status() yield product_id _ensure_status() @pytest.fixture def checked_out_product_id(): """Return checked out product ID for unsubmit test.""" return 2544109 @pytest.fixture def vendor_id(): """Return vendor ID for the integration test account.""" return "7123" # --------------------------------------------------------------------------- # JWT fixtures — fetch bearer tokens from AWS Secrets Manager # --------------------------------------------------------------------------- _SERVICE = "ows-product-digital-integration-test" _AUTH0_SECRET = "OWS_PRODUCT_DIGITAL_INTEGRATION_TEST_APP_AUTH0_CREDENTIALS" @pytest.fixture(scope="session") def jwt(generate_bearer_token, jwtauth_secrets_manager) -> str: """Return JWT for the standard integration test user.""" return generate_bearer_token( get_user_creds_args=SecretLookupInfo( environment="qa", service_name=_SERVICE, secret_name="OWS_PRODUCT_DIGITAL_INTEGRATION_TEST_USER_CREDENTIALS", ), get_auth0_creds_args=SecretLookupInfo( environment="qa", service_name=_SERVICE, secret_name=_AUTH0_SECRET, ), secrets_manager=jwtauth_secrets_manager, ) @pytest.fixture(scope="session") def pp_jwt(generate_bearer_token, jwtauth_secrets_manager) -> str: """Return JWT for the PP user (bulk_create_digital_audio role).""" return generate_bearer_token( get_user_creds_args=SecretLookupInfo( environment="qa", service_name=_SERVICE, secret_name="OWS_PRODUCT_DIGITAL_INTEGRATION_TEST_PP_USER_CREDENTIALS", ), get_auth0_creds_args=SecretLookupInfo( environment="qa", service_name=_SERVICE, secret_name=_AUTH0_SECRET, ), secrets_manager=jwtauth_secrets_manager, ) @pytest.fixture(scope="session") def no_access_jwt(generate_bearer_token, jwtauth_secrets_manager) -> str: """Return JWT for the no-access user (no PP roles, no profiles).""" return generate_bearer_token( get_user_creds_args=SecretLookupInfo( environment="qa", service_name=_SERVICE, secret_name="OWS_PRODUCT_DIGITAL_INTEGRATION_TEST_NO_ACCESS_USER_CREDENTIALS", ), get_auth0_creds_args=SecretLookupInfo( environment="qa", service_name=_SERVICE, secret_name=_AUTH0_SECRET, ), secrets_manager=jwtauth_secrets_manager, ) # --------------------------------------------------------------------------- # HTTP client fixtures # --------------------------------------------------------------------------- @pytest.fixture(scope="session") def client(jwt: str) -> OwsProductDigital: """Return an authenticated client for the standard integration test user.""" return OwsProductDigital(jwt) @pytest.fixture(scope="session") def pp_client(pp_jwt: str) -> OwsProductDigital: """Return an authenticated client for the PP user.""" return OwsProductDigital(pp_jwt) @pytest.fixture(scope="session") def no_access_client(no_access_jwt: str) -> OwsProductDigital: """Return an authenticated client for the no-access user.""" return OwsProductDigital(no_access_jwt)