Skip to content

Commit

Permalink
Make tests pass after adding bst category
Browse files Browse the repository at this point in the history
  • Loading branch information
allholy committed Dec 19, 2024
1 parent fa750b4 commit e348540
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions accounts/tests/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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))

Expand Down
1 change: 1 addition & 0 deletions sounds/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}),
Expand Down
2 changes: 2 additions & 0 deletions sounds/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions sounds/tests/test_sound.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
Expand All @@ -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())
Expand Down
3 changes: 2 additions & 1 deletion utils/sound_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit e348540

Please sign in to comment.