def test_chat(self): self.mox.StubOutWithMock(xmpp_request_handler.XmppRequestHandler, '_send') request = webapp2.Request.blank('/xmpp', POST={'message_type': 'chat', 'to': '*****@*****.**', 'from': '*****@*****.**', 'chat': 'Chat content'}) response = webapp2.Response() handler = xmpp_request_handler.XmppRequestHandler(request, response) data = xmpp_request_handler._FormData() data.add_text('from', '*****@*****.**', 'plain') data.add_text('to', '*****@*****.**', 'plain') data.add_text('body', 'Chat content', 'plain') data.add_text( 'stanza', CompareXml( '<ns0:message from="*****@*****.**" to="*****@*****.**" ' 'type="chat" xmlns:ns0="jabber:client">' '<ns0:body>Chat content</ns0:body>' '</ns0:message>'), 'xml') handler._send('/_ah/xmpp/message/chat/', data).AndReturn( dispatcher.ResponseTuple('404 Not Found', [], 'Response')) self.mox.ReplayAll() handler.post() self.mox.VerifyAll() self.assertEqual('404 Not Found', response.status)
def test_subscribe(self): self.mox.StubOutWithMock(xmpp_request_handler.XmppRequestHandler, '_send') request = webapp2.Request.blank('/xmpp', POST={'message_type': 'subscribe', 'to': '*****@*****.**', 'from': '*****@*****.**', 'subscription_type': 'subscribe'}) response = webapp2.Response() handler = xmpp_request_handler.XmppRequestHandler(request, response) data = xmpp_request_handler._FormData() data.add_text('from', '*****@*****.**', 'plain') data.add_text('to', '*****@*****.**', 'plain') data.add_text( 'stanza', CompareXml( '<ns0:presence from="*****@*****.**" to="*****@*****.**" ' 'type="subscribe" xmlns:ns0="jabber:client" />'), 'xml') handler._send('/_ah/xmpp/subscription/subscribe/', data).AndReturn( dispatcher.ResponseTuple('404 Not Found', [], 'Response')) self.mox.ReplayAll() handler.post() self.mox.VerifyAll() self.assertEqual('404 Not Found', response.status)
def test_chat(self): self.mox.StubOutWithMock(xmpp_request_handler.XmppRequestHandler, '_send') request = webapp2.Request.blank('/xmpp', POST={'message_type': 'chat', 'to': '*****@*****.**', 'from': '*****@*****.**', 'chat': 'Chat content'}) response = webapp2.Response() handler = xmpp_request_handler.XmppRequestHandler(request, response) data = xmpp_request_handler._FormData() data.add_text('from', '*****@*****.**', 'plain') data.add_text('to', '*****@*****.**', 'plain') data.add_text('body', 'Chat content', 'plain') data.add_text( 'stanza', CompareXml( '<ns0:message from="*****@*****.**" to="*****@*****.**" ' 'type="chat" xmlns:ns0="jabber:client">' '<ns0:body>Chat content</ns0:body>' '</ns0:message>'), 'xml') handler._send('/_ah/xmpp/message/chat/', data).AndReturn( dispatcher.ResponseTuple('404 Not Found', [], 'Response')) self.mox.ReplayAll() handler.post() self.mox.VerifyAll() self.assertEqual('404 Not Found', response.status)
def test_subscribe(self): self.mox.StubOutWithMock(xmpp_request_handler.XmppRequestHandler, '_send') request = webapp2.Request.blank('/xmpp', POST={'message_type': 'subscribe', 'to': '*****@*****.**', 'from': '*****@*****.**', 'subscription_type': 'subscribe'}) response = webapp2.Response() handler = xmpp_request_handler.XmppRequestHandler(request, response) data = xmpp_request_handler._FormData() data.add_text('from', '*****@*****.**', 'plain') data.add_text('to', '*****@*****.**', 'plain') data.add_text( 'stanza', CompareXml( '<ns0:presence from="*****@*****.**" to="*****@*****.**" ' 'type="subscribe" xmlns:ns0="jabber:client" />'), 'xml') handler._send('/_ah/xmpp/subscription/subscribe/', data).AndReturn( dispatcher.ResponseTuple('404 Not Found', [], 'Response')) self.mox.ReplayAll() handler.post() self.mox.VerifyAll() self.assertEqual('404 Not Found', response.status)
def test(self): form_data = xmpp_request_handler._FormData() form_data.add_text('message', '\N{White Smiling Face}', 'plain') form_data.add_text('stanza', '<p>This is\na\ntest!</p>', 'xml') boundary, content = form_data.get_boundary_and_content() self.assertMultiLineEqual( '--{boundary}\r\n' 'Content-Type: text/plain; charset="UTF-8"\r\n' 'Content-Disposition: form-data; name="message"\r\n' '\r\n' '\xe2\x98\xba\r\n' '--{boundary}\r\n' 'Content-Type: text/xml; charset="UTF-8"\r\n' 'Content-Disposition: form-data; name="stanza"\r\n' '\r\n' '<p>This is\na\ntest!</p>\r\n' '--{boundary}--\r\n'.format(boundary=boundary), content)
def test_send(self): self.mox.StubOutWithMock(xmpp_request_handler.XmppRequestHandler, 'dispatcher') handler = xmpp_request_handler.XmppRequestHandler() handler.dispatcher = self.mox.CreateMock(dispatcher.Dispatcher) handler.dispatcher.add_request( method='POST', relative_url='url', headers=[('Content-Type', mox.Regex('multipart/form-data; boundary=".*?"'))], body=mox.IsA(str), source_ip='0.1.0.10') data = xmpp_request_handler._FormData() self.mox.ReplayAll() handler._send('url', data) self.mox.VerifyAll()
def test(self): form_data = xmpp_request_handler._FormData() form_data.add_text('message', u'\N{White Smiling Face}', 'plain') form_data.add_text('stanza', '<p>This is\na\ntest!</p>', 'xml') boundary, content = form_data.get_boundary_and_content() self.assertMultiLineEqual( '--{boundary}\r\n' 'Content-Type: text/plain; charset="UTF-8"\r\n' 'Content-Disposition: form-data; name="message"\r\n' '\r\n' '\xe2\x98\xba\r\n' '--{boundary}\r\n' 'Content-Type: text/xml; charset="UTF-8"\r\n' 'Content-Disposition: form-data; name="stanza"\r\n' '\r\n' '<p>This is\na\ntest!</p>\r\n' '--{boundary}--\r\n'.format(boundary=boundary), content )
def test_send(self): self.mox.StubOutWithMock(xmpp_request_handler.XmppRequestHandler, 'dispatcher') handler = xmpp_request_handler.XmppRequestHandler() handler.dispatcher = self.mox.CreateMock(dispatcher.Dispatcher) handler.dispatcher.add_request( method='POST', relative_url='url', headers=[('Content-Type', mox.Regex('multipart/form-data; boundary=".*?"'))], body=mox.IsA(str), source_ip='0.1.0.10', fake_login=True) data = xmpp_request_handler._FormData() self.mox.ReplayAll() handler._send('url', data) self.mox.VerifyAll()