"""Test match_audio model.""" import json import boto3 from moto import mock_aws from syrupy.assertion import SnapshotAssertion from assets.models import match_audio as match_audio_model @mock_aws def test_get_match_audio_results(snapshot: SnapshotAssertion) -> None: """Test get_match_audio_results.""" dynamodb = boto3.resource("dynamodb") table_name = "test_content_review_match_audio_match" table = dynamodb.create_table( TableName=table_name, KeySchema=[{"AttributeName": "asset_final_id", "KeyType": "HASH"}], AttributeDefinitions=[ {"AttributeName": "asset_final_id", "AttributeType": "N"} ], ProvisionedThroughput={"ReadCapacityUnits": 5, "WriteCapacityUnits": 5}, ) match_audio_results = [ {"matches": json.dumps({"matches": None})}, { "matches": json.dumps( {"matches": [{"artist": ["Artist"], "label": "something"}]} ) }, { "matches": json.dumps( {"matches": [{"artist": ["Artist"], "label": "ORCHARD - something"}]} ) }, ] * 49 match_audio_results.append( { "matches": json.dumps( { "matches": [ { "artist": ["Artist"], "rights_claim": [ {"distributor": {"name": "The Orchard Enterprises"}} ], } ] } ) } ) with table.batch_writer() as batch: for match_audio_result_index, match_audio_result in enumerate( match_audio_results ): batch.put_item( Item={ "asset_final_id": match_audio_result_index + 1, **match_audio_result, } ) checked_asset_final_id_to_track_id = { match_audio_result_index + 1: match_audio_result_index + 1 + len(match_audio_results) - 1 for match_audio_result_index, match_audio_result in enumerate( match_audio_results ) } unchecked_asset_final_id_to_track_id = {12321: 32123, 78987: 98789, 45645: 65456} asset_final_id_to_track_id = { **checked_asset_final_id_to_track_id, **unchecked_asset_final_id_to_track_id, } # Test the batching of requests sent to dynamo by ensuring # len(asset_final_id_to_track_id) greater than the batch size of 100. assert len(asset_final_id_to_track_id) > 100 result = match_audio_model.get_match_audio_results(asset_final_id_to_track_id) assert result == snapshot