def test_hash(self): environ = { 'xmpp.body': '#155', 'xmpp.jid': JID('*****@*****.**'), 'xmpp.stanza_type': 'chat' } rv = app(environ) self.check_resp(rv.next())
def test_version_user_ru(self): environ = { 'xmpp.body': u'версия that@guy', 'xmpp.jid': JID('*****@*****.**'), 'xmpp.stanza_type': 'chat' } with app.request_context(environ): rv = app(environ) self.assertEqual(list(rv), [u"а это еще кто?"])
def test_version_user(self): environ = { 'xmpp.body': 'version that@guy', 'xmpp.jid': JID('*****@*****.**'), 'xmpp.stanza_type': 'chat' } with app.request_context(environ): rv = app(environ) self.assertEqual(list(rv), [u"who's that?"])
def test_version_user_in_muc(self): environ = { 'xmpp.body': 'version tasman', 'xmpp.jid': JID('[email protected]/somebody'), 'xmpp.stanza_type': 'groupchat' } with app.request_context(environ): rv = app(environ) cmd, payload = rv.next() self.assertEqual(cmd, 'version') self.assertEqual(payload['jid'], '[email protected]/tasman')
def test_version_hidden(self): environ = { 'xmpp.body': u'version', 'xmpp.jid': JID('*****@*****.**'), 'xmpp.stanza_type': 'chat' } with app.request_context(environ): rv = app(environ) cmd, payload = rv.next() self.assertEqual(cmd, 'version') rv = rv.send(None) self.assertEquals(rv, u"seems he's hiding from NSA")
def test_version_hidden_ru(self): environ = { 'xmpp.body': u'версия', 'xmpp.jid': JID('*****@*****.**'), 'xmpp.stanza_type': 'chat' } with app.request_context(environ): rv = app(environ) cmd, payload = rv.next() self.assertEqual(cmd, 'version') rv = rv.send(None) self.assertEquals(rv, u"он зашифровался")
def test_version_ru(self): environ = { 'xmpp.body': u'версия', 'xmpp.jid': JID('*****@*****.**'), 'xmpp.stanza_type': 'chat' } info = {'os': 'Linux', 'name': 'xmppflask', 'version': '1.0'} with app.request_context(environ): rv = app(environ) cmd, payload = rv.next() self.assertEqual(cmd, 'version') rv = rv.send(info) self.assertEquals(rv, u'{name} {version} @ {os}'.format(**info))
def test_version_no_ver(self): environ = { 'xmpp.body': 'version', 'xmpp.jid': JID('*****@*****.**'), 'xmpp.stanza_type': 'chat' } info = {'os': 'Linux', 'name': '', 'version': ''} with app.request_context(environ): rv = app(environ) cmd, payload = rv.next() self.assertEqual(cmd, 'version') rv = rv.send(info) self.assertEquals(rv, u'[no name] [no ver] @ {os}'.format(**info))
def test_ticket_ru(self): environ = { 'xmpp.body': u'рев 1', 'xmpp.jid': JID('*****@*****.**'), 'xmpp.stanza_type': 'chat' } rv = app(environ) self.check_resp(rv.next()) environ = { 'xmpp.body': u'ревизия 1', 'xmpp.jid': JID('*****@*****.**'), 'xmpp.stanza_type': 'chat' } rv = app(environ) self.check_resp(rv.next()) environ = { 'xmpp.body': u'коммит 1', 'xmpp.jid': JID('*****@*****.**'), 'xmpp.stanza_type': 'chat' } rv = app(environ) self.check_resp(rv.next())
def test_revision_en(self): environ = { 'xmpp.body': 'rev 1', 'xmpp.jid': JID('*****@*****.**'), 'xmpp.stanza_type': 'chat' } rv = app(environ) self.check_resp(rv.next()) environ = { 'xmpp.body': 'revision 1', 'xmpp.jid': JID('*****@*****.**'), 'xmpp.stanza_type': 'chat' } rv = app(environ) self.check_resp(rv.next()) environ = { 'xmpp.body': 'commit 1', 'xmpp.jid': JID('*****@*****.**'), 'xmpp.stanza_type': 'chat' } rv = app(environ) self.check_resp(rv.next())
def test_ticket_en(self): environ = { 'xmpp.body': 'bug 155', 'xmpp.jid': JID('*****@*****.**'), 'xmpp.stanza_type': 'chat' } rv = app(environ) self.check_resp(rv.next()) environ = { 'xmpp.body': 'issue 155', 'xmpp.jid': JID('*****@*****.**'), 'xmpp.stanza_type': 'chat' } rv = app(environ) self.check_resp(rv.next()) environ = { 'xmpp.body': 'ticket 155', 'xmpp.jid': JID('*****@*****.**'), 'xmpp.stanza_type': 'chat' } rv = app(environ) self.check_resp(rv.next())
def test_ticket_ru(self): environ = { 'xmpp.body': u'баг 155', 'xmpp.jid': JID('*****@*****.**'), 'xmpp.stanza_type': 'chat' } rv = app(environ) self.check_resp(rv.next()) environ = { 'xmpp.body': u'проблема 155', 'xmpp.jid': JID('*****@*****.**'), 'xmpp.stanza_type': 'chat' } rv = app(environ) self.check_resp(rv.next()) environ = { 'xmpp.body': u'тикет 155', 'xmpp.jid': JID('*****@*****.**'), 'xmpp.stanza_type': 'chat' } rv = app(environ) self.check_resp(rv.next())
def tell(cmd, nick, message): if request.type == 'groupchat': to_jid = JID(request.jid) to_jid.resource = nick from_jid = request.username else: to_jid = nick from_jid = request.environ['xmpp.jid'] ts = datetime.datetime.utcfromtimestamp(request.environ['xmpp.timestamp']) MESSAGE_QUEUE[to_jid].put(('message', { 'to': to_jid, 'body': '[%sZ] %s: %s' % (ts, from_jid, message) })) return render_template('tell.html')
def test_tell_in_muc(self): environ = { 'xmpp.body': 'tell foo boo!', 'xmpp.stanza_type': 'groupchat', 'xmpp.jid': JID('[email protected]/tasman'), 'xmpp.timestamp': 1234567890 } rv = app(environ) self.assertEqual(list(rv), ["I'll pass that onto foo"]) self.assertEqual( MESSAGE_QUEUE['[email protected]/foo'].get(), ('message', { 'body': u'[2009-02-13 23:31:30Z] tasman: boo!', 'to': u'[email protected]/foo' }))
def tell(nick, message, **kwargs): """Sends to the specified user the message when he becomes available""" if request.type == 'groupchat': to_jid = JID(request.jid) to_jid.resource = nick from_jid = request.username else: to_jid = nick from_jid = request.environ['xmpp.jid'] ts = datetime.datetime.utcfromtimestamp(request.environ['xmpp.timestamp']) MESSAGE_QUEUE[to_jid].put(( 'message', {'to': to_jid, 'body': '[%sZ] %s: %s' % (ts, from_jid, message)} )) return render_template('tell.html')
def test_passed_groupchat(self): environ = {'xmpp.body': 'test', 'xmpp.jid': JID('[email protected]/tasman'), 'xmpp.stanza_type': 'groupchat'} rv = app(environ) self.assertEquals(list(rv), ['tasman: passed'])
def test_strict(self): environ = {'xmpp.body': 'test test test', 'xmpp.jid': JID('*****@*****.**')} rv = app(environ) self.assertEquals(list(rv), [])
def test_invalid_id(self): environ = {'xmpp.body': 'bug XYZ', 'xmpp.jid': JID('*****@*****.**')} rv = app(environ) self.assertEquals(list(rv), [])
def test_passed_groupchat_ru(self): environ = {'xmpp.body': u'тест', 'xmpp.jid': JID('[email protected]/tasman'), 'xmpp.stanza_type': 'groupchat'} rv = app(environ) self.assertEquals(list(rv), [u'tasman: пассед'])
def test_not_found(self): environ = {'xmpp.body': 'bug 000', 'xmpp.jid': JID('*****@*****.**')} rv = app(environ) self.assertEquals(list(rv), ['Ticket 0 does not exist.'])
def test_request_username_groupchat(self): jid = JID('user@domain/resource') req = Request({'xmpp.jid': jid, 'xmpp.stanza_type': 'groupchat'}) self.assertEqual(req.username, 'resource')
def test_request_app_jid(self): jid = JID('user@domain/resource') req = Request({'app.jid': jid}) self.assertTrue(jid is req.app_jid)
def test_not_found(self): environ = {'xmpp.body': 'rev 000', 'xmpp.jid': JID('*****@*****.**')} rv = app(environ) self.assertEquals(list(rv), ['No such revision 0'])
def test_passed(self): environ = {'xmpp.body': 'test', 'xmpp.jid': JID('*****@*****.**'), 'xmpp.stanza_type': 'chat'} rv = app(environ) self.assertEquals(list(rv), ['passed'])