1 from unittest import mock
2 from django.test import TestCase
3 from archive.models import Audiobook
7 @mock.patch("youtube.models.youtube_call")
8 @mock.patch("youtube.utils.subprocess")
9 @mock.patch("youtube.models.concat_audio")
10 @mock.patch("youtube.models.unlink")
11 @mock.patch("youtube.models.YouTube.prepare_thumbnail")
12 class YouTubeTests(TestCase):
13 fixtures = ["tests.yaml"]
15 def test_youtube_volumes(
16 self, prepare_thumbnail, unlink, concat_audio, subprocess, youtube_call
18 youtube_call.return_value = mock.Mock(
19 json=mock.Mock(return_value={"id": "deadbeef"})
21 audiobooks = Audiobook.objects.all().order_by("index")
23 self.assertEqual(audiobooks[0].youtube_volume_count, 3)
24 self.assertEqual([a.youtube_volume_index for a in audiobooks], [1, 2, 2, 3])
26 [a.is_youtube_publishable for a in audiobooks], [True, True, False, True]
29 tasks.YouTubeTask().run(None, 2, True)
31 # In creating a volume of two audiobooks, we should've called concat with a list of two files.
32 self.assertEqual(len(concat_audio.call_args[0][0]), 2)