5 from BaseLib.Core.CacheDB.sqlitecachedb import SQLiteCacheDB, str2bin, CURRENT_MAIN_DB_VERSION
6 from BaseLib.Core.CacheDB.SqliteCacheDBHandler import PreferenceDBHandler, MyPreferenceDBHandler
7 from BaseLib.Core.BuddyCast.TorrentCollecting import SimpleTorrentCollecting
8 from bak_tribler_sdb import *
10 CREATE_SQL_FILE = os.path.join('..',"schema_sdb_v"+str(CURRENT_MAIN_DB_VERSION)+".sql"))
11 assert os.path.isfile(CREATE_SQL_FILE)
14 init_bak_tribler_sdb()
17 SQLiteCacheDB.DEBUG = False
19 class TestTorrentCollecting(unittest.TestCase):
22 self.db = SQLiteCacheDB.getInstance()
23 self.db.initDB(TRIBLER_DB_PATH_BACKUP)
26 permid[3127] = 'MFIwEAYHKoZIzj0CAQYFK4EEABoDPgAEAcPezgQ13k1MSOaUrCPisWRhYuNT7Tm+q5rUgHFvAWd9b+BcSut6TCniEgHYHDnQ6TH/vxQBqtY8Loag'
27 permid[994] = 'MFIwEAYHKoZIzj0CAQYFK4EEABoDPgAEAJUNmwvDaigRaM4cj7cE2O7lessqnnFEQsan7df9AZS8xeNmVsP/XXVrEt4t7e2TNicYmjn34st/sx2P'
28 permid[19] = 'MFIwEAYHKoZIzj0CAQYFK4EEABoDPgAEAAJv2YLuIWa4QEdOEs4CPRxQZDwZphKd/xK/tgbcALG198nNdT10znJ2sZYl+OJIvj7YfYp75PrrnWNX'
29 permid[5] = 'MFIwEAYHKoZIzj0CAQYFK4EEABoDPgAEAAB0XbUrw5b8CrTrMZST1SPyrzjgSzIE6ynALtlZASGAb+figVXRRGpKW6MSal3KnEm1/q0P3JPWrhCE'
32 db = MyPreferenceDBHandler.getInstance()
38 def test_selecteTorrentToCollect(self):
39 db = PreferenceDBHandler.getInstance()
40 tc = SimpleTorrentCollecting(None,None)
41 truth = {3127:235, 994:20, 19:1, 5:0}
44 pl = db.getPrefList(str2bin(self.permid[pid]))
45 assert len(pl) == truth[pid], [pid, len(pl)]
46 # test random selection
47 infohash = tc.selecteTorrentToCollect(pl, True)
48 if pid == 994 or pid == 3127:
49 assert len(infohash) == 20, infohash
51 assert infohash is None, infohash
53 #tc.updateAllCooccurrence()
55 pl = db.getPrefList(str2bin(self.permid[pid]))
56 assert len(pl) == truth[pid], [pid, len(pl)]
57 # test selecting most relevant torrent
58 infohash = tc.selecteTorrentToCollect(pl, False)
60 tid = tc.torrent_db.getTorrentID(infohash)
63 permid = self.permid[pid]
64 infohash = tc.updatePreferences(permid, pl)
65 tid = tc.torrent_db.getTorrentID(infohash)
68 tid = tc.torrent_db.getTorrentID(infohash)
71 permid = self.permid[pid]
72 infohash = tc.updatePreferences(permid, pl)
73 tid = tc.torrent_db.getTorrentID(infohash)
76 assert infohash is None, infohash
80 suite = unittest.TestSuite()
81 suite.addTest(unittest.makeSuite(TestTorrentCollecting))
87 unittest.main(defaultTest='test_suite')
90 if __name__ == '__main__':