Exemplo n.º 1
0
    def test_edit_audio(self):
        data, audiofile = self.create_audio_form_data("tone.mp3", "audio/mpeg")
        form = AudioForm(data, {"audio": audiofile}, user=self.user)
        self.assertTrue(form.is_valid())
        audio = form.save()

        data['description'] = "new desc"
        edit_form = AudioForm(data, instance=audio, user=self.user)
        self.assertTrue(form.is_valid())
        edit_form.save()
Exemplo n.º 2
0
    def test_edit_audio(self):
        data, audiofile = self.create_audio_form_data("tone.mp3", "audio/mpeg")
        form = AudioForm(data, {"audio": audiofile}, user=self.user)
        self.assertTrue(form.is_valid())
        audio = form.save()

        data['description'] = "new desc"
        edit_form = AudioForm(data, instance=audio, user=self.user)
        self.assertTrue(form.is_valid())
        edit_form.save()
Exemplo n.º 3
0
 def test_upload_audio_with_wrong_extension(self):
     data, _ = self.create_audio_form_data(u"tone.mp3", "audio/mpeg")
     audiofile = SimpleUploadedFile(u"tone.mpe",
                                    "file content",
                                    content_type="audio/mpeg")
     form = AudioForm(data, {"audio": audiofile}, user=self.user)
     self.assertFalse(form.is_valid())
Exemplo n.º 4
0
    def test_upload_audio_with_wrong_extension(self):
        data, _ = self.create_audio_form_data("tone.mp3", "audio/mpeg")
        audiofile = SimpleUploadedFile("tone.mpe", "file content",
                                       content_type="audio/mpeg")
        form = AudioForm(data, {"audio":audiofile}, user=self.user)

        self.assertFalse(form.is_valid())
        self.assertTrue("extension" in form.errors.as_ul())
Exemplo n.º 5
0
def audio_create_update(request, slug=None):
    instance = get_object_or_404(Audio, slug=slug) if slug else None
    if request.method == "POST":
        form = AudioForm(request.POST, request.FILES, user=request.user,
                         instance=instance)
        if form.is_valid():
            project = form.cleaned_data.get("project")
            project = get_object_or_404(Project, pk=project.pk)
            audio = form.save()
            project.audios.add(audio)
            return redirect("audio-detail", slug=audio.slug)
    else:
        form = AudioForm(user=request.user, instance=instance)

    return render(request, "audio/audio_form.html", {
        'form': form,
        'object': instance,
    })
Exemplo n.º 6
0
def audio_create_update(request, slug=None):
    instance = get_object_or_404(Audio, slug=slug) if slug else None
    if request.method == "POST":
        form = AudioForm(request.POST,
                         request.FILES,
                         user=request.user,
                         instance=instance)
        if form.is_valid():
            project = form.cleaned_data.get("project")
            project = get_object_or_404(Project, pk=project.pk)
            audio = form.save()
            project.audios.add(audio)
            return redirect("audio-detail", slug=audio.slug)
    else:
        form = AudioForm(user=request.user, instance=instance)

    return render(request, "audio/audio_form.html", {
        'form': form,
        'object': instance,
    })
Exemplo n.º 7
0
 def test_upload_ogg(self):
     data, audiofile = self.create_audio_form_data(u"tone.ogg",
                                                   "audio/mpeg")
     form = AudioForm(data, {"audio": audiofile}, user=self.user)
     self.assertTrue(form.is_valid())
     audio = form.save()
Exemplo n.º 8
0
 def test_upload_audio(self):
     data, audiofile = self.create_audio_form_data("tone.mp3", "audio/mpeg")
     form = AudioForm(data, {"audio":audiofile}, user=self.user)
     self.assertTrue(form.is_valid())
     audio = form.save()