def test_find_torrent_wrong_file_extension_failed(self): plugin = DownloaderPlugin() settings = {'path': self.downloader_dir} plugin.set_settings(settings) os.makedirs(self.downloader_dir) with open(os.path.join(self.downloader_dir, "1.txt"), "w") as f: f.write("Not A Torrent File") self.assertFalse(plugin.find_torrent("TORRENT_HASH"))
def test_find_torrent_wrong_file_format_failed(self): plugin = DownloaderPlugin() settings = {'path': self.downloader_dir} plugin.set_settings(settings) os.makedirs(self.downloader_dir) with open(os.path.join(self.downloader_dir, "1.torrent"), "w") as f: f.write("Fake Torrent File") self.assertFalse(plugin.find_torrent("TORRENT_HASH"))
def test_find_torrent(self): torrent_filename = 'Hell.On.Wheels.S05E02.720p.WEB.rus.LostFilm.TV.mp4.torrent' torrent_filepath = self.get_httpretty_filename(torrent_filename) torrent = Torrent.from_file(torrent_filepath) plugin = DownloaderPlugin() settings = {'path': self.downloader_dir} self.assertFalse(plugin.find_torrent(torrent.info_hash)) plugin.set_settings(settings) self.assertFalse(plugin.find_torrent(torrent.info_hash)) downloaded_filepath = os.path.join(self.downloader_dir, torrent_filename) if not os.path.exists(self.downloader_dir): os.makedirs(self.downloader_dir) shutil.copy(torrent_filepath, downloaded_filepath) find_torrent = plugin.find_torrent(torrent.info_hash) self.assertNotEqual(False, find_torrent) date_added = datetime.fromtimestamp(os.path.getctime(downloaded_filepath))\ .replace(tzinfo=reference.LocalTimezone()).astimezone(utc) expected = {'name': torrent_filename, 'date_added': date_added} self.assertEqual(expected, find_torrent)
def test_find_torrent_failed_os_error(self): torrent_filename = 'Hell.On.Wheels.S05E02.720p.WEB.rus.LostFilm.TV.mp4.torrent' torrent_filepath = self.get_httpretty_filename(torrent_filename) torrent = Torrent.from_file(torrent_filepath) plugin = DownloaderPlugin() settings = {'path': self.downloader_dir} plugin.set_settings(settings) downloaded_filepath = os.path.join(self.downloader_dir, torrent_filename) if not os.path.exists(self.downloader_dir): os.makedirs(self.downloader_dir) shutil.copy(torrent_filepath, downloaded_filepath) with patch('monitorrent.plugins.clients.downloader.os.path.getctime') as access: access.side_effect = OSError self.assertFalse(plugin.find_torrent(torrent.info_hash))
def test_find_torrent_unexist_hash_failed(self): plugin = DownloaderPlugin() settings = {'path': self.downloader_dir} plugin.set_settings(settings) self.assertFalse(plugin.find_torrent("TORRENT_HASH"))