def homepage(request): if request.method == "POST": form = MusicFileForm(request.POST, request.FILES) if form.is_valid(): newsong = UploadedMusic(musicfile=request.FILES['musicfile']) newsong.save() return HttpResponseRedirect(reverse('play.views.homepage')) else: form = MusicFileForm() return render(request, 'home.html', {'form': form})
def test_uploads_and_sounds_are_in_table(self): song_one = Track() song_one.text = "The first song" song_one.path = 28436940 song_one.save() song_two = UploadedMusic() file_path = "/play/dummy.wav" song_two.musicfile = file_path song_two.save() song_three = Track() song_three.text = "Second song" song_three.path = 409284092 song_three.save() saved_songs = Song.objects.all() self.assertEqual(saved_songs.count(), 3) self.assertNotEqual(saved_songs[0].song_id, saved_songs[1].song_id)