class TestLocalFolder(unittest.TestCase):


    def setUp(self):
        #self.policy = Communicator(SIS_URL, simple=True)
        self.selector = LocalFolderSelector(folder=TORRENT_FOLDER)
    
    def tearDown(self):
        pass

    def testReadingTorrents(self):
        '''test reading torrent defs from torrent directory'''
        files = get_torrents(TORRENT_FOLDER)
        assert len(files)==7, files
        
    
    def testLocalFolder(self):
        #build request
        #rated = self._tryRanking(iplist = ['209.34.91.45', '81.19.23.42'])
        #self.assertTrue(rated['81.19.23.42']>rated['209.34.91.45'])
        
        # dummy test
        self.selector.report_activity("foo", "bar", None)
        
        # test limited number
        torrents = self.selector.retrieve_torrent_stats(5)
        assert len(torrents) == 5, "torrents are %s" % torrents
        
        # test all
        torrents = self.selector.retrieve_torrent_stats(1000)
        assert len(torrents) == 7
        ids = []
#        print "torrents are: ", torrents
        for (id, url, rate) in torrents:
            tdef = TorrentDef.load(url)
            assert get_id(tdef) == id
            #print "%s with rating %s" % (tdef.get_name(), rate)
            assert rate == 100
            ids.append(id)
            
        # test local peers
        peers = self.selector.retrieve_local_peers_for_active_torrents(ids, 100, True)
        assert len(peers) == 0
        
        # dummy test for config parameters
        params = self.selector.retrieve_configuration_parameters("localhost")
        assert len(params) == 0
    
    def testRetrieveLocalPeersForActiveTorrents(self):
        # without torrents
        torrent_dict = self.selector.retrieve_local_peers_for_active_torrents(list_of_torrent_ids=[],
                                                                   maximum_number_of_peers=10,
                                                                   include_seeds=False)
        assert len(torrent_dict) == 0
 def testNoSisSelectorCreation(self):
     return
     #default should be local folder
     selector = LocalFolderSelector()
     ts = TorrentSelection.start_torrent_selection(DummyCache(), selector,
                                                   10)
     try:
         mech = ts.selector
         self.assertEquals((LocalFolderSelector), type(mech))
     except:
         sys.exit(-1)
     finally:
         ts.stop()
Example #3
0
class TestLocalFolder(unittest.TestCase):
    def setUp(self):
        #self.policy = Communicator(SIS_URL, simple=True)
        self.selector = LocalFolderSelector(folder=TORRENT_FOLDER)

    def tearDown(self):
        pass

    def testReadingTorrents(self):
        '''test reading torrent defs from torrent directory'''
        files = get_torrents(TORRENT_FOLDER)
        assert len(files) == 7, files

    def testLocalFolder(self):
        #build request
        #rated = self._tryRanking(iplist = ['209.34.91.45', '81.19.23.42'])
        #self.assertTrue(rated['81.19.23.42']>rated['209.34.91.45'])

        # dummy test
        self.selector.report_activity("foo", "bar", None)

        # test limited number
        torrents = self.selector.retrieve_torrent_stats(5)
        assert len(torrents) == 5, "torrents are %s" % torrents

        # test all
        torrents = self.selector.retrieve_torrent_stats(1000)
        assert len(torrents) == 7
        ids = []
        #        print "torrents are: ", torrents
        for (id, url, rate) in torrents:
            tdef = TorrentDef.load(url)
            assert get_id(tdef) == id
            #print "%s with rating %s" % (tdef.get_name(), rate)
            assert rate == 100
            ids.append(id)

        # test local peers
        peers = self.selector.retrieve_local_peers_for_active_torrents(
            ids, 100, True)
        assert len(peers) == 0

        # dummy test for config parameters
        params = self.selector.retrieve_configuration_parameters("localhost")
        assert len(params) == 0

    def testRetrieveLocalPeersForActiveTorrents(self):
        # without torrents
        torrent_dict = self.selector.retrieve_local_peers_for_active_torrents(
            list_of_torrent_ids=[],
            maximum_number_of_peers=10,
            include_seeds=False)
        assert len(torrent_dict) == 0
    def testNoSisSelectionMechanism(self):
        ''' Manual test without actually starting the thread.
        '''
        return
        #MAX_TORRENTS = 7
        #build request
        #rated = self._tryRanking(iplist = ['209.34.91.45', '81.19.23.42'])
        #self.assertTrue(rated['81.19.23.42']>rated['209.34.91.45'])

        #there should be 2 files inside!
        cache = DummyCache()
        mech = LocalFolderSelector(folder="SisClient/Cache/Test/resources")
        max_torrents = 5
        stay_in_torrents = 3
        selector = TorrentSelection.TorrentSelection(
            cache,
            mech,
            selection_interval=1,
            max_torrents=max_torrents,
            stay_in_torrents=stay_in_torrents)

        #PRE_CONDITION
        assert len(cache.running) == 0

        # fill up to the max
        joined = selector.get_torrents()
        assert joined == max_torrents, joined
        assert len(cache.running) == max_torrents
        #print "Now running:", cache.running

        # now replace some of them
        joined = selector.get_torrents()
        assert joined == max_torrents - stay_in_torrents
        assert len(cache.running) == max_torrents

        # now check if there is too much space
        for id in cache.running.keys()[0:-2]:
            cache.leave_swarm(id)
        assert len(cache.running) == 2
        joined = selector.get_torrents()
        assert joined == max_torrents - 2
        assert len(cache.running) == max_torrents
    def testNoSisLocalFolderSelection(self):
        ''' Start and finish thread!
        '''

        cache = DummyCache()
        assert len(cache.running) == 0

        #default should be local folder
        ts = TorrentSelection.start_torrent_selection(cache,
                                                      LocalFolderSelector(), 2)
        try:
            mech = ts.selector
            isinstance(mech, LocalFolderSelector)
            # now let it run for some iterations
            #cache.running.clear()

            # test threading
            #selector.start()
            time.sleep(5)  # should be enough to find all torrents
        finally:
            ts.stop()
        # expect selector to find all 7 available torrents
        assert len(cache.running) > 0, len(cache.running)
 def setUp(self):
     #self.policy = Communicator(SIS_URL, simple=True)
     self.selector = LocalFolderSelector(folder=TORRENT_FOLDER)
Example #7
0
 def setUp(self):
     #self.policy = Communicator(SIS_URL, simple=True)
     self.selector = LocalFolderSelector(folder=TORRENT_FOLDER)