"""Integration tests for lambda function.""" import json import gzip import base64 import boto3 import pytest from tests.consts import config as test_config # noqa class TestSuccessfulCheck: """Test successful check.""" @pytest.fixture def lambda_payload(self): """Fixture for lambda payload.""" data = { 'product': { 'productId': 3123694, 'upc': '886446701554', 'participations': [ { 'participated_as': 'performer', 'participant': { 'uuid': '8e961d0d-b426-4078-b345-f916e17a65d7', 'name': 'Fanny Andersen' } } ], 'tracks': [ { 'tuid': '33498005', 'isrc': 'NOXB61702010', 'participations': [ { 'participated_as': 'performer', 'participant': { 'uuid': '8e961d0d-b426-4078-b345-f916e17a65d7', 'name': 'FANNY' } }, { 'participated_as': 'producer', 'participant': { 'uuid': '61a27e57-564e-42ed-a950-978e69639fce', 'name': 'Kito' } }, { 'participated_as': 'track_writer', 'participant': { 'uuid': '8e961d0d-b426-4078-b345-f916e17a65d7', 'name': 'FANNY' } }, { 'participated_as': 'composer', 'participant': { 'uuid': 'd071fe79-7383-4769-b09f-8e80ef0eae0d', 'name': 'Maaike Lebbing' } }, { 'participated_as': 'track_writer', 'participant': { 'uuid': 'd071fe79-7383-4769-b09f-8e80ef0eae0d', 'name': 'Maaike Lebbing' } } ], 'labelSoundRecording': { 'id': 'e67cc021-9c7f-40c2-b9d2-3401b484e2c3', 'isrc': 'NOXB61702010' } } ] } } # Compress payload as it returns compressed from get-product-metadata comp = base64.b85encode(gzip.compress(json.dumps(data).encode('utf-8'))).decode('utf-8') return json.dumps({'product_metadata': comp}) @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): """Test successful invocation.""" assert lambda_response['status'] == 'OK' assert lambda_response['report'] == {}