Back to index

moin  1.9.0~rc2
test_capat.py
Go to the documentation of this file.
00001 # -*- coding: utf-8 -*-
00002 
00003 import py
00004 
00005 try:
00006     from jabberbot import capat
00007 except ImportError:
00008     py.test.skip("Skipping jabber bot tests - pyxmpp is not installed")
00009 
00010 def test_ver_simple():
00011     # example values supplied by the XEP
00012     ident = (("client", "pc"), )
00013     feat = ("http://jabber.org/protocol/disco#info",
00014             "http://jabber.org/protocol/disco#items",
00015             "http://jabber.org/protocol/muc",
00016            )
00017 
00018     assert capat.generate_ver(ident, feat) == "8RovUdtOmiAjzj+xI7SK5BCw3A8="
00019 
00020 def test_ver_complex():
00021     # this test should verify that ordering works properly
00022     ident = (("client", "animal"),
00023              ("client", "bear"), # type ordering after category ordering
00024              ("apples", "bar"),
00025              ("apple", "foo"), # "apples" starts with "apple"
00026                                # thus it's greater
00027             )
00028     feat = ()
00029 
00030     expected = capat.hash_new('sha1')
00031     expected.update("apple/foo<apples/bar<client/animal<client/bear<")
00032     expected = capat.base64.b64encode(expected.digest())
00033     assert capat.generate_ver(ident, feat) == expected
00034 
00035 def test_xml():
00036     try:
00037         import pyxmpp.iq
00038     except ImportError:
00039         py.test.skip("pyxmpp needs to be installed for this test")
00040 
00041     x = pyxmpp.iq.Iq(stanza_type='result', stanza_id='disco1',
00042                      from_jid='romeo@montague.lit/orchard',
00043                      to_jid='juliet@capulet.lit/chamber')
00044     y = x.new_query(ns_uri='http://jabber.org/protocol/disco#info')
00045     z = y.newChild(None, 'identity', None)
00046     z.setProp('category', 'client')
00047     z.setProp('type', 'pc')
00048     y.newChild(None, 'feature', None).setProp(
00049         'var', 'http://jabber.org/protocol/disco#info')
00050     y.newChild(None, 'feature', None).setProp(
00051         'var', 'http://jabber.org/protocol/disco#items')
00052     y.newChild(None, 'feature', None).setProp(
00053         'var', 'http://jabber.org/protocol/muc')
00054 
00055     assert capat.hash_iq(x) == "8RovUdtOmiAjzj+xI7SK5BCw3A8="
00056     # hash value taken from `test_ver_simple`
00057