"""conftest for integration tests.""" import os from typing import Any import pytest import requests from auth.auth import GrassAuth, UserType from tests.testutils.api_client.api_client import APIClient from tests.testutils.api_client.product_digital_api_client import ( ProductDigitalAPIClient, ) from tests.testutils.api_client.track_api_client import TrackAPIClient @pytest.fixture(scope="session") def workstation_user() -> dict[str, Any]: """Return data for workstation user.""" return {"user_id": 38271, "vendor_id": 7123} @pytest.fixture(scope="session", autouse=True) def get_large_tiff() -> None: """Download a large image file from s3 for tests, if file does not exist.""" giant_tiff_path = "tests/integration/assets/giant_image_300dpi.tiff" if not os.path.isfile(giant_tiff_path): img_data = requests.get( "https://s3.amazonaws.com/qa-orcd-raw-assets-load-testing/big_assets/giant_image_300dpi.tiff" ).content with open(giant_tiff_path, "wb") as handler: handler.write(img_data) def workstation_session_token(user_id: int) -> Any: """Initialize workstation grass auth token at start of test session.""" return GrassAuth(UserType.WORKSTATION, user_id).grass_token @pytest.fixture def workstation_api_client(workstation_user: dict[str, Any]) -> APIClient: """Create APIClient object with Workstation session token.""" return APIClient( os.environ["BASE_QA_GRASS_URL"], workstation_session_token(workstation_user["user_id"]), ) @pytest.fixture def workstation_api_client_d3() -> APIClient: """Create APIClient object with Workstation session token from D3 test account.""" return APIClient(os.environ["BASE_QA_GRASS_URL"], workstation_session_token(19453)) @pytest.fixture def workstation_product_digital_api_client( workstation_user: dict[str, Any], ) -> ProductDigitalAPIClient: """Create Product Digital APIClient with Workstation session token.""" return ProductDigitalAPIClient( os.environ["BASE_QA_GRASS_URL"], workstation_session_token(workstation_user["user_id"]), ) @pytest.fixture def workstation_track_api_client( workstation_user: dict[str, Any], ) -> TrackAPIClient: """Create Track APIClient object with Workstation session token.""" return TrackAPIClient( os.environ["BASE_QA_GRASS_URL"], workstation_session_token(workstation_user["user_id"]), ) @pytest.fixture def project_id() -> int: """Return a Project ID from QA.""" return 3938193 @pytest.fixture def product_data(project_id: int) -> dict[str, Any]: """Return a dictionary with product data.""" return { "format": "Full Length", "product_name": "My Product", "distribution_format_type": "digital", "upc": "", "project_id": project_id, "subaccount_id": None, } def valid_files() -> list[str]: """Return a list of valid files.""" return [ # https://pillow.readthedocs.io/en/5.1.x/handbook/concepts.html#modes # We support "L" mode "tests/integration/assets/l_mode_image.jpg", "tests/integration/assets/jpg_file.jpg", "tests/integration/assets/jpeg_file.jpeg", "tests/integration/assets/tif_file.tif", "tests/integration/assets/tiff_file.tiff", "tests/integration/assets/flac_file.flac", "tests/integration/assets/wav_file.wav", "tests/integration/assets/m4a_file.m4a", ] def big_image() -> list[str]: """Return a large image file.""" return ["tests/integration/assets/giant_image_300dpi.tiff"] @pytest.fixture def not_owned_id() -> int: """Return an not owned ID.""" return 11345435 @pytest.fixture def invalid_id() -> int: """Return an invalid ID.""" return 999999999999999 @pytest.fixture def wrong_dimensions() -> dict[str, str]: """Return code and description for a wrong dimension asset.""" return { "error_code": "image_wrong_aspect_ratio_error", "description": "Image has non-square aspect ratio", } @pytest.fixture def too_small() -> dict[str, str]: """Return code and description for a too small asset.""" return { "error_code": "image_too_small_dimensions_error", "description": "Image dimensions are too small", } @pytest.fixture def too_big() -> dict[str, str]: """Return code and description for a too large asset.""" return { "error_code": "image_too_large_dimensions_error", "description": "Image dimensions are too large", } @pytest.fixture def invalid_colors() -> dict[str, str]: """Return code and description for an invalid colors asset.""" return {"error_code": "image_invalid_mode", "description": "Invalid image mode"} @pytest.fixture def invalid_dpi() -> dict[str, str]: """Return code and description for an invalid DPI asset.""" return { "error_code": "image_wrong_dpi_error", "description": "Image file has wrong DPI", }