"""Integration tests for Audio Attribute Suggestion Persister.""" from backend.connectors import mysql from backend.models.audio_attribute import TrackAudioAttributeSuggestions from backend.models.track_audio_attribute_persister import TrackAudioAttributePersister from tests.testutils import db SUGGESTIONS = [ {'attribute_id': 1, 'reasons': [{'type': 'spoken_word_check'}]}, {'attribute_id': 2, 'reasons': [{'type': 'keyword_match', 'keyword': 'remastered', 'on': 'track_name'}]}, ] @db.test_schema def test_write_audio_attribute_suggestions_inserts_one_row(): """Test that write_audio_attribute_suggestions inserts a single row with the suggestions JSON.""" TrackAudioAttributePersister.write_audio_attribute_suggestions( unique_track_id=182, suggestions=SUGGESTIONS, user_uuid='8955b4aa-2ad0-4b0b-a2ea-6f070554d6d0', review_queue_id=42, ) with mysql.db_session() as session: rows = ( session.query(TrackAudioAttributeSuggestions) .filter( TrackAudioAttributeSuggestions.unique_track_id == 182, TrackAudioAttributeSuggestions.review_queue_id == 42, ) .all() ) assert len(rows) == 1 assert rows[0].suggestions == SUGGESTIONS @db.test_schema def test_write_audio_attribute_suggestions_stores_correct_fields(): """Test that the inserted suggestion row stores all fields correctly.""" TrackAudioAttributePersister.write_audio_attribute_suggestions( unique_track_id=182, suggestions=SUGGESTIONS, user_uuid='8955b4aa-2ad0-4b0b-a2ea-6f070554d6d0', review_queue_id=99, ) with mysql.db_session() as session: row = ( session.query(TrackAudioAttributeSuggestions) .filter( TrackAudioAttributeSuggestions.unique_track_id == 182, TrackAudioAttributeSuggestions.review_queue_id == 99, ) .one() ) assert row.unique_track_id == 182 assert row.suggestions == SUGGESTIONS assert row.user_uuid == '8955b4aa-2ad0-4b0b-a2ea-6f070554d6d0' assert row.review_queue_id == 99