import uuid from typing import Any import pytest from common.connectors.graphql.schemas import HydrateMetadataResult from common.schemas.ingestion import BulkEvent from common.schemas.s3_reference import S3Reference from common.test_data.event import bulk_event_data @pytest.fixture def s3_filename() -> str: return str(bulk_event_data["key"]) @pytest.fixture def s3_bucket() -> str: return str(bulk_event_data["bucket"]) @pytest.fixture def bulk_session_id() -> str: return str(bulk_event_data["bulk_session_id"]) @pytest.fixture def bulk_session_ingestion_id() -> str: return str(bulk_event_data["bulk_session_ingestion_id"]) @pytest.fixture def identity_uuid() -> str: return str(uuid.uuid4()) @pytest.fixture() def event_data() -> dict[str, Any]: return bulk_event_data @pytest.fixture() def event() -> BulkEvent: return BulkEvent(**bulk_event_data) @pytest.fixture def s3_reference_data(s3_filename: str, s3_bucket: str) -> dict[str, Any]: return {"bucket": s3_bucket, "key": s3_filename} @pytest.fixture def s3_reference(s3_filename: str, s3_bucket: str) -> S3Reference: return S3Reference(key=s3_filename, bucket=s3_bucket) @pytest.fixture def hydrate_metadata_ok_response( s3_filename: str, s3_bucket: str, bulk_session_id: str ) -> HydrateMetadataResult: return HydrateMetadataResult( **{ "bulkSessionId": bulk_session_id, "s3Bucket": s3_bucket, "s3Filename": s3_filename, } ) @pytest.fixture def hydrate_metadata_graphql_hydration_error_response( s3_filename: str, ) -> dict[str, Any]: return { "data": None, "errors": [ { "message": "400: Bad Request", "locations": [{"line": 1, "column": 74}], "path": ["hydrateMetadata"], "extensions": { "response": { "url": f"https://ows-product-staging.theorchard.io/metadata-hydration/{s3_filename}", "status": 400, "statusText": "Bad Request", "body": { "code": "bad_request", "message": "metadata_hydration_error", "details": "1 validation error for ProductData\nproduct_info.product\n Value error, Can't set metadata_language_code.\nLanguage 'Unknown Language' not found. [type=value_error, input_value={'metadata_language_code'..., 'subaccount_id': None}, input_type=dict]\n For further information visit https://errors.pydantic.dev/2.11/v/value_error", }, }, "code": "INTERNAL_SERVER_ERROR", "stacktrace": [ "GraphQLError: 400: Bad Request", " at OwsProductStagingDataSource.errorFromResponse (/var/app/node_modules/@apollo/datasource-rest/dist/RESTDataSource.js:94:16)", " at OwsProductStagingDataSource.throwIfResponseIsError (/var/app/node_modules/@apollo/datasource-rest/dist/RESTDataSource.js:91:26)", " at OwsProductStagingDataSource.throwIfResponseIsError (/var/app/node_modules/@theorchard/datasource-ows/dist/cjs/src/owsDataSource.js:165:21)", " at /var/app/node_modules/@apollo/datasource-rest/dist/RESTDataSource.js:202:32", " at process.processTicksAndRejections (node:internal/process/task_queues:95:5)", " at async OwsProductStagingDataSource.trace (/var/app/node_modules/@theorchard/datasource-ows/dist/cjs/src/owsDataSource.js:176:16)", " at async OwsProductStagingDataSource.fetch (/var/app/node_modules/@apollo/datasource-rest/dist/RESTDataSource.js:250:21)", " at async OwsProductStagingDataSource.executeRequest (/var/app/node_modules/@theorchard/datasource-ows/dist/cjs/src/owsDataSource.js:108:24)", " at async OwsProductStagingDataSource.post (/var/app/node_modules/@theorchard/datasource-ows/dist/cjs/src/owsDataSource.js:200:17)", " at async OwsProductStagingDataSource.hydrateMetadata (/var/app/connectors/owsProductStaging/owsProductStaging.js:117:24)", ], }, } ], } @pytest.fixture def hydrate_metadata_graphql_general_error_response(s3_filename: str) -> dict[str, Any]: return { "data": None, "errors": [ { "message": "500: Internal Server Error", "locations": [{"line": 1, "column": 74}], "path": ["hydrateMetadata"], "extensions": { "response": { "url": f"https://ows-product-staging.theorchard.io/metadata-hydration/{s3_filename}", "status": 500, "statusText": "Internal Server Error", "body": { "code": "internal_error", "message": "The server encountered an internal error and was unable to complete your request.", }, }, "code": "INTERNAL_SERVER_ERROR", "stacktrace": [ "GraphQLError: 500: Internal Server Error", " at OwsProductStagingDataSource.errorFromResponse (/var/app/node_modules/@apollo/datasource-rest/dist/RESTDataSource.js:94:16)", " at OwsProductStagingDataSource.throwIfResponseIsError (/var/app/node_modules/@apollo/datasource-rest/dist/RESTDataSource.js:91:26)", " at OwsProductStagingDataSource.throwIfResponseIsError (/var/app/node_modules/@theorchard/datasource-ows/dist/cjs/src/owsDataSource.js:165:21)", " at /var/app/node_modules/@apollo/datasource-rest/dist/RESTDataSource.js:202:32", " at process.processTicksAndRejections (node:internal/process/task_queues:95:5)", " at async OwsProductStagingDataSource.trace (/var/app/node_modules/@theorchard/datasource-ows/dist/cjs/src/owsDataSource.js:176:16)", " at async OwsProductStagingDataSource.fetch (/var/app/node_modules/@apollo/datasource-rest/dist/RESTDataSource.js:250:21)", " at async OwsProductStagingDataSource.executeRequest (/var/app/node_modules/@theorchard/datasource-ows/dist/cjs/src/owsDataSource.js:108:24)", " at async OwsProductStagingDataSource.post (/var/app/node_modules/@theorchard/datasource-ows/dist/cjs/src/owsDataSource.js:200:17)", " at async OwsProductStagingDataSource.hydrateMetadata (/var/app/connectors/owsProductStaging/owsProductStaging.js:129:24)", ], }, } ], }