From e348540a9ea3f1141b3a424cd3ac79308871662b Mon Sep 17 00:00:00 2001 From: allholy Date: Thu, 19 Dec 2024 14:52:13 +0100 Subject: [PATCH] Make tests pass after adding bst category --- accounts/tests/test_upload.py | 3 +++ sounds/forms.py | 1 + sounds/models.py | 2 ++ sounds/tests/test_sound.py | 3 +++ utils/sound_upload.py | 3 ++- 5 files changed, 11 insertions(+), 1 deletion(-) diff --git a/accounts/tests/test_upload.py b/accounts/tests/test_upload.py index 81490d2d0..d3979eec7 100644 --- a/accounts/tests/test_upload.py +++ b/accounts/tests/test_upload.py @@ -141,6 +141,7 @@ def test_describe_selected_files(self): '0-license': '3', '0-description': 'a test description for the sound file', '0-new_pack': '', + '0-bst_category': 'ss', '0-name': filenames[0], '1-audio_filename': filenames[1], '1-license': '3', @@ -167,6 +168,8 @@ def test_describe_selected_files(self): self.assertEqual(Pack.objects.filter(name='Name of a new pack').exists(), True) self.assertEqual(Tag.objects.filter(name__contains="testtag").count(), 5) self.assertNotEqual(user.sounds.get(original_filename=filenames[0]).geotag, None) + self.assertEqual(user.sounds.get(original_filename=filenames[0]).bst_category, 'ss') + self.assertEqual(user.sounds.get(original_filename=filenames[1]).bst_category, '') sound_with_sources = user.sounds.get(original_filename=filenames[1]) self.assertEqual(sound_with_sources.sources.all().count(), len(sound_sources)) diff --git a/sounds/forms.py b/sounds/forms.py index da0be3dd1..cd23d441b 100644 --- a/sounds/forms.py +++ b/sounds/forms.py @@ -247,6 +247,7 @@ class SoundEditAndDescribeForm(forms.Form): widget=forms.TextInput(attrs={'size': 65, 'class': 'inputText'})) bst_category = forms.ChoiceField( choices=Sound.BST_CATEGORY_CHOICES, + required=False ) tags = TagField( widget=forms.Textarea(attrs={'cols': 80, 'rows': 3}), diff --git a/sounds/models.py b/sounds/models.py index 90a24a334..bb10a06bf 100644 --- a/sounds/models.py +++ b/sounds/models.py @@ -432,6 +432,7 @@ def bulk_query_solr(self, sound_ids): sound.id, sound.type, sound.original_filename, + sound.bst_category, sound.is_explicit, sound.filesize, sound.md5, @@ -490,6 +491,7 @@ def bulk_query(self, where, order_by, limit, args, include_analyzers_output=Fals sound.type, sound.user_id, sound.original_filename, + sound.bst_category, sound.is_explicit, sound.avg_rating, sound.channels, diff --git a/sounds/tests/test_sound.py b/sounds/tests/test_sound.py index 5b6b411fa..14c232846 100644 --- a/sounds/tests/test_sound.py +++ b/sounds/tests/test_sound.py @@ -1174,12 +1174,14 @@ def test_update_description(self): new_name = 'New name' new_tags = ['tag1', 'tag2', 'tag3'] new_pack_name = 'Name of a new pack' + new_bst_category = 'ss' new_sound_sources = Sound.objects.exclude(id=self.sound.id) geotag_lat = 46.31658418182218 resp = self.client.post(reverse('sound-edit', args=[self.sound.user.username, self.sound.id]), { '0-sound_id': self.sound.id, '0-description': new_description, '0-name': new_name, + '0-bst_category': new_bst_category, '0-tags': ' '.join(new_tags), '0-license': '3', '0-sources': ','.join([f'{s.id}' for s in new_sound_sources]), @@ -1194,6 +1196,7 @@ def test_update_description(self): self.sound.refresh_from_db() self.assertEqual(self.sound.description, new_description) self.assertEqual(self.sound.original_filename, new_name) + self.assertEqual(self.sound.bst_category, new_bst_category) self.assertListEqual(sorted(self.sound.get_sound_tags()), sorted(new_tags)) self.assertEqual(self.sound.sources.all().count(), len(new_sound_sources)) self.assertTrue(Pack.objects.filter(name='Name of a new pack').exists()) diff --git a/utils/sound_upload.py b/utils/sound_upload.py index db9edabc6..0a7b61cd7 100644 --- a/utils/sound_upload.py +++ b/utils/sound_upload.py @@ -153,7 +153,8 @@ def create_sound(user, sound.user = user sound.original_filename = sound_fields['name'] sound.original_path = sound_fields['dest_path'] - sound.bst_category = sound_fields['bst_category'] + if 'bst_category' in sound_fields: + sound.bst_category = sound_fields['bst_category'] try: sound.filesize = os.path.getsize(sound.original_path) except OSError: