Exemple #1
0
 def setUp(self):
     JCLTestCase.setUp(self, tables=[Account, User])
     self.comp = FeederComponent("jcl.test.com",
                                 "password",
                                 "localhost",
                                 "5347",
                                 None,
                                 None)
     self.sender = MessageSender(self.comp)
     self.message_type = None
Exemple #2
0
class MessageSender_TestCase(JCLTestCase):
    def setUp(self):
        JCLTestCase.setUp(self, tables=[Account, User])
        self.comp = FeederComponent("jcl.test.com",
                                    "password",
                                    "localhost",
                                    "5347",
                                    None,
                                    None)
        self.sender = MessageSender(self.comp)
        self.message_type = None

    def test_send(self):
        self.comp.stream = MockStream()
        self.comp.stream_class = MockStream
        model.db_connect()
        account11 = Account(user=User(jid="*****@*****.**"),
                            name="account11",
                            jid="*****@*****.**")
        self.sender.send(account11, ("subject", "Body message"))
        self.assertEquals(len(self.comp.stream.sent), 1)
        message = self.comp.stream.sent[0]
        self.assertEquals(message.get_from(), account11.jid)
        self.assertEquals(message.get_to(), account11.user.jid)
        self.assertEquals(message.get_subject(), "subject")
        self.assertEquals(message.get_body(), "Body message")
        self.assertEquals(message.get_type(), self.message_type)
        model.db_disconnect()

    def test_send_closed_connection(self):
        self.comp.stream = None
        model.db_connect()
        account11 = Account(user=User(jid="*****@*****.**"),
                            name="account11",
                            jid="*****@*****.**")
        self.sender.send(account11, ("subject", "Body message"))
Exemple #3
0
 def create_full_email_message(self, email_from, email_subject,
                               email_body, to_account):
     """
     Create a jabber message with email data and XEP-0033 addresses
     """
     message = MessageSender.create_message(self, to_account,
                                            (email_subject, email_body))
     if email_from is not None:
         msg_node = message.get_node()
         addresses_node = msg_node.newChild(None, "addresses", None)
         address_ns = addresses_node.newNs("http://jabber.org/protocol/address",
                                           None)
         addresses_node.setNs(address_ns)
         replyto_address_node = addresses_node.newChild(address_ns, "address",
                                                        None)
         replyto_address_node.setProp("type", "replyto")
         replyto_jid = email_from.replace('@', '%', 1) + "@" \
             + unicode(JID(to_account.jid).domain)
         replyto_address_node.setProp("jid", replyto_jid)
     return message