Esempio n. 1
0
    def test_ttl_value_updated(self):
        config = get_test_config()
        config["rssfeeds"]["0"]["update_interval"] = 30
        config["rssfeeds"]["0"]["obey_ttl"] = True
        config["rssfeeds"]["0"]["url"] = yarss2.common.get_resource(
            common.testdata_rssfeed_filename, path="tests")

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

        timer = RSSFeedTimer(yarss_config, log)
        timer.enable_timers()

        def add_torrents_pass(*arg):
            pass

        timer.add_torrent_func = add_torrents_pass

        # Run the rssfeed with key 0
        timer.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(timer.rssfeed_timers["0"]["update_interval"], 60)
        timer.disable_timers()
Esempio n. 2
0
    def test_rssfeed_update_handler(self):
        timer = RSSFeedTimer(self.config, log)
        timer.enable_timers()

        subscription = yarss2.yarss_config.get_fresh_subscription_config(
            rssfeed_key="0", key="0")
        self.config.set_config({"subscriptions": {"0": subscription}})

        # Check that last_update changes
        old_last_update = self.rssfeeds["0"]["last_update"]

        # Run the rssfeed with key 0
        timer.rssfeed_update_handler("0")
        self.assertNotEquals(old_last_update,
                             self.rssfeeds["0"]["last_update"])

        old_last_update = self.rssfeeds["0"]["last_update"]

        # Run the subscription with key 0 like when the user runs it manually
        timer.rssfeed_update_handler(None, "0")

        # last_update should not have changed
        self.assertEquals(old_last_update, self.rssfeeds["0"]["last_update"])

        # Must stop loopingcalls or test fails
        timer.disable_timers()
Esempio n. 3
0
    def test_interval_unchanged(self):
        timer = RSSFeedTimer(self.config, log)
        timer.enable_timers()
        # Set timer 0 with same interval
        self.assertFalse(timer.set_timer("0", 1))

        # Must stop loopingcalls or test fails
        timer.disable_timers()
Esempio n. 4
0
    def test_disable_timers(self):
        timer = RSSFeedTimer(self.config, log)
        timer.enable_timers()
        timer.disable_timers()

        # Now verify that the timers have been stopped
        for key in timer.rssfeed_timers.keys():
            # Is the timer running?
            self.assertFalse(timer.rssfeed_timers[key]["timer"].running)
Esempio n. 5
0
 def enable(self, config=None):
     self.log = yarss2.logger.Logger()
     self.torrent_handler = TorrentHandler(self.log)
     if config is None:
         self.yarss_config = YARSSConfig(self.log)
     else:
         self.yarss_config = config
     self.rssfeed_timer = RSSFeedTimer(self.yarss_config, self.log)
     self.rssfeed_timer.enable_timers()
     self.log.info("Enabled YaRSS2 %s" % yarss2.common.get_version())
Esempio n. 6
0
    def test_delete_timer(self):
        timer = RSSFeedTimer(self.config, log)
        timer.enable_timers()
        # Delete timer
        self.assertTrue(timer.delete_timer("0"))
        self.assertFalse(timer.delete_timer("-1"))

        self.assertEquals(len(timer.rssfeed_timers.keys()), 4)
        self.assertFalse(timer.rssfeed_timers.has_key("0"))
        # Must stop loopingcalls or test fails
        timer.disable_timers()
Esempio n. 7
0
    def test_reschedule_timer(self):
        timer = RSSFeedTimer(self.config, log)
        timer.enable_timers()

        # Change interval to 60 minutes
        self.assertTrue(timer.set_timer("0", 60))

        interval = timer.rssfeed_timers["0"]["timer"].interval
        self.assertEquals(60 * 60, interval)
        self.assertEquals(timer.rssfeed_timers["0"]["update_interval"], 60)

        # Must stop loopingcalls or test fails
        timer.disable_timers()
Esempio n. 8
0
    def test_schedule_timer(self):
        timer = RSSFeedTimer(self.config, log)
        timer.enable_timers()

        # Add new timer (with key "5") with interval 60 minutes
        self.assertTrue(timer.set_timer("5", 60))

        # Verify timer values
        interval = timer.rssfeed_timers["5"]["timer"].interval
        self.assertEquals(60 * 60, interval)
        self.assertEquals(timer.rssfeed_timers["5"]["update_interval"], 60)

        # Should now be 6 timers
        self.assertEquals(len(timer.rssfeed_timers.keys()), 6)

        # Must stop loopingcalls or test fails
        timer.disable_timers()
Esempio n. 9
0
    def test_enable_timers(self):
        timer = RSSFeedTimer(self.config, log)
        timer.enable_timers()

        # Now verify the timers
        for key in timer.rssfeed_timers.keys():
            # Is the timer running?
            self.assertTrue(timer.rssfeed_timers[key]["timer"].running)

            # Does the timer have the correct interval?
            interval = timer.rssfeed_timers[key]["timer"].interval
            self.assertEquals(self.rssfeeds[key]["update_interval"] * 60,
                              interval)
            self.assertEquals(self.rssfeeds[key]["update_interval"],
                              timer.rssfeed_timers[key]["update_interval"])

        # Must stop loopingcalls or test fails
        timer.disable_timers()
Esempio n. 10
0
    def test_rssfeed_update_queue(self):
        """Doesn't actually test anything". Used to manually test which threads are running
        with print statements"""
        from yarss2.rssfeed_handling import RSSFeedRunQueue

        self.config.set_config(get_test_config())
        timer = RSSFeedTimer(self.config, log)

        def add_torrents_pass(*arg):
            pass

        timer.add_torrent_func = add_torrents_pass

        #import threading
        #print "TESST thread id:", threading.current_thread()

        timer.queue_rss_feed_update(rssfeed_key="0")
        timer.queue_rss_feed_update(subscription_key="1")
        timer.queue_rss_feed_update(rssfeed_key="1")
        return timer.queue_rss_feed_update(rssfeed_key="2")