/usr/share/pyshared/wokkel/test/test_shim.py is in python-wokkel 0.7.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | # -*- test-case-name: wokkel.test.test_shim -*-
#
# Copyright (c) Ralph Meijer.
# See LICENSE for details.
"""
Tests for {wokkel.shim}.
"""
from twisted.trial import unittest
from wokkel import shim
from wokkel.generic import parseXml
NS_SHIM = 'http://jabber.org/protocol/shim'
class HeadersTest(unittest.TestCase):
"""
Tests for L{wokkel.shim.headers}.
"""
def test_noHeaders(self):
headers = shim.Headers([])
self.assertEquals(NS_SHIM, headers.uri)
self.assertEquals('headers', headers.name)
self.assertEquals([], headers.children)
def test_header(self):
headers = shim.Headers([('Urgency', 'high')])
elements = list(headers.elements())
self.assertEquals(1, len(elements))
header = elements[0]
self.assertEquals(NS_SHIM, header.uri)
self.assertEquals('header', header.name)
self.assertEquals('Urgency', header['name'])
self.assertEquals('high', unicode(header))
def test_headerRepeated(self):
"""
Some headers can appear more than once with the same name.
"""
headers = shim.Headers([('Collection', 'node1'),
('Collection', 'node2')])
elements = list(headers.elements())
self.assertEquals(2, len(elements))
collections = set((unicode(element) for element in elements
if element['name'] == 'Collection'))
self.assertIn('node1', collections)
self.assertIn('node2', collections)
class ExtractHeadersTest(unittest.TestCase):
"""
Tests for L{wokkel.shim.extractHeaders}.
"""
def test_noHeaders(self):
"""
A stanza without headers results in an empty dictionary.
"""
stanza = parseXml("""<message/>""")
headers = shim.extractHeaders(stanza)
self.assertEquals({}, headers)
def test_headers(self):
"""
A stanza with headers results in a dictionary with those headers.
"""
xml = """<message>
<headers xmlns='http://jabber.org/protocol/shim'>
<header name='Collection'>node1</header>
<header name='Urgency'>high</header>
</headers>
</message>"""
stanza = parseXml(xml)
headers = shim.extractHeaders(stanza)
self.assertEquals({'Urgency': ['high'],
'Collection': ['node1']}, headers)
def test_headersRepeated(self):
"""
Some headers may appear repeatedly. Make sure all values are extracted.
"""
xml = """<message>
<headers xmlns='http://jabber.org/protocol/shim'>
<header name='Collection'>node1</header>
<header name='Urgency'>high</header>
<header name='Collection'>node2</header>
</headers>
</message>"""
stanza = parseXml(xml)
headers = shim.extractHeaders(stanza)
self.assertEquals({'Urgency': ['high'],
'Collection': ['node1', 'node2']}, headers)
|