Welcome to mirror list, hosted at ThFree Co, Russian Federation.

test_jid_parsing.py « unit « test - dev.gajim.org/gajim/python-nbxmpp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 56ecf88c518f7a49e4aaa0b61c5225e78278a7a0 (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
import unittest

from nbxmpp.protocol import LocalpartByteLimit
from nbxmpp.protocol import LocalpartNotAllowedChar
from nbxmpp.protocol import ResourcepartByteLimit
from nbxmpp.protocol import ResourcepartNotAllowedChar
from nbxmpp.protocol import DomainpartByteLimit
from nbxmpp.protocol import DomainpartNotAllowedChar
from nbxmpp.protocol import JID

class JIDParsing(unittest.TestCase):

    def test_valid_jids(self):
        tests = [
            'juliet@example.com',
            'juliet@example.com/foo',
            'juliet@example.com/foo bar',
            'juliet@example.com/foo@bar',
            'foo\\20bar@example.com',
            'fussball@example.com',
            'fu\U000000DFball@example.com',
            '\U000003C0@example.com',
            '\U000003A3@example.com/foo',
            '\U000003C3@example.com/foo',
            '\U000003C2@example.com/foo',
            'king@example.com/\U0000265A',
            'example.com',
            'example.com/foobar',
            'a.example.com/b@example.net',
        ]

        for jid in tests:
            JID(jid)

    def test_invalid_jids(self):
        tests = [
            ('"juliet"@example.com', LocalpartNotAllowedChar),
            ('foo bar@example.com', LocalpartNotAllowedChar),
            ('henry\U00002163@example.com', LocalpartNotAllowedChar),
            ('@example.com', LocalpartByteLimit),
            ('user@example.com/', ResourcepartByteLimit),
            ('user@example.com/\U00000001', ResourcepartNotAllowedChar),
            ('\U0000265A@example.com', LocalpartNotAllowedChar),
            ('user@host@example.com', DomainpartNotAllowedChar),
            ('juliet@', DomainpartByteLimit),
            ('/foobar', DomainpartByteLimit),
        ]

        for jid, exception in tests:
            with self.assertRaises(exception):
                JID(jid)

    def test_ip_literals(self):
        tests = [
            ('juliet@[2002:4559:1FE2::4559:1FE2]/res'),
            ('juliet@123.123.123.123/res'),
        ]

        for jid in tests:
            JID(jid)