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 find_torrent(self, torrent_hash): path = self.check_connection() if not path: return False files = os.listdir(path) for torrent_file in files: file_path = os.path.join(path, torrent_file) if torrent_file.endswith(".torrent") and os.path.isfile(file_path): try: try: torrent = Torrent.from_file(file_path) except: continue if torrent.info_hash == torrent_hash: date_added = datetime.fromtimestamp(os.path.getctime(file_path))\ .replace(tzinfo=reference.LocalTimezone()).astimezone(utc) return {"name": torrent_file, "date_added": date_added} except OSError: continue return False
def test_remove_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() self.assertFalse(plugin.remove_torrent(torrent.info_hash)) settings = {'path': self.downloader_dir} plugin.set_settings(settings) self.assertFalse(plugin.remove_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) self.assertFalse(plugin.remove_torrent("RANDOM_HASH")) self.assertTrue(plugin.remove_torrent(torrent.info_hash)) self.assertFalse(os.path.exists(downloaded_filepath))
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)