Example #1
0
    def test_initiate_rssfeed_update(self):
        config = common.get_test_config_dict()
        config["rssfeeds"]["0"]["update_interval"] = 30
        config["rssfeeds"]["0"]["obey_ttl"] = True
        config["rssfeeds"]["0"]["url"] = yarss2.util.common.get_resource(
            common.testdata_rssfeed_filename, path="tests")

        self.config.set_config(config)
        self.core.yarss_config = self.config

        self.add_torrents_called = False

        def add_torrents_pass(*arg):
            self.add_torrents_called = True

        self.core.rssfeed_scheduler.add_torrents_func = add_torrents_pass
        d = self.core.initiate_rssfeed_update(None, subscription_key="0")

        def callback_check(args):
            # Verify that add_torrents_pass was called
            self.assertTrue(self.add_torrents_called,
                            "add_torrents has not been called")

        d.addCallback(callback_check)
        return d
    def test_rssfeed_update_queue(self):
        """Tests that the add_torrent_func is called the correct number of times,
        and that add_torrent_func is running in the main thread.
        """
        # Don't use the loopingcall, so disable just to avoid any trouble
        self.scheduler.disable_timers()
        self.config.set_config(common.get_test_config_dict())

        add_torrents_count = []
        main_thread = threading.current_thread()

        def add_torrents_cb(*arg):
            self.assertEquals(main_thread, threading.current_thread(), "add_torrents must be called from the main thread!")
            add_torrents_count.append(0)
        self.scheduler.add_torrent_func = add_torrents_cb

        d_first = self.scheduler.queue_rssfeed_update(rssfeed_key="0")
        self.scheduler.queue_rssfeed_update(subscription_key="1")
        self.scheduler.queue_rssfeed_update(rssfeed_key="1")
        d_last = self.scheduler.queue_rssfeed_update(rssfeed_key="2")

        def verify_callback_count(args):
            self.assertEquals(len(add_torrents_count), 3)

        d_last.addCallback(verify_callback_count)
        return d_last
    def test_ttl_value_updated(self):
        config = common.get_test_config_dict()
        config["rssfeeds"]["0"]["update_interval"] = 30
        config["rssfeeds"]["0"]["obey_ttl"] = True
        config["rssfeeds"]["0"]["url"] = yarss2.util.common.get_resource(common.testdata_rssfeed_filename, path="tests")

        yarss_config = common.get_test_config()
        yarss_config.set_config(config)

        self.scheduler.disable_timers()
        self.scheduler.yarss_config = yarss_config
        self.scheduler.enable_timers()

        def add_torrents_pass(*arg):
            pass
        self.scheduler.add_torrent_func = add_torrents_pass

        # Run the rssfeed with key 0
        self.scheduler.rssfeed_update_handler("0")

        # Verify that update_interval of rssfeed in config was updated
        self.assertEquals(yarss_config.get_config()["rssfeeds"]["0"]["update_interval"], 60)

        # Verify that update_interval of the timer was updated
        self.assertEquals(self.scheduler.rssfeed_timers["0"]["update_interval"], 60)
        self.scheduler.disable_timers()
Example #4
0
    def test_add_torrent_default_user_agent(self):
        torrent_name = "FreeBSD-9.0-RELEASE-amd64-dvd1.torrent"
        torrent_url = yarss2.util.common.get_resource(torrent_name,
                                                      path="tests/data/")
        torrent_info = {"link": torrent_url, "rssfeed_key": "0"}
        config = common.get_test_config_dict()
        default_user_agent = get_user_agent()
        self.config.set_config(config)
        self.core.yarss_config = self.config

        download_dict = self.core.add_torrent(torrent_info)
        self.assertEquals(download_dict["headers"]["User-Agent"],
                          default_user_agent)
    def test_initiate_rssfeed_update(self):
        config = common.get_test_config_dict()
        config["rssfeeds"]["0"]["update_interval"] = 30
        config["rssfeeds"]["0"]["obey_ttl"] = True
        config["rssfeeds"]["0"]["url"] = yarss2.util.common.get_resource(common.testdata_rssfeed_filename, path="tests")

        self.config.set_config(config)
        self.core.yarss_config = self.config

        self.add_torrents_called = False

        def add_torrents_pass(*arg):
            self.add_torrents_called = True

        self.core.rssfeed_scheduler.add_torrent_func = add_torrents_pass
        d = self.core.initiate_rssfeed_update(None, subscription_key="0")

        def callback_check(args):
            # Verify that add_torrents_pass was called
            self.assertTrue(self.add_torrents_called, "add_torrents has not been called")

        d.addCallback(callback_check)
        return d
 def test_fetch_feed_torrents(self):
     config = common.get_test_config_dict()                                # 0 is the rssfeed key
     matche_result = self.rssfeedhandler.fetch_feed_torrents(config, "0")
     matches = matche_result["matching_torrents"]
     self.assertTrue(len(matches) == 3)