コード例 #1
0
    def test_send_torrent_email_multipart_with_deferred(self):
        subscription = {"name": "Subscription name"}
        torrent_names = ["Torrent 1", "Torrent 2"]
        self.email["message"] = "Hi\n\nThis is a test message. \n\n$torrentlist\n\nRegards"
        email_data = {}

        def callback(args):
            message = smtp.get_emails().pop()
            self.verify_email_multipart(message, self.email, self.email_config, email_data)
            # Verify that the torrent names have been inserted into the message
            self.assertTrue(email_data["message"].find(torrent_names[0]) != -1)
            self.assertTrue(email_data["message"].find(torrent_names[1]) != -1)
            self.assertTrue(email_data["message_html"].find(torrent_names[0]) != -1)
            self.assertTrue(email_data["message_html"].find(torrent_names[1]) != -1)

        # Send email without deferred
        has_sent = send_torrent_email(self.email_config, self.email,
                                      torrent_name_list=torrent_names,
                                      subscription_data=subscription,
                                      deferred=False, callback_func=callback,
                                      email_data=email_data)
        self.assertTrue(has_sent)
        # Send email in
        d = send_torrent_email(self.email_config, self.email, torrent_name_list=torrent_names,
                               deferred=True, callback_func=callback, email_data=email_data)
        return d
コード例 #2
0
    def test_send_torrent_email_multipart_with_deferred(self):
        subscription = {"name": "Subscription name"}
        torrent_names = ["Torrent 1", "Torrent 2"]
        self.email["message"] = "Hi\n\nThis is a test message. \n\n$torrentlist\n\nRegards"
        email_data = {}

        def callback(args):
            message = test_yarss_email.smtp.get_emails().pop()
            self.verify_email_multipart(message, self.email, self.email_config, email_data)
            # Verify that the torrent names have been inserted into the message
            self.assertTrue(email_data["message"].find(torrent_names[0]) != -1)
            self.assertTrue(email_data["message"].find(torrent_names[1]) != -1)
            self.assertTrue(email_data["message_html"].find(torrent_names[0]) != -1)
            self.assertTrue(email_data["message_html"].find(torrent_names[1]) != -1)

        # Send email without deferred
        has_sent = send_torrent_email(self.email_config, self.email,
                                      torrent_name_list=torrent_names,
                                      subscription_data=subscription,
                                      defered=False, callback_func=callback,
                                      email_data=email_data)
        self.assertTrue(has_sent)
        # Send email in
        d = send_torrent_email(self.email_config, self.email, torrent_name_list=torrent_names,
                               defered=True, callback_func=callback, email_data=email_data)
        return d
コード例 #3
0
 def on_button_send_email_clicked(self, menuitem):
     key = get_value_in_selected_row(self.email_messages_treeview, self.email_messages_store)
     # Send email
     torrents = ["Torrent title"]
     send_torrent_email(self.email_config,
                        self.email_messages[key],
                        subscription_data={"name": "Test subscription"},
                        torrent_name_list=torrents,
                        defered=True, callback_func=self.test_email_callback)
コード例 #4
0
    def add_torrents(self, save_subscription_func, torrent_list, config):
        torrent_names = {}
        for torrent_match in torrent_list:
            torrent_download = self.add_torrent(torrent_match)

            if not torrent_download.success:
                self.log.warning(
                    "Failed to add torrent '%s' from url '%s'" %
                    (torrent_match["title"], torrent_match["link"]))
            else:
                self.log.info("Succesfully added torrent '%s'." %
                              torrent_match["title"])
                # Update subscription with date
                torrent_time = torrent_match["updated_datetime"]

                last_subscription_update = common.isodate_to_datetime(
                    torrent_match["subscription_data"]["last_match"])

                last_subscription_update = common.datetime_ensure_timezone(
                    last_subscription_update)
                # Update subscription time if this is newer
                # The order of the torrents are in ordered from newest to oldest
                if torrent_time and last_subscription_update <= torrent_time:
                    torrent_match["subscription_data"][
                        "last_match"] = torrent_time.isoformat()
                    # Save subsription with updated timestamp
                    save_subscription_func(
                        subscription_data=torrent_match["subscription_data"])

                # Handle email notification
                # key is the dictionary key used in the email_messages config.
                for key in torrent_match["subscription_data"][
                        "email_notifications"].keys():
                    # Must be enabled in the subscription
                    if not torrent_match["subscription_data"][
                            "email_notifications"][key]["on_torrent_added"]:
                        continue
                    if key not in torrent_names:
                        torrent_names[key] = (
                            torrent_match["subscription_data"], [])
                    # Add the torrent file to the list of files for this notification.
                    torrent_names[key][1].append(torrent_match["title"])
        if config["email_configurations"][
                "send_email_on_torrent_events"] is False:
            return

        for email_key in torrent_names.keys():
            # Check that the message is active
            if not config["email_messages"][email_key]["active"]:
                continue
            # Send email in
            send_torrent_email(config["email_configurations"],
                               config["email_messages"][email_key],
                               subscription_data=torrent_names[key][0],
                               torrent_name_list=torrent_names[key][1],
                               deferred=True)
