def test_add_torrent_ret_false(self):
     handler = TorrentHandler(self.log)
     torrent_url = "http://url.com/file.torrent"
     cookies_dict = {}
     global test_component
     test_component.download_success = False
     handler.download_torrent_file = test_component.download_torrent_file
     torrent_info = {"link": torrent_url, "site_cookies_dict": cookies_dict}
     torrent_download = handler.add_torrent(torrent_info)
     self.assertFalse(torrent_download.success)
     # Set by download_torrent_file
     self.assertEquals(torrent_download.torrent_url, torrent_url)
     self.assertEquals(torrent_download.cookies_dict, cookies_dict)
     test_component.download_success = True
 def test_add_torrent_ret_false(self):
     handler = TorrentHandler(self.log)
     torrent_url = "http://url.com/file.torrent"
     cookies = {}
     global test_component
     test_component.download_success = False
     handler.download_torrent_file = test_component.download_torrent_file
     torrent_info = {"link": torrent_url, "site_cookies_dict": cookies}
     torrent_download = handler.add_torrent(torrent_info)
     self.assertFalse(torrent_download.success)
     # Set by download_torrent_file
     self.assertEquals(torrent_download.torrent_url, torrent_url)
     self.assertEquals(torrent_download.cookies, cookies)
     test_component.download_success = True
 def test_get_torrent(self):
     handler = TorrentHandler(self.log)
     handler.download_torrent_file = test_component.download_torrent_file
     filename = yarss2.util.common.get_resource(
         "FreeBSD-9.0-RELEASE-amd64-dvd1.torrent", path="tests/data/")
     test_component.use_filedump = read_file(filename)
     torrent_info = {
         "link": "http://url.com/file.torrent",
         "site_cookies_dict": {
             "cookiekey": "cookievalue"
         },
         "user_agent": "test"
     }
     download = handler.get_torrent(torrent_info)
     self.assertEquals(download.headers, {'User-Agent': 'test'})
     self.assertEquals(download.cookies, {'cookiekey': 'cookievalue'})
     self.assertFalse(download.is_magnet)
    def test_add_torrents(self):
        handler = TorrentHandler(self.log)
        from yarss2.rssfeed_handling import RSSFeedHandler

        self.rssfeedhandler = RSSFeedHandler(self.log)

        # Override method download_torrent_file
        handler.download_torrent_file = test_component.download_torrent_file
        filename = yarss2.util.common.get_resource("FreeBSD-9.0-RELEASE-amd64-dvd1.torrent", path="tests/data/")
        test_component.use_filedump = read_file(filename)

        config = get_test_config_dict()  # 0 is the rssfeed key
        match_result = self.rssfeedhandler.fetch_feed_torrents(config, "0")
        matching_torrents = match_result["matching_torrents"]

        saved_subscriptions = []

        def save_subscription_func(subscription_data):
            saved_subscriptions.append(subscription_data)

        handler.add_torrents(save_subscription_func, matching_torrents, self.config.get_config())
        self.assertEquals(len(saved_subscriptions), 1)
        handler.use_filedump = None
    def test_add_torrents(self):
        handler = TorrentHandler(self.log)
        from yarss2.rssfeed_handling import RSSFeedHandler
        self.rssfeedhandler = RSSFeedHandler(self.log)

        # Override method download_torrent_file
        handler.download_torrent_file = test_component.download_torrent_file
        filename = yarss2.util.common.get_resource(
            "FreeBSD-9.0-RELEASE-amd64-dvd1.torrent", path="tests/data/")
        test_component.use_filedump = read_file(filename)

        config = get_test_config_dict()  # 0 is the rssfeed key
        match_result = self.rssfeedhandler.fetch_feed_torrents(config, "0")
        matching_torrents = match_result["matching_torrents"]
        saved_subscriptions = []

        def save_subscription_func(subscription_data):
            saved_subscriptions.append(subscription_data)

        handler.add_torrents(save_subscription_func, matching_torrents,
                             self.config.get_config())
        self.assertEquals(len(saved_subscriptions), 3)
        handler.use_filedump = None