From 8b0f924193a60b0aeef3864a860805c9306982b6 Mon Sep 17 00:00:00 2001 From: Drikus Roor Date: Mon, 10 Jun 2024 15:35:02 +0200 Subject: [PATCH] feat: Add validation for tags in Toontje Hoger 4 Absolute playlist sections --- .../tests/test_toontjehoger_4_absolute.py | 43 +++++++++++++------ .../rules/toontjehoger_4_absolute.py | 5 +++ 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/backend/experiment/rules/tests/test_toontjehoger_4_absolute.py b/backend/experiment/rules/tests/test_toontjehoger_4_absolute.py index b95d3bacc..12855445c 100644 --- a/backend/experiment/rules/tests/test_toontjehoger_4_absolute.py +++ b/backend/experiment/rules/tests/test_toontjehoger_4_absolute.py @@ -57,12 +57,12 @@ def test_initializes_correctly(self): def test_validate_valid_groups(self): csv_data = ( - "Albania 2018 - Eugent Bushpepa,Mall,7.046,45.0,ToontjeHoger4Absolute/audio-1.mp3,1,1\n" - "Albania 2018 - Eugent Bushpepa,Mall,7.046,45.0,ToontjeHoger4Absolute/audio-2.mp3,2,2\n" - "Albania 2018 - Eugent Bushpepa,Mall,7.046,45.0,ToontjeHoger4Absolute/audio-3.mp3,3,3\n" - "Albania 2018 - Eugent Bushpepa,Mall,7.046,45.0,ToontjeHoger4Absolute/audio-4.mp3,4,4\n" - "Albania 2018 - Eugent Bushpepa,Mall,7.046,45.0,ToontjeHoger4Absolute/audio-5.mp3,5,5\n" - "Albania 2018 - Eugent Bushpepa,Mall,7.046,45.0,ToontjeHoger4Absolute/audio-6.mp3,6,6\n" + "Albania 2018 - Eugent Bushpepa,Mall,7.046,45.0,ToontjeHoger4Absolute/audio-1.mp3,a,1\n" + "Albania 2018 - Eugent Bushpepa,Mall,7.046,45.0,ToontjeHoger4Absolute/audio-2.mp3,c,2\n" + "Albania 2018 - Eugent Bushpepa,Mall,7.046,45.0,ToontjeHoger4Absolute/audio-3.mp3,a,3\n" + "Albania 2018 - Eugent Bushpepa,Mall,7.046,45.0,ToontjeHoger4Absolute/audio-4.mp3,b,4\n" + "Albania 2018 - Eugent Bushpepa,Mall,7.046,45.0,ToontjeHoger4Absolute/audio-5.mp3,c,5\n" + "Albania 2018 - Eugent Bushpepa,Mall,7.046,45.0,ToontjeHoger4Absolute/audio-6.mp3,b,6\n" ) playlist = PlaylistModel.objects.create(name='TestToontjeHoger5Tempo') playlist.csv = csv_data @@ -75,12 +75,12 @@ def test_validate_valid_groups(self): def test_validate_invalid_groups(self): csv_data = ( - "Albania 2018 - Eugent Bushpepa,Mall,7.046,45.0,ToontjeHoger4Absolute/audio-1.mp3,1,a\n" - "Albania 2018 - Eugent Bushpepa,Mall,7.046,45.0,ToontjeHoger4Absolute/audio-2.mp3,2,2\n" - "Albania 2018 - Eugent Bushpepa,Mall,7.046,45.0,ToontjeHoger4Absolute/audio-3.mp3,3,4\n" - "Albania 2018 - Eugent Bushpepa,Mall,7.046,45.0,ToontjeHoger4Absolute/audio-4.mp3,4,4\n" - "Albania 2018 - Eugent Bushpepa,Mall,7.046,45.0,ToontjeHoger4Absolute/audio-5.mp3,5,5\n" - "Albania 2018 - Eugent Bushpepa,Mall,7.046,45.0,ToontjeHoger4Absolute/audio-6.mp3,6,7\n" + "Albania 2018 - Eugent Bushpepa,Mall,7.046,45.0,ToontjeHoger4Absolute/audio-1.mp3,a,a\n" + "Albania 2018 - Eugent Bushpepa,Mall,7.046,45.0,ToontjeHoger4Absolute/audio-2.mp3,c,2\n" + "Albania 2018 - Eugent Bushpepa,Mall,7.046,45.0,ToontjeHoger4Absolute/audio-3.mp3,a,4\n" + "Albania 2018 - Eugent Bushpepa,Mall,7.046,45.0,ToontjeHoger4Absolute/audio-4.mp3,b,4\n" + "Albania 2018 - Eugent Bushpepa,Mall,7.046,45.0,ToontjeHoger4Absolute/audio-5.mp3,c,5\n" + "Albania 2018 - Eugent Bushpepa,Mall,7.046,45.0,ToontjeHoger4Absolute/audio-6.mp3,b,7\n" ) playlist = PlaylistModel.objects.create(name='TestToontjeHoger5Tempo') playlist.csv = csv_data @@ -93,3 +93,22 @@ def test_validate_invalid_groups(self): 'Groups in playlist sections should be sequential and unique from 1 to 6. E.g. [1, 2, 3, 4, 5, 6]' ] ) + + def test_validate_invalid_tags(self): + csv_data = ( + "Albania 2018 - Eugent Bushpepa,Mall,7.046,45.0,ToontjeHoger4Absolute/audio-1.mp3,a,1\n" + "Albania 2018 - Eugent Bushpepa,Mall,7.046,45.0,ToontjeHoger4Absolute/audio-2.mp3,c,2\n" + "Albania 2018 - Eugent Bushpepa,Mall,7.046,45.0,ToontjeHoger4Absolute/audio-3.mp3,a,3\n" + "Albania 2018 - Eugent Bushpepa,Mall,7.046,45.0,ToontjeHoger4Absolute/audio-4.mp3,b,4\n" + "Albania 2018 - Eugent Bushpepa,Mall,7.046,45.0,ToontjeHoger4Absolute/audio-5.mp3,c,5\n" + "Albania 2018 - Eugent Bushpepa,Mall,7.046,45.0,ToontjeHoger4Absolute/audio-6.mp3,d,6\n" + ) + playlist = PlaylistModel.objects.create(name='TestToontjeHoger5Tempo') + playlist.csv = csv_data + playlist.update_sections() + + toontje_hoger_4_absolute = ToontjeHoger4Absolute() + self.assertEqual( + toontje_hoger_4_absolute.validate_playlist(playlist), + ['Tags in playlist sections should be \'a\', \'b\' or \'c\'. This playlist has tags: [\'a\', \'b\', \'c\', \'d\']'] + ) diff --git a/backend/experiment/rules/toontjehoger_4_absolute.py b/backend/experiment/rules/toontjehoger_4_absolute.py index 4798d8966..b2ca8f7c7 100644 --- a/backend/experiment/rules/toontjehoger_4_absolute.py +++ b/backend/experiment/rules/toontjehoger_4_absolute.py @@ -196,4 +196,9 @@ def validate_playlist(self, playlist: Playlist): if groups != list(map(str, range(1, len(groups) + 1))): errors.append(f"Groups in playlist sections should be sequential and unique from 1 to {len(groups)}. E.g. {list(range(1, len(groups) + 1))}") + # Check if the tags are 'a', 'b' or 'c' + tags = list(playlist.section_set.values_list('tag', flat=True).distinct()) + if tags != ['a', 'b', 'c']: + errors.append("Tags in playlist sections should be 'a', 'b' or 'c'. This playlist has tags: {}".format(tags)) + return errors