예제 #1
0
파일: app.py 프로젝트: santiago26/tasman
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')
예제 #2
0
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')
예제 #3
0
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')
예제 #4
0
    def test_hash(self):
        environ = {
            'xmpp.body': '#155',
            'xmpp.jid': JID('*****@*****.**'),
            'xmpp.stanza_type': 'chat'
        }

        rv = app(environ)
        self.check_resp(rv.next())
예제 #5
0
    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"а это еще кто?"])
예제 #6
0
    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?"])
예제 #7
0
    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')
예제 #8
0
    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"он зашифровался")
예제 #9
0
    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")
예제 #10
0
    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))
예제 #11
0
    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))
예제 #12
0
    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())
예제 #13
0
    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())
예제 #14
0
    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())
예제 #15
0
    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())
예제 #16
0
    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'
            }))
예제 #17
0
    def test_not_found(self):
        environ = {'xmpp.body': 'rev 000', 'xmpp.jid': JID('*****@*****.**')}

        rv = app(environ)
        self.assertEquals(list(rv), ['No such revision 0'])
예제 #18
0
    def test_invalid_id(self):
        environ = {'xmpp.body': 'bug XYZ', 'xmpp.jid': JID('*****@*****.**')}

        rv = app(environ)
        self.assertEquals(list(rv), [])
예제 #19
0
    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.'])
예제 #20
0
 def test_request_app_jid(self):
     jid = JID('user@domain/resource')
     req = Request({'app.jid': jid})
     self.assertTrue(jid is req.app_jid)
예제 #21
0
    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'])
예제 #22
0
    def test_passed(self):
        environ = {'xmpp.body': 'test', 'xmpp.jid': JID('*****@*****.**'),
                   'xmpp.stanza_type': 'chat'}

        rv = app(environ)
        self.assertEquals(list(rv), ['passed'])
예제 #23
0
    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: пассед'])
예제 #24
0
    def test_strict(self):
        environ = {'xmpp.body': 'test test test',
                   'xmpp.jid': JID('*****@*****.**')}

        rv = app(environ)
        self.assertEquals(list(rv), [])
예제 #25
0
 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')