summaryrefslogtreecommitdiff
path: root/tests/test_stanza_xep_0377.py
blob: 321a26a8d423ef7328cdb448822e721bea3d8968 (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
import unittest
from slixmpp import Iq
from slixmpp.test import SlixTest
import slixmpp.plugins.xep_0191 as xep_0191
import slixmpp.plugins.xep_0377 as xep_0377
from slixmpp.xmlstream import register_stanza_plugin


class TestSpamReporting(SlixTest):

    def setUp(self):
        register_stanza_plugin(Iq, xep_0191.Block)
        register_stanza_plugin(
                xep_0191.Block,
                xep_0377.Report,
        )
        register_stanza_plugin(
            xep_0377.Report,
            xep_0377.Text,
        )

    def testCreateReport(self):
        report = """
          <iq type="set">
            <block xmlns="urn:xmpp:blocking">
                <report xmlns="urn:xmpp:reporting:0">
                    <spam/>
                </report>
            </block>
          </iq>
        """

        iq = self.Iq()
        iq['type'] = 'set'
        iq['block']['report']['spam'] = True

        self.check(iq, report)

    def testEnforceOnlyOneSubElement(self):
        report = """
          <iq type="set">
            <block xmlns="urn:xmpp:blocking">
                <report xmlns="urn:xmpp:reporting:0">
                    <abuse/>
                </report>
            </block>
          </iq>
        """

        iq = self.Iq()
        iq['type'] = 'set'
        iq['block']['report']['spam'] = True
        iq['block']['report']['abuse'] = True
        self.check(iq, report)

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