def test_commands_can_yield_html(self): dummy = self.dummy m = self.example_message dummy._execute_and_send(cmd='yield_args_as_html', args=['foo', 'bar'], mess=m, jid='noterr@localhost', template_name=dummy.yield_args_as_html._err_command_template) response1 = dummy.pop_message() response2 = dummy.pop_message() self.assertEqual("foo", response1.getBody()) self.assertEqual('<strong xmlns:ns0="http://jabber.org/protocol/xhtml-im">foo</strong>\n\n', mess_2_embeddablehtml(response1)[0]) self.assertEqual("bar", response2.getBody()) self.assertEqual('<strong xmlns:ns0="http://jabber.org/protocol/xhtml-im">bar</strong>\n\n', mess_2_embeddablehtml(response2)[0])
def send_message(self, mess): if self.token and mess.type == 'groupchat': logging.debug('Message intercepted for Hipchat API') content, _ = mess_2_embeddablehtml(mess) room_jid = mess.to self.send_api_message(room_jid.node.split('_')[1], CHATROOM_FN, content) else: super(HipchatClient, self).send_message(mess)
def send_message(self, mess): if self.token and mess.getType() == 'groupchat': logging.debug('Message intercepted for Hipchat API') content, _ = mess_2_embeddablehtml(mess) room_jid = mess.getTo() self.send_api_message(room_jid.getNode().split('_')[1], CHATROOM_FN, content) else: super(HipchatClient, self).send_message(mess)
def test_commands_can_return_html(self): dummy = self.dummy m = self.example_message dummy._execute_and_send(cmd='return_args_as_html', args=['foo', 'bar'], match=None, mess=m, jid='noterr@localhost', template_name=dummy.return_args_as_html._err_command_template) response = dummy.pop_message() self.assertEqual("foobar", response.body) self.assertEqual('<strong xmlns:ns0="http://jabber.org/protocol/xhtml-im">foo</strong>' '<em xmlns:ns0="http://jabber.org/protocol/xhtml-im">bar</em>\n\n', mess_2_embeddablehtml(response)[0])
def test_commands_can_yield_html(self): dummy = self.dummy m = self.example_message dummy._execute_and_send( cmd='yield_args_as_html', args=['foo', 'bar'], mess=m, jid='noterr@localhost', template_name=dummy.yield_args_as_html._err_command_template) response1 = dummy.pop_message() response2 = dummy.pop_message() self.assertEqual("foo", response1.getBody()) self.assertEqual( '<strong xmlns:ns0="http://jabber.org/protocol/xhtml-im">foo</strong>\n\n', mess_2_embeddablehtml(response1)[0]) self.assertEqual("bar", response2.getBody()) self.assertEqual( '<strong xmlns:ns0="http://jabber.org/protocol/xhtml-im">bar</strong>\n\n', mess_2_embeddablehtml(response2)[0])
def test_commands_can_yield_html(self): dummy = self.dummy m = self.example_message dummy._execute_and_send( cmd="yield_args_as_html", args=["foo", "bar"], match=None, mess=m, jid="noterr@localhost", template_name=dummy.yield_args_as_html._err_command_template, ) response1 = dummy.pop_message() response2 = dummy.pop_message() self.assertEqual("foo", response1.body) self.assertEqual( '<strong xmlns:ns0="http://jabber.org/protocol/xhtml-im">foo</strong>\n\n', mess_2_embeddablehtml(response1)[0], ) self.assertEqual("bar", response2.body) self.assertEqual( '<strong xmlns:ns0="http://jabber.org/protocol/xhtml-im">bar</strong>\n\n', mess_2_embeddablehtml(response2)[0], )
def emit_mess_to_webroom(self, mess): if not self.server or not self.webchat_mode: return if hasattr(mess, "getBody") and mess.getBody() and not mess.getBody().isspace(): content, is_html = mess_2_embeddablehtml(mess) if not is_html: content = "<pre>" + content + "</pre>" else: content = "<div>" + content + "</div>" pkt = dict(type="event", name="msg_to_room", args=(mess.getFrom().getNode(), content), endpoint="") room_name = "_main_room" for sessid, socket in self.server.sockets.iteritems(): if "rooms" not in socket.session: continue if room_name in socket.session["rooms"]: socket.send_packet(pkt)
def test_commands_can_return_html(self): dummy = self.dummy m = self.example_message dummy._execute_and_send( cmd='return_args_as_html', args=['foo', 'bar'], match=None, mess=m, jid='noterr@localhost', template_name=dummy.return_args_as_html._err_command_template) response = dummy.pop_message() self.assertEqual("foobar", response.body) self.assertEqual( '<strong xmlns:ns0="http://jabber.org/protocol/xhtml-im">foo</strong>' '<em xmlns:ns0="http://jabber.org/protocol/xhtml-im">bar</em>\n\n', mess_2_embeddablehtml(response)[0])
def emit_mess_to_webroom(self, mess): if hasattr(mess, 'getBody') and mess.getBody() and not mess.getBody().isspace(): content, is_html = mess_2_embeddablehtml(mess) if not is_html: content = '<pre>' + content + '</pre>' else: content = '<div>' + content + '</div>' pkt = dict(type="event", name='msg_to_room', args=(mess.getFrom().getNode(), content), endpoint='') room_name = '_main_room' for sessid, socket in self.server.sockets.iteritems(): if 'rooms' not in socket.session: continue if room_name in socket.session['rooms']: socket.send_packet(pkt)
def emit_mess_to_webroom(self, mess): if not self.server or not self.webchat_mode: return if hasattr( mess, 'getBody') and mess.getBody() and not mess.getBody().isspace(): content, is_html = mess_2_embeddablehtml(mess) if not is_html: content = '<pre>' + content + '</pre>' else: content = '<div>' + content + '</div>' pkt = dict(type="event", name='msg_to_room', args=(mess.getFrom().getNode(), content), endpoint='') room_name = '_main_room' for sessid, socket in self.server.sockets.iteritems(): if 'rooms' not in socket.session: continue if room_name in socket.session['rooms']: socket.send_packet(pkt)
def send(self, mess): if hasattr(mess, 'body') and mess.body and not mess.body.isspace(): content, is_html = mess_2_embeddablehtml(mess) self.newAnswer.emit(content, is_html)
def send(self, mess): if hasattr(mess, 'getBody') and mess.getBody() and not mess.getBody().isspace(): content, is_html = mess_2_embeddablehtml(mess) self.newAnswer.emit(content, is_html)
def send(self, mess): if hasattr(mess, "body") and mess.body and not mess.body.isspace(): content, is_html = mess_2_embeddablehtml(mess) self.newAnswer.emit(content, is_html)