Skip to content

Commit

Permalink
feat: Add validation for tags in Toontje Hoger 4 Absolute playlist se…
Browse files Browse the repository at this point in the history
…ctions
  • Loading branch information
drikusroor committed Jun 10, 2024
1 parent 474fe30 commit 8b0f924
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
43 changes: 31 additions & 12 deletions backend/experiment/rules/tests/test_toontjehoger_4_absolute.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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\']']
)
5 changes: 5 additions & 0 deletions backend/experiment/rules/toontjehoger_4_absolute.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 8b0f924

Please sign in to comment.