def test_load_remote_m3u8(self, m): mocked_path = 'http://example.com/playlist.m3u8' m.get(mocked_path, text=self.sample_m3u8) load_remote_m3u8(mocked_path, self.playlist, remove_existed=True) self.assertEqual(self.playlist.count, 2)
def form_valid(self, form): playlist, created = Playlist.objects.get_or_create( user=self.request.user) if form.cleaned_data['url']: load_remote_m3u8( form.cleaned_data['url'], playlist, remove_existed=form.cleaned_data['remove_existed']) elif form.cleaned_data['file']: load_m3u8_from_file( form.cleaned_data['file'], playlist, remove_existed=form.cleaned_data['remove_existed']) return super(CreatePlaylist, self).form_valid(form)
def form_valid(self, form): playlist = Playlist.objects.filter(user=self.request.user).first() if not playlist: playlist = Playlist.objects.create(user=self.request.user) form.instance.user = self.request.user if form.cleaned_data['url']: load_remote_m3u8( form.cleaned_data['url'], playlist, remove_existed=form.cleaned_data['remove_existed']) elif form.cleaned_data['file']: load_m3u8_from_file( form.cleaned_data['file'], playlist, remove_existed=form.cleaned_data['remove_existed']) return super(CreatePlaylist, self).form_valid(form)