summaryrefslogtreecommitdiff
path: root/tests/test_stanza_xep_0059.py
blob: 860ec869b4245b81171bd55b82d4ec953acbdb63 (plain)
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
99
100
101
102
103
104
105
106
107
108
import unittest
from sleekxmpp.test import SleekTest
from sleekxmpp.plugins.xep_0059 import Set
from sleekxmpp.xmlstream import ET


class TestSetStanzas(SleekTest):

    def testSetFirstIndex(self):
        s = Set()
        s['first'] = 'id'
        s.set_first_index('10')
        self.check(s, """
          <set xmlns="http://jabber.org/protocol/rsm">
            <first index="10">id</first>
          </set>
        """)

    def testGetFirstIndex(self):
        xml_string = """
          <set xmlns="http://jabber.org/protocol/rsm">
            <first index="10">id</first>
          </set>
        """
        s = Set(ET.fromstring(xml_string))
        expected = '10'
        self.failUnless(s['first_index'] == expected)

    def testDelFirstIndex(self):
        xml_string = """
          <set xmlns="http://jabber.org/protocol/rsm">
            <first index="10">id</first>
          </set>
        """
        s = Set(ET.fromstring(xml_string))
        del s['first_index']
        self.check(s, """
          <set xmlns="http://jabber.org/protocol/rsm">
            <first>id</first>
          </set>
        """)

    def testSetBefore(self):
        s = Set()
        s['before'] = True
        self.check(s, """
          <set xmlns="http://jabber.org/protocol/rsm">
            <before />
          </set>
        """)

    def testGetBefore(self):
        xml_string = """
          <set xmlns="http://jabber.org/protocol/rsm">
            <before />
          </set>
        """
        s = Set(ET.fromstring(xml_string))
        expected = True
        self.failUnless(s['before'] == expected)

    def testGetBefore(self):
        xml_string = """
          <set xmlns="http://jabber.org/protocol/rsm">
            <before />
          </set>
        """
        s = Set(ET.fromstring(xml_string))
        del s['before']
        self.check(s, """
          <set xmlns="http://jabber.org/protocol/rsm">
          </set>
        """)

    def testSetBeforeVal(self):
        s = Set()
        s['before'] = 'id'
        self.check(s, """
          <set xmlns="http://jabber.org/protocol/rsm">
            <before>id</before>
          </set>
        """)

    def testGetBeforeVal(self):
        xml_string = """
          <set xmlns="http://jabber.org/protocol/rsm">
            <before>id</before>
          </set>
        """
        s = Set(ET.fromstring(xml_string))
        expected = 'id'
        self.failUnless(s['before'] == expected)

    def testGetBeforeVal(self):
        xml_string = """
          <set xmlns="http://jabber.org/protocol/rsm">
            <before>id</before>
          </set>
        """
        s = Set(ET.fromstring(xml_string))
        del s['before']
        self.check(s, """
          <set xmlns="http://jabber.org/protocol/rsm">
          </set>
        """)


suite = unittest.TestLoader().loadTestsFromTestCase(TestSetStanzas)