def test_create_torrent(self): torrent_content = TORRENT_PATH self.obj = Torrent(source_type="TORRENT", source=torrent_content, name="test movie") self.obj.bind_session(self.session) self.assertIsInstance(self.obj, Torrent) self.assertIsInstance(self.obj.get_torrent_info(), lt.torrent_info)
def _create_torrent_handler(self, source_type, source, source_path, label, session): id = self._get_torrent_uniqueness(source_path if source_type == "TORRENT" else source) t_obj = Torrent(source_type, source, label) # TODO: make it asynchronous t_obj.set_source(source, session) self.torrents[id] = t_obj return t_obj
def test_create_magnet_torrent(self): self.obj = Torrent(source_type="MAGNET", source=MAGNET, name="test movie") self.obj.bind_session(self.session) self.assertIsInstance(self.obj, Torrent) # we need to wait to download metadata self.assertRaises(TorrentHasNotMetadataYet, self.obj.get_torrent_info) count = 0 while not self.obj.has_torrent_info(): time.sleep(0.2) count += 1 if count > 300: raise Exception("counter exceeded") self.assertIsInstance(self.obj.get_torrent_info(), lt.torrent_info)
# -*- coding:utf-8 -*- from torrent.torrent import Torrent t = Torrent("demo", ["http://121.14.98.151:9090/announce"]) t.create()