def test_to_file(): t0 = Torrent({}) with pytest.raises(TorrentError): t0.to_file() t1 = Torrent.from_file(FPATH_TORRENT_SIMPLE) fpath = join(mkdtemp(), str(uuid4())) t1.to_file(fpath) t2 = Torrent.from_file(fpath) assert t1._struct == t2._struct
def test_to_file(torr_test_file): t0 = Torrent({}) with pytest.raises(TorrentError): t0.to_file() t1 = Torrent.from_file(torr_test_file) fpath = join(mkdtemp(), str(uuid4())) t1.to_file(fpath) t2 = Torrent.from_file(fpath) assert t1._struct == t2._struct
def test_setters_httpseed(): t = Torrent() t.name = 'mytorrent' t.httpseeds = None assert t.httpseeds == [] t.httpseeds = 'http://host.some/file' assert t.httpseeds == ['http://host.some/file'] seeds = ['seed1', 'seed2'] t.httpseeds = seeds assert t.httpseeds == seeds t.httpseeds = None assert t.httpseeds == [] assert 'httpseeds' not in t._struct
def test_setters(): t = Torrent() assert t.info_hash is None assert t.comment is None assert t.created_by is None assert t.creation_date is None assert t.total_size == 0 assert t.announce_urls == [] assert t.files == [] t.name = 'mytorrent' assert t.name == 'mytorrent' t.comment = 'mycomment' assert t.comment == 'mycomment' t.created_by = 'some/1.0' assert t.created_by == 'some/1.0' now = datetime.now() t.creation_date = now assert t.creation_date == now.replace(microsecond=0) t.announce_urls = 'some1' assert t.announce_urls == [['some1']] assert t._struct['announce'] == 'some1' assert 'announce-list' not in t._struct t.announce_urls = ['some3', 'some4'] assert t.announce_urls == [['some3'], ['some4']] assert t._struct['announce'] == 'some3' t.announce_urls = ['some5'] assert t.announce_urls == [['some5']] assert t._struct['announce'] == 'some5' assert 'announce-list' not in t._struct assert not t.private t.private = False assert not t.private t.private = True assert t.private t.private = False assert not t.private
def test_setters_webseed(): t = Torrent() t.name = 'mytorrent' t.webseeds = None assert t.webseeds == [] t.webseeds = 'http://host.some/file' assert t.webseeds == ['http://host.some/file'] assert (t.get_magnet() == 'magnet:?xt=urn:btih:0f967b3f021421750069f93d256e319f13c404b1' '&ws=http%3A%2F%2Fhost.some%2Ffile') seeds = ['seed1', 'seed2'] t.webseeds = seeds assert t.webseeds == seeds assert t.get_magnet( ) == 'magnet:?xt=urn:btih:0f967b3f021421750069f93d256e319f13c404b1&ws=seed1&ws=seed2' t.webseeds = None assert t.webseeds == [] assert 'url-list' not in t._struct