コード例 #5
0
 def test_send_torrent_email_with_deferred(self):
     def callback(args):
         self.verify_email(test_yarss_email.smtp.get_emails().pop(), self.email, self.email_config)
     # Send email in
     d = send_torrent_email(self.email_config, self.email, defered=True)
     d.addCallback(callback)
     return d
コード例 #6
0
 def test_send_torrent_email_with_deferred_with_callback(self):
     """This test uses the callback keyword argument to add the callback
     function to the deferred"""
     def callback(args):
         self.verify_email(smtp.get_emails().pop(), self.email, self.email_config)
     d = send_torrent_email(self.email_config, self.email, deferred=True,
                            callback_func=callback)
     return d
コード例 #7
0
    def test_send_torrent_email_with_deferred(self):
        def callback(args):
            self.verify_email(test_yarss_email.smtp.get_emails().pop(),
                              self.email, self.email_config)

        # Send email in
        d = send_torrent_email(self.email_config, self.email, deferred=True)
        d.addCallback(callback)
        return d
コード例 #8
0
 def test_send_torrent_email_with_deferred_with_callback(self):
     """This test uses the callback keyword argument to add the callback
     function to the deferred"""
     def callback(args):
         self.verify_email(test_yarss_email.smtp.get_emails().pop(), self.email, self.email_config)
     # Send email in
     d = send_torrent_email(self.email_config, self.email, defered=True,
                                         callback_func=callback)
     return d
コード例 #9
0
    def add_torrents(self, save_subscription_func, torrent_list, config):
        torrent_names = {}
        for torrent_match in torrent_list:
            torrent_download = self.add_torrent(torrent_match)
            if not torrent_download.success:
                self.log.warn("Failed to add torrent '%s' from url '%s'" % (torrent_match["title"], torrent_match["link"]))
            else:
                self.log.info("Succesfully added torrent '%s'." % torrent_match["title"])
                # Update subscription with date
                torrent_time = torrent_match["updated_datetime"]
                last_subscription_update = common.isodate_to_datetime(torrent_match["subscription_data"]["last_match"])
                # Update subscription time if this is newer
                # The order of the torrents are in ordered from newest to oldest
                if torrent_time and last_subscription_update < torrent_time:
                    torrent_match["subscription_data"]["last_match"] = torrent_time.isoformat()
                    # Save subsription with updated timestamp
                    save_subscription_func(subscription_data=torrent_match["subscription_data"])

                # Handle email notification
                # key is the dictionary key used in the email_messages config.
                for key in torrent_match["subscription_data"]["email_notifications"].keys():
                    # Must be enabled in the subscription
                    if not torrent_match["subscription_data"]["email_notifications"][key]["on_torrent_added"]:
                        continue
                    if not torrent_names.has_key(key):
                        torrent_names[key] = (torrent_match["subscription_data"], [])
                    # Add the torrent file to the list of files for this notification.
                    torrent_names[key][1].append(torrent_match["title"])
        if config["email_configurations"]["send_email_on_torrent_events"] is False:
            return

        for email_key in torrent_names.keys():
            # Check that the message is active
            if not config["email_messages"][email_key]["active"]:
                continue
            # Send email in
            send_torrent_email(config["email_configurations"],
                                    config["email_messages"][email_key],
                                    subscription_data = torrent_names[key][0],
                                    torrent_name_list = torrent_names[key][1],
                                    defered=True)
コード例 #10
0
 def send_test_email(self, email_key):
     """
     Send a test email
     """
     self.email_config = self.yarss_config.get_config().get(
         'email_configurations', {})
     self.email_messages = self.yarss_config.get_config().get(
         'email_messages', {})
     torrents = ["Torrent title"]
     return send_torrent_email(
         self.email_config,
         self.email_messages[email_key],
         subscription_data={"name": "Test subscription"},
         torrent_name_list=torrents,
         deferred=True)