~ubuntu-branches/ubuntu/natty/moin/natty-updates

« back to all changes in this revision

Viewing changes to jabberbot/_tests/test_capat.py

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mfrom: (0.9.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080622211713-fpo2zrq3s5dfecxg
Tags: 1.7.0-3
Simplify /etc/moin/wikilist format: "USER URL" (drop unneeded middle
CONFIG_DIR that was wrongly advertised as DATA_DIR).  Make
moin-mass-migrate handle both formats and warn about deprecation of
the old one.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
 
 
3
import py
 
4
 
 
5
try:
 
6
    from jabberbot import capat
 
7
except ImportError:
 
8
    py.test.skip("Skipping jabber bot tests - pyxmpp is not installed")
 
9
 
 
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",
 
16
           )
 
17
 
 
18
    assert capat.generate_ver(ident, feat) == "8RovUdtOmiAjzj+xI7SK5BCw3A8="
 
19
 
 
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
 
24
             ("apples", "bar"),
 
25
             ("apple", "foo"), # "apples" starts with "apple"
 
26
                               # thus it's greater
 
27
            )
 
28
    feat = ()
 
29
 
 
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
 
34
 
 
35
def test_xml():
 
36
    try:
 
37
        import pyxmpp.iq
 
38
    except ImportError:
 
39
        py.test.skip("pyxmpp needs to be installed for this test")
 
40
 
 
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')
 
54
 
 
55
    assert capat.hash_iq(x) == "8RovUdtOmiAjzj+xI7SK5BCw3A8="
 
56
    # hash value taken from `test_ver_simple`
 
57