1
# -*- coding: utf-8 -*-
6
from jabberbot import capat
8
py.test.skip("Skipping jabber bot tests - pyxmpp is not installed")
10
def test_ver_simple():
11
# example values supplied by the XEP
12
ident = (("client", "pc"), )
13
feat = ("http://jabber.org/protocol/disco#info",
14
"http://jabber.org/protocol/disco#items",
15
"http://jabber.org/protocol/muc",
18
assert capat.generate_ver(ident, feat) == "8RovUdtOmiAjzj+xI7SK5BCw3A8="
20
def test_ver_complex():
21
# this test should verify that ordering works properly
22
ident = (("client", "animal"),
23
("client", "bear"), # type ordering after category ordering
25
("apple", "foo"), # "apples" starts with "apple"
30
expected = capat.hash_new('sha1')
31
expected.update("apple/foo<apples/bar<client/animal<client/bear<")
32
expected = capat.base64.b64encode(expected.digest())
33
assert capat.generate_ver(ident, feat) == expected
39
py.test.skip("pyxmpp needs to be installed for this test")
41
x = pyxmpp.iq.Iq(stanza_type='result', stanza_id='disco1',
42
from_jid='romeo@montague.lit/orchard',
43
to_jid='juliet@capulet.lit/chamber')
44
y = x.new_query(ns_uri='http://jabber.org/protocol/disco#info')
45
z = y.newChild(None, 'identity', None)
46
z.setProp('category', 'client')
47
z.setProp('type', 'pc')
48
y.newChild(None, 'feature', None).setProp(
49
'var', 'http://jabber.org/protocol/disco#info')
50
y.newChild(None, 'feature', None).setProp(
51
'var', 'http://jabber.org/protocol/disco#items')
52
y.newChild(None, 'feature', None).setProp(
53
'var', 'http://jabber.org/protocol/muc')
55
assert capat.hash_iq(x) == "8RovUdtOmiAjzj+xI7SK5BCw3A8="
56
# hash value taken from `test_ver_simple`