Exemplo n.º 1
0
 def test_init_with_default_strict_errors_on_unassigned(self):
     with self.assertRaises(ValueError):
         structs.JID("\U0001f601", "example.com", "bar")
     with self.assertRaises(ValueError):
         structs.JID("foo", "\U0001f601example.com", "bar")
     with self.assertRaises(ValueError):
         structs.JID("foo", "example.com", "\U0001f601")
Exemplo n.º 2
0
 def test_reject_long_localpart(self):
     with self.assertRaisesRegex(ValueError, "too long"):
         structs.JID("x"*1024, "foo", None)
     with self.assertRaisesRegex(ValueError, "too long"):
         structs.JID("ü"*512, "foo", None)
     with self.assertRaisesRegex(ValueError, "too long"):
         structs.JID.fromstr("ü"*512 + "@foo")
Exemplo n.º 3
0
 def test_fromstr_full(self):
     self.assertEqual(structs.JID("foo", "example.test", "bar"),
                      structs.JID.fromstr("[email protected]/bar"))
     self.assertEqual(structs.JID("ßA", "IX.test", "\u2168"),
                      structs.JID.fromstr("[email protected]/IX"))
     self.assertEqual(structs.JID("ßA", "IX.test", "bar@baz/fnord"),
                      structs.JID.fromstr("[email protected]/bar@baz/fnord"))
Exemplo n.º 4
0
 def test_reject_long_domainpart(self):
     with self.assertRaisesRegex(ValueError, "too long"):
         structs.JID(None, "x"*1024, None)
     with self.assertRaisesRegex(ValueError, "too long"):
         structs.JID(None, "ü"*512, None)
     with self.assertRaisesRegex(ValueError, "too long"):
         structs.JID.fromstr("ü"*512)
Exemplo n.º 5
0
 def test_reject_long_resource(self):
     with self.assertRaisesRegex(ValueError, "too long"):
         structs.JID(None, "foo", "x"*1024)
     with self.assertRaisesRegex(ValueError, "too long"):
         structs.JID(None, "foo", "ü"*512)
     with self.assertRaisesRegex(ValueError, "too long"):
         structs.JID.fromstr("foo/" + "ü"*512)
Exemplo n.º 6
0
 def test_fromstr_bare(self):
     self.assertEqual(
         structs.JID("foo", "example.test", None),
         structs.JID.fromstr("*****@*****.**")
     )
     self.assertEqual(
         structs.JID("ßA", "IX.test", None),
         structs.JID.fromstr("*****@*****.**")
     )
Exemplo n.º 7
0
 def test_fromstr_domain(self):
     self.assertEqual(
         structs.JID(None, "example.test", None),
         structs.JID.fromstr("example.test")
     )
     self.assertEqual(
         structs.JID(None, "IX.test", None),
         structs.JID.fromstr("ix.test")
     )
Exemplo n.º 8
0
 def test_init_domain_jid(self):
     j = structs.JID(None, "example.test", None)
     self.assertIsNone(j.resource)
     self.assertIsNone(j.localpart)
     self.assertEqual(
         "example.test",
         j.domain)
Exemplo n.º 9
0
 def test_fromstr_domain_nonstrict(self):
     self.assertEqual(
         structs.JID("\U0001f601", "\U0001f601example.test", "\U0001f601",
                     strict=False),
         structs.JID.fromstr("\U0001f601@\U0001f601example.test/\U0001f601",
                             strict=False)
     )
Exemplo n.º 10
0
 def test_replace(self):
     j = structs.JID("foo", "example.com", "bar")
     j2 = j.replace(localpart="fnord",
                    domain="example.invalid",
                    resource="baz")
     self.assertEqual("fnord", j2.localpart)
     self.assertEqual("example.invalid", j2.domain)
     self.assertEqual("baz", j2.resource)
Exemplo n.º 11
0
    def test_replace_ignores_problems_on_existing_parts(self):
        j = structs.JID(
            "\U0001f601foo", "\U0001f601example.test", "\U0001f601bar",
            strict=False,
        )

        j2 = j.replace()
        self.assertEqual(j, j2)
Exemplo n.º 12
0
    def test_replace_checks_replaced_strings(self):
        j = structs.JID(
            "\U0001f601foo", "\U0001f601example.test", "\U0001f601bar",
            strict=False,
        )

        with self.assertRaises(ValueError):
            j.replace(
                domain=j.domain
            )
Exemplo n.º 13
0
 def test_init_full(self):
     j = structs.JID("foo", "example.com", "bar")
     self.assertEqual(
         "foo",
         j.localpart)
     self.assertEqual(
         "example.com",
         j.domain)
     self.assertEqual(
         "bar",
         j.resource)
Exemplo n.º 14
0
    def test_replace_nonstrict_allows_unassigned_codepoints(self):
        j = structs.JID(
            "\U0001f601foo", "\U0001f601example.test", "\U0001f601bar",
            strict=False,
        )

        j2 = j.replace(
            domain=j.domain,
            strict=False,
        )

        self.assertEqual(j, j2)
Exemplo n.º 15
0
    def test_replace_enforces_stringprep(self):
        j = structs.JID("foo", "example.com", "bar")
        with self.assertRaises(ValueError):
            j.replace(localpart="\u0007")
        with self.assertRaises(ValueError):
            j.replace(domain="\u070f")
        with self.assertRaises(ValueError):
            j.replace(resource="\u0007")

        self.assertEqual("ssa", j.replace(localpart="ßA").localpart)
        self.assertEqual("ix.test", j.replace(domain="IX.test").domain)
        self.assertEqual("IX", j.replace(resource="\u2168").resource)
Exemplo n.º 16
0
    def test_init_enforces_stringprep(self):
        with self.assertRaises(ValueError):
            structs.JID("\u0007", "example.com", "bar")
        with self.assertRaises(ValueError):
            structs.JID("foo", "\u070f", "bar")
        with self.assertRaises(ValueError):
            structs.JID("foo", "example.com", "\u0007")

        self.assertEqual("ssa",
                         structs.JID("ßA", "example.test", None).localpart)

        self.assertEqual("ix.test", structs.JID(None, "IX.test", None).domain)

        self.assertEqual("IX",
                         structs.JID(None, "example.test", "\u2168").resource)
Exemplo n.º 17
0
 def test_reject_empty_resource(self):
     with self.assertRaises(ValueError):
         structs.JID("foo", "bar.baz", "")
     with self.assertRaises(ValueError):
         structs.JID.fromstr("[email protected]/")
Exemplo n.º 18
0
 def test_reject_empty_domainpart(self):
     with self.assertRaises(ValueError):
         structs.JID("foo", "", None)
     with self.assertRaises(ValueError):
         structs.JID.fromstr("foo@")
Exemplo n.º 19
0
 def test_reject_empty_localpart(self):
     with self.assertRaises(ValueError):
         structs.JID("", "bar.baz", None)
     with self.assertRaises(ValueError):
         structs.JID.fromstr("@bar.baz")
Exemplo n.º 20
0
 def test_str_full_jid(self):
     j = structs.JID("foo", "example.test", "bar")
     self.assertEqual(
         "[email protected]/bar",
         str(j))
Exemplo n.º 21
0
 def test_fromstr_domain_with_funny_resource(self):
     self.assertEqual(
         structs.JID(None, "example.test", "foo@bar"),
         structs.JID.fromstr("example.test/foo@bar")
     )
Exemplo n.º 22
0
 def test_replace_rejects_surplus_argument(self):
     j = structs.JID("foo", "example.test", "bar")
     with self.assertRaises(TypeError):
         j.replace(foobar="baz")
Exemplo n.º 23
0
 def test_str_domain_jid(self):
     j = structs.JID(None, "example.test", None)
     self.assertEqual(
         "example.test",
         str(j))
Exemplo n.º 24
0
 def test_is_domain(self):
     self.assertFalse(structs.JID("foo", "example.test", "bar").is_domain)
     self.assertFalse(structs.JID("foo", "example.test", None).is_domain)
     self.assertTrue(structs.JID(None, "example.test", None).is_domain)
Exemplo n.º 25
0
 def test_bare(self):
     j = structs.JID("foo", "example.test", "bar")
     self.assertEqual(
         structs.JID("foo", "example.test", None),
         j.bare())
Exemplo n.º 26
0
 def test_immutable(self):
     j = structs.JID(None, "example.test", None)
     with self.assertRaises(AttributeError):
         j.foo = "bar"
Exemplo n.º 27
0
 def test_replace_domain_jid(self):
     j = structs.JID("foo", "example.test", "bar")
     self.assertEqual(
         structs.JID(None, "example.test", None),
         j.replace(localpart=None, resource=None)
     )
Exemplo n.º 28
0
 def test_replace_require_domainpart(self):
     j = structs.JID("foo", "example.test", "bar")
     with self.assertRaises(ValueError):
         j.replace(domain=None)
Exemplo n.º 29
0
 def test_str_bare_jid(self):
     j = structs.JID("foo", "example.test", None)
     self.assertEqual(
         "*****@*****.**",
         str(j))
Exemplo n.º 30
0
 def test_require_domainpart(self):
     with self.assertRaises(ValueError):
         structs.JID(None, None, None)