Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_downloadqueue_init():
mydownloadqueue = DownloadQueue()
assert isinstance(mydownloadqueue, DownloadQueue)
def test_datafile_download_bad_url(display):
display.change_status = mock.MagicMock(name="change_status")
mydownloadqueue = DownloadQueue()
url = "https://bad"
DataFile.download_to_file(
url,
"datafile_download_temp",
"datafile download name",
mydownloadqueue,
display=display
)
while mydownloadqueue.length > 0:
pass
assert display.change_status.call_count > 0
assert not os.path.exists("datafile_download_temp")
def test_downloadqueue_start():
mydownloadqueue = DownloadQueue()
mydownloadqueue._display = mock.MagicMock()
mydownloadqueue.add(episode1)
episode1.download = mock.MagicMock(name="download")
mydownloadqueue.start()
episode1.download.assert_called_with(mydownloadqueue,
mydownloadqueue._display, )
def test_downloadqueue_update():
mydownloadqueue = DownloadQueue()
mydownloadqueue.add(episode1)
mydownloadqueue.start = mock.MagicMock(name="start")
mydownloadqueue.update()
assert mydownloadqueue.start.call_count == 1
def test_datafile_download(display):
display.change_status = mock.MagicMock(name="change_status")
mydownloadqueue = DownloadQueue()
url = "https://travis-ci.org/"
DataFile.download_to_file(
url,
"datafile_download_temp",
"datafile download name",
mydownloadqueue,
display=display
)
while mydownloadqueue.length > 0:
pass
assert display.change_status.call_count > 0
assert os.path.exists("datafile_download_temp")
os.remove("datafile_download_temp")
def test_episode_download():
DataFile.DEFAULT_DOWNLOADED_DIR = os.path.join(my_dir, "downloaded")
mydownloadqueue = DownloadQueue()
myfeed = Feed(file=my_dir + "/feeds/valid_basic.xml")
myepisode = myfeed.parse_episodes()[1]
DataFile.download_to_file = mock.MagicMock(name="download_to_file")
myepisode.download(mydownloadqueue)
assert DataFile.download_to_file.call_count == 1
DataFile.DEFAULT_DOWNLOADED_DIR = os.path.join(DataFile.DATA_DIR,
"downloaded")
def test_downloadqueue_first():
mydownloadqueue = DownloadQueue()
mydownloadqueue.add(episode1)
assert mydownloadqueue.first == episode1
def test_episode_download_with_display_no_enclosure(display):
DataFile.DEFAULT_DOWNLOADED_DIR = os.path.join(my_dir, "downloaded")
mydownloadqueue = DownloadQueue()
myfeed = Feed(file=my_dir + "/feeds/valid_basic.xml")
myepisode = myfeed.parse_episodes()[1]
DataFile.download_to_file = mock.MagicMock(name="download_to_file")
display.change_status = mock.MagicMock(name="change_status")
myepisode.download(mydownloadqueue, display=display)
assert display.change_status.call_count == 1
DataFile.DEFAULT_DOWNLOADED_DIR = os.path.join(DataFile.DATA_DIR,
"downloaded")
def test_episode_download_with_display(display):
DataFile.DEFAULT_DOWNLOADED_DIR = os.path.join(my_dir, "downloaded")
mydownloadqueue = DownloadQueue()
myfeed = Feed(file=my_dir + "/feeds/valid_basic.xml")
myepisode = myfeed.parse_episodes()[1]
DataFile.download_to_file = mock.MagicMock(name="download_to_file")
display.change_status = mock.MagicMock(name="change_status")
myepisode.download(mydownloadqueue, display=display)
assert DataFile.download_to_file.call_count == 1
DataFile.DEFAULT_DOWNLOADED_DIR = os.path.join(DataFile.DATA_DIR,
"downloaded")