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()
    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)
Exemple #4
0
 def setUp(self):
     #self.policy = Communicator(SIS_URL, simple=True)
     self.selector = LocalFolderSelector(folder=TORRENT_FOLDER)