def test_add_torrent_with_subscription_data(self): handler = TorrentHandler(self.log) subscription_data = yarss2.yarss_config.get_fresh_subscription_config() subscription_data["move_completed"] = "move/path" subscription_data["download_location"] = "download/path" subscription_data[ "add_torrents_in_paused_state"] = GeneralSubsConf.DEFAULT download = TorrentDownload() torrent_info = { "link": "http://url.com/file.torrent", "site_cookies_dict": {}, "subscription_data": subscription_data, "torrent_download": download } d = handler.add_torrent(torrent_info) self.assertTrue(d.success) added = test_component.added.pop() self.assertTrue(added.options["move_completed"]) self.assertEquals(added.options["move_completed_path"], subscription_data["move_completed"]) self.assertEquals(added.options["download_location"], subscription_data["download_location"]) # When using DEFAULT, the default value for add_paused on TorrentSettings is False self.assertEquals(added.options["add_paused"], False)
def setUp(self): # NOQA self.handler = TorrentHandler(log) smtplib.SMTP = DummySMTP self.email_config = yarss2.yarss_config.get_fresh_email_config() self.email_config["from_address"] = "*****@*****.**" self.email = {} self.email["to_address"] = "*****@*****.**" self.email["subject"] = "Test Subject" self.email["message"] = "Hi\n\nThis is a test message.\n\n\nRegards" self.email["name"] = "Test Message Name" self.expected_messsage = [] self.expected_messsage.append('Content-Type: text/plain; charset="utf-8"') self.expected_messsage.append('MIME-Version: 1.0') self.expected_messsage.append('Content-Transfer-Encoding: base64') self.expected_messsage.append("Subject: %s") self.expected_messsage.append("From: %s") self.expected_messsage.append("To: %s") self.expected_messsage_multipart = [] self.expected_messsage_multipart.append('Content-Type: multipart/alternative;') self.expected_messsage_multipart.append('MIME-Version: 1.0') self.expected_messsage_multipart.append("Subject: %s") self.expected_messsage_multipart.append("From: %s") self.expected_messsage_multipart.append("To: %s") self.expected_messsage_multipart.append('Content-Type: text/plain; charset="utf-8"') self.expected_messsage_multipart.append('MIME-Version: 1.0') self.expected_messsage_multipart.append('Content-Transfer-Encoding: base64') self.expected_messsage_multipart.append('Content-Type: text/html; charset="utf-8"') self.expected_messsage_multipart.append('MIME-Version: 1.0') self.expected_messsage_multipart.append('Content-Transfer-Encoding: base64')
def __init__(self, config, logger): self.yarss_config = config self.rssfeed_timers = {} self.run_queue = RSSFeedRunQueue() self.log = logger self.rssfeedhandler = RSSFeedHandler(logger) self.torrent_handler = TorrentHandler(logger) self.add_torrent_func = self.torrent_handler.add_torrents # To make it possible to disable adding torrents in testing
def test_add_torrent_magnet_link(self): handler = TorrentHandler(self.log) torrent_url = "magnet:blbalba/url.magnet.link" torrent_info = {"link": torrent_url, "site_cookies_dict": {}} download = handler.add_torrent(torrent_info) self.assertTrue(download.success) self.assertTrue(download.is_magnet) self.assertEquals(test_component.added.pop().magnet, torrent_url)
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())
def test_add_torrent_raise_AddTorrentError(self): # noqa: N802 handler = TorrentHandler(self.log) filename = yarss2.util.common.get_resource( "FreeBSD-9.0-RELEASE-amd64-dvd1.torrent", path="tests/data/") torrent_info = {"link": filename, "site_cookies_dict": {}} with mock.patch.object(TestComponent, 'add') as test_component_add: test_component_add.side_effect = AddTorrentError( 'Torrent already in session (%s).' % 1) torrent_added = handler.add_torrent(torrent_info) self.assertFalse(torrent_added.success)
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_add_torrent(self): handler = TorrentHandler(self.log) filename = yarss2.util.common.get_resource( "FreeBSD-9.0-RELEASE-amd64-dvd1.torrent", path="tests/data/") torrent_info = {"link": filename, "site_cookies_dict": {}} torrent_download = handler.add_torrent(torrent_info) torrent_added = test_component.added.pop() self.assertTrue(torrent_added.success) self.assertFalse(torrent_added.filedump is None, "Filedump is not None") self.assertEquals(torrent_added.filename, os.path.split(filename)[1]) self.assertFalse(torrent_added.filedump is None) self.assertEquals(torrent_download.url, filename)
def setUp(self): # NOQA defer.setDebugging(True) self.config = common.get_test_config() # get_test_config will load a new core.conf with the default values. # Must save to save to file so that torrent.py.TorrentOptions loads the default values self.config.core_config.save() test_component = TestComponent() self.torrent_handler = TorrentHandler(LOG) self.torrent_handler.download_torrent_file = test_component.download_torrent_file # Might be necessary for changes in master branch # yarss2.core.component = test_component self.core = Core("test") self.core.enable(config=self.config) self.core.torrent_handler = self.torrent_handler
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), 3) handler.use_filedump = None
def createUI(self): self.glade = gtk.glade.XML(get_resource("yarss_main.glade")) self.glade.signal_autoconnect({ "on_button_add_subscription_clicked": self.on_button_add_subscription_clicked, "on_button_delete_subscription_clicked": self.on_button_delete_subscription_clicked, "on_button_edit_subscription_clicked": self.on_button_edit_subscription_clicked, "on_button_add_rssfeed_clicked": self.on_button_add_rssfeed_clicked, "on_button_delete_rssfeed_clicked": self.on_button_delete_rssfeed_clicked, "on_button_edit_rssfeed_clicked": self.on_button_edit_rssfeed_clicked, "on_button_add_cookie_clicked": self.on_button_add_cookie_clicked, "on_button_edit_cookie_clicked": self.on_button_edit_cookie_clicked, "on_button_delete_cookie_clicked": self.on_button_delete_cookie_clicked, "on_button_add_message_clicked": self.on_button_add_message_clicked, "on_button_edit_message_clicked": self.on_button_edit_message_clicked, "on_button_delete_message_clicked": self.on_button_delete_message_clicked, "on_checkbox_email_authentication_toggled": self.on_checkbox_email_authentication_toggled, "on_checkbutton_send_email_on_torrent_events_toggled": self.on_checkbutton_send_email_on_torrent_events_toggled }) component.get("Preferences").add_page( "YaRSS2", self.glade.get_widget("notebook_main")) component.get("PluginManager").register_hook("on_apply_prefs", self.on_apply_prefs) component.get("PluginManager").register_hook("on_show_prefs", self.on_show_prefs) self.gtkui_log = GTKUI_logger(self.glade.get_widget('textview_log')) self.log = Logger(gtkui_logger=self.gtkui_log) self.torrent_handler = TorrentHandler(self.log) self.subscriptions = {} self.rssfeeds = {} self.selected_path_subscriptions = None self.selected_path_rssfeeds = None self.selected_path_email_message = None self.selected_path_cookies = None # key, enabled, name, site, download_location self.subscriptions_store = gtk.ListStore(str, bool, str, str, str, str, str) # key, active, name, site, Update interval, Last update, subscripions, URL self.rssfeeds_store = gtk.ListStore(str, bool, str, str, str, str, str, str) # key, active, site, value self.cookies_store = gtk.ListStore(str, bool, str, str) # key, active, name, to-address, subject, message-content self.email_messages_store = gtk.ListStore(str, bool, str, str, str, str) self.create_subscription_pane() self.create_rssfeeds_pane() self.create_cookies_pane() self.create_email_messages_pane()
def test_get_torrent_magnet(self): handler = TorrentHandler(self.log) torrent_info = {"link": "magnet:hash"} download = handler.get_torrent(torrent_info) self.assertTrue(download.is_magnet)