def test_download(srt): open_mock = mock_open() with patch("builtins.open", open_mock): srt.return_value = "" caption = Caption( { "url": "url1", "name": { "simpleText": "name1" }, "languageCode": "en" }, None) caption.download("title") assert open_mock.call_args_list[0][0][0].split( "/")[-1] == "title (en).srt"
def test_download_xml_and_trim_extension(xml): open_mock = mock_open() with patch("builtins.open", open_mock): xml.return_value = "" caption = Caption( { "url": "url1", "name": { "simpleText": "name1" }, "languageCode": "en" }, None) caption.download("title.xml", srt=False) assert open_mock.call_args_list[0][0][0].split( "/")[-1] == "title (en).xml"
def test_download_caption_with_language_found(youtube_item): youtube_item.title = "video title" caption = Caption( { "url": "url1", "name": { "simpleText": "name1" }, "languageCode": "en" }, None) caption.download = MagicMock(return_value="file_path") youtube_item.captions = CaptionQuery([caption]) cli.download_caption(youtube_item, "en") caption.download.assert_called_with(title="video title", output_path=None)
def test_download_with_output_path(srt): open_mock = mock_open() captions.target_directory = MagicMock(return_value="/target") with patch("builtins.open", open_mock): srt.return_value = "" caption = Caption( { "url": "url1", "name": { "simpleText": "name1" }, "languageCode": "en" }, None) file_path = caption.download("title", output_path="blah") assert file_path == "/target/title (en).srt" captions.target_directory.assert_called_with("blah")