File: test_stanza_message.py

package info (click to toggle)
slixmpp 1.13.2-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 5,516 kB
  • sloc: python: 41,715; xml: 1,211; makefile: 135
file content (88 lines) | stat: -rw-r--r-- 2,840 bytes parent folder | download | duplicates (5)
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
import unittest
from slixmpp.test import SlixTest
from slixmpp.stanza.message import Message
from slixmpp.stanza.htmlim import HTMLIM
from slixmpp.plugins.xep_0172 import UserNick
from slixmpp.xmlstream import register_stanza_plugin


class TestMessageStanzas(SlixTest):

    def setUp(self):
        register_stanza_plugin(Message, HTMLIM)
        register_stanza_plugin(Message, UserNick)

    def testGroupchatReplyRegression(self):
        "Regression groupchat reply should be to barejid"
        msg = self.Message()
        msg['to'] = 'me@myserver.tld'
        msg['from'] = 'room@someservice.someserver.tld/somenick'
        msg['type'] = 'groupchat'
        msg['body'] = "this is a message"
        msg = msg.reply()
        self.assertTrue(str(msg['to']) == 'room@someservice.someserver.tld')

    def testHTMLPlugin(self):
        "Test message/html/body stanza"
        msg = self.Message()
        msg['to'] = "fritzy@netflint.net/slixmpp"
        msg['body'] = "this is the plaintext message"
        msg['type'] = 'chat'
        msg['html']['body'] = '<p>This is the htmlim message</p>'
        self.check(msg, """
          <message to="fritzy@netflint.net/slixmpp" type="chat">
            <body>this is the plaintext message</body>
            <html xmlns="http://jabber.org/protocol/xhtml-im">
              <body xmlns="http://www.w3.org/1999/xhtml">
                <p>This is the htmlim message</p>
             </body>
            </html>
          </message>""")

    def testNickPlugin(self):
        "Test message/nick/nick stanza."
        msg = self.Message()
        msg['nick']['nick'] = 'A nickname!'
        self.check(msg, """
          <message>
            <nick xmlns="http://jabber.org/protocol/nick">A nickname!</nick>
          </message>
        """)

    def testSubject(self):
        msg = self.Message()
        assert "subject" not in msg
        msg["subject"] = "some subject"
        assert "subject" in msg
        self.check(
            msg,
            """
            <message>
            <subject>some subject</subject>
            </message>
            """,
        )
        assert msg["subject"] == "some subject"
        del msg["subject"]
        assert "subject" not in msg
        assert not msg["subject"]
        assert "subject" not in msg
        self.check(msg, "<message />")
        msg = self.Message()
        msg["subject"] = ""
        assert "subject" in msg
        self.check(
            msg,
            """
        <message>
            <subject />
        </message>
        """,
        use_values=False  # third stanza produced does not contain the <subject /> element
        )
        del msg["subject"]
        assert "subject" not in msg
        self.check(msg, "<message />")


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