"""Tests for shared DDEX validation.""" from unittest.mock import patch import pytest from soundrecording_utils.constants.ddex.constants import RuleService from soundrecording_utils.ddex.validate import base_validation def test_base_validation_tiktok_raises_for_empty_track_name(mock_track): """It rejects missing/empty primary track names for TikTok.""" track_with_blank_name = mock_track._replace(name=' \x00 ') with pytest.raises( ValueError, match='The primary track name cannot be an empty string or missing.', ): base_validation(track_with_blank_name, RuleService.TIKTOK, selected_version='3.8') def test_base_validation_tiktok_v38_raises_when_artists_are_missing( mock_track, mock_track_participation, ): """It requires at least one display artist for v3.8 TikTok deliveries.""" track_without_display_artists = mock_track._replace( participations=[ mock_track_participation._replace(participated_as='non_display_role') ] ) with pytest.raises(ValueError, match='The artists are missing.'): base_validation( track_without_display_artists, RuleService.TIKTOK, selected_version='3.8', ) def test_base_validation_tiktok_v43_raises_when_artists_are_missing( mock_track, mock_track_participation, ): """It requires at least one display artist for v4.3 TikTok deliveries.""" track_without_display_artists = mock_track._replace( participations=[ mock_track_participation._replace(participated_as='non_display_role') ] ) with pytest.raises(ValueError, match='The artists are missing.'): base_validation( track_without_display_artists, RuleService.TIKTOK, selected_version='4.3', ) def test_base_validation_skips_tiktok_rules_for_other_services(mock_track): """Non-TikTok services are not validated by this helper yet.""" track_that_would_fail_tiktok_checks = mock_track._replace(name=' \x00 ', participations=[]) base_validation( track_that_would_fail_tiktok_checks, RuleService.YOUTUBE, selected_version='3.8', ) @patch('soundrecording_utils.ddex.validate.generate_track_display_artists_43') @patch('soundrecording_utils.ddex.validate.generate_track_display_artists_38') def test_base_validation_uses_v38_display_artist_generator( mocked_v38_generator, mocked_v43_generator, mock_track, ): """Version 3.8 selects the v38 artist generator.""" mocked_v38_generator.return_value = [object()] base_validation(mock_track, RuleService.TIKTOK, selected_version='3.8') mocked_v38_generator.assert_called_once_with(mock_track) mocked_v43_generator.assert_not_called() @patch('soundrecording_utils.ddex.validate.generate_track_display_artists_43') @patch('soundrecording_utils.ddex.validate.generate_track_display_artists_38') def test_base_validation_uses_v43_display_artist_generator( mocked_v38_generator, mocked_v43_generator, mock_track, ): """Any non-3.8 version selects the v43 artist generator.""" mocked_v43_generator.return_value = [object()] base_validation(mock_track, RuleService.TIKTOK, selected_version='4.3') mocked_v38_generator.assert_not_called() mocked_v43_generator.assert_called_once_with(mock_track)