def setUp(self): yield super(TestCreditMiningPolicies, self).setUp() self.torrents = [CreditMiningTorrent(i, 'test torrent %d' % i) for i in range(10)] try: self.assertCountEqual # Python 3 except AttributeError: # Python 2 self.assertCountEqual = self.assertItemsEqual
def test_credit_mining_get_storage(self): infohash_bin = '0' * 40 name = u'torrent' tdef = MockObject() tdef.get_infohash = lambda: infohash_bin tdef.get_name = lambda: name tdef.get_length = lambda: 1000 state = MockObject() state.get_progress = lambda: 0.5 download = MockObject() download.get_def = lambda: tdef download.get_state = lambda: state torrent = CreditMiningTorrent(infohash_bin, name, download=download) total, downloaded = torrent.get_storage() self.assertEqual(total, 1000) self.assertEqual(downloaded, 500)
def test_torrent_insert_duplicate(self): self.credit_mining_manager.torrents[self.infohash] = CreditMiningTorrent(self.infohash, self.name) self.credit_mining_manager.on_torrent_insert(self.cid, self.infohash, self.name) torrent = self.credit_mining_manager.torrents.values()[0] self.credit_mining_manager.on_torrent_insert(self.cid, self.infohash, self.name) self.assertIn(torrent, self.credit_mining_manager.torrents.values()) self.assertFalse(self.session.get_download(self.infohash_bin)) # When we add a duplicate from another known source, the set of sources should update source = '1' * 40 self.credit_mining_manager.add_source(source) self.credit_mining_manager.on_torrent_insert(source, self.infohash, self.name) self.assertIn(source, torrent.sources) self.assertIn(torrent, self.credit_mining_manager.torrents.values()) self.assertFalse(self.session.get_download(self.infohash_bin))
def setUp(self, annotate=True): yield super(TestCreditMiningPolicies, self).setUp(annotate=annotate) self.torrents = [ CreditMiningTorrent(i, 'test torrent %d' % i) for i in range(10) ]
def setUp(self): yield super(TestInvestmentPolicy, self).setUp() self.torrents = [CreditMiningTorrent(i, 'test torrent %d' % i) for i in range(10)] self.policy = InvestmentPolicy()