41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
import pytest
|
|
import os
|
|
from src.core.torrent_session import TorrentSession
|
|
from src.data.database_manager import DatabaseManager
|
|
|
|
def test_add_and_persist_torrent(tmp_path):
|
|
# Setup temporary paths for portable mode testing
|
|
db_path = str(tmp_path / "test_citorrent.db")
|
|
save_path = str(tmp_path / "downloads")
|
|
os.makedirs(save_path, exist_ok=True)
|
|
|
|
core = TorrentSession(save_path=save_path)
|
|
db = DatabaseManager(db_path)
|
|
|
|
# Use a real magnet link (or a dummy one if libtorrent allows)
|
|
magnet_link = "magnet:?xt=urn:btih:deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
|
|
|
|
try:
|
|
handle = core.add_magnet(magnet_link)
|
|
status = core.get_status(handle)
|
|
info_hash = handle.info_hash().to_string()
|
|
|
|
# Persist to DB
|
|
db.add_torrent({
|
|
"info_hash": info_hash,
|
|
"name": status["name"],
|
|
"save_path": save_path,
|
|
"status": "Downloading",
|
|
"progress": status["progress"],
|
|
"source": magnet_link
|
|
})
|
|
|
|
# Verify it's in DB
|
|
saved = db.get_torrent(info_hash)
|
|
assert saved is not None
|
|
assert saved["name"] == status["name"]
|
|
assert saved["source"] == magnet_link
|
|
|
|
except Exception as e:
|
|
pytest.fail(f"Integration flow failed: {e}")
|