"""Integration tests for lambda function.""" import json import base64 import gzip import boto3 import pytest from tests.consts import config as test_config # noqa class TestSuccessfulCheck: """Test successful check.""" @pytest.fixture def product_id(self): """Fixture for product id.""" return 2237375 @pytest.fixture def lambda_payload(self, product_id): """Fixture for lambda payload.""" return json.dumps({'product_id': product_id}) @pytest.fixture def expected_decompressed_result(self): """Fixture for product metadata compressed result.""" return { 'product': { 'productId': 2237375, 'upc': '4050486998229', 'participations': [ { 'participated_as': 'performer', 'participant': { 'uuid': 'd66a2901-6b7b-48d9-adb3-fd57f26e7dd1', 'name': 'Norbert R. Stammberger' } }, { 'participated_as': 'featuring', 'participant': { 'uuid': '12d0caa2-e6ad-4742-b352-a79231a862f0', 'name': 'Emilio Berné' } }, { 'participated_as': 'producer', 'participant': { 'uuid': '3a6e0418-ae39-4012-b1b7-2298bd82f1cb', 'name': 'Norbert Stammberger' } } ], 'tracks': [ { 'tuid': '27081010', 'isrc': 'DEZ651711711', 'participations': [ { 'participated_as': 'performer', 'participant': { 'uuid': 'd66a2901-6b7b-48d9-adb3-fd57f26e7dd1', 'name': 'Norbert R. Stammberger' } }, { 'participated_as': 'featuring', 'participant': { 'uuid': '12d0caa2-e6ad-4742-b352-a79231a862f0', 'name': 'Emilio Berné' } }, { 'participated_as': 'producer', 'participant': { 'uuid': '3a6e0418-ae39-4012-b1b7-2298bd82f1cb', 'name': 'Norbert Stammberger' } }, { 'participated_as': 'track_writer', 'participant': { 'uuid': '3a6e0418-ae39-4012-b1b7-2298bd82f1cb', 'name': 'Norbert Stammberger' } } ], 'labelSoundRecording': { 'id': '8087d61b-f137-4343-97a5-c00e7957f450', 'isrc': 'DEZ651711711' } }, { 'tuid': '27081011', 'isrc': 'DEZ651711712', 'participations': [ { 'participated_as': 'performer', 'participant': { 'uuid': 'd66a2901-6b7b-48d9-adb3-fd57f26e7dd1', 'name': 'Norbert R. Stammberger' } }, { 'participated_as': 'featuring', 'participant': { 'uuid': '12d0caa2-e6ad-4742-b352-a79231a862f0', 'name': 'Emilio Berné' } }, { 'participated_as': 'producer', 'participant': { 'uuid': '3a6e0418-ae39-4012-b1b7-2298bd82f1cb', 'name': 'Norbert Stammberger' } }, { 'participated_as': 'track_writer', 'participant': { 'uuid': '3a6e0418-ae39-4012-b1b7-2298bd82f1cb', 'name': 'Norbert Stammberger' } } ], 'labelSoundRecording': { 'id': '352b559d-9144-4656-9a50-8c90259ec1bb', 'isrc': 'DEZ651711712' } } ] } } @pytest.fixture def lambda_response(self, lambda_payload): """Fixture for lambda invocation response.""" client = boto3.client('lambda', region_name=test_config.AWS_REGION) response = client.invoke( FunctionName=test_config.LAMBDA_NAME, InvocationType='RequestResponse', LogType='None', Payload=lambda_payload, ) return json.loads(response['Payload'].read().decode('utf-8')) def test_successful_invocation(self, lambda_response, expected_decompressed_result): """Test successful invocation.""" decompressed_result = gzip.decompress(base64.b85decode(lambda_response['product_metadata'])) assert json.loads(decompressed_result) == expected_decompressed_result