Exemple #1
0
    def testAlternateSchemes(self):
        field = pg_iri.parse("postgres://host")['host']
        self.assertEqual(field, 'host')

        field = pg_iri.parse("postgresql://host")['host']
        self.assertEqual(field, 'host')

        try:
            pg_iri.parse("reject://host")
        except ValueError:
            pass
        else:
            self.fail("unacceptable IRI scheme not rejected")
Exemple #2
0
 def testParseSerialize(self):
     scheme = 'pq://'
     for x in iri_samples:
         px = pg_iri.parse(x)
         spx = pg_iri.serialize(px)
         pspx = pg_iri.parse(spx)
         self.assertTrue(
             pspx == px,
             "parse-serialize incongruity, %r -> %r -> %r : %r != %r" %
             (x, px, spx, pspx, px))
         spspx = pg_iri.serialize(pspx)
         self.assertTrue(
             spx == spspx,
             "parse-serialize incongruity, %r -> %r -> %r -> %r : %r != %r"
             % (x, px, spx, pspx, spspx, spx))
Exemple #3
0
    def testPresentPasswordObscure(self):
        """
		Password is *not* present in IRI, and do nothing.
		"""
        s = 'pq://user@host:port/dbname'
        o = 'pq://user@host:port/dbname'
        p = pg_iri.parse(s)
        ps = pg_iri.serialize(p, obscure_password=True)
        self.assertEqual(ps, o)
Exemple #4
0
    def testPresentPasswordObscure(self):
        """
		Password is present in IRI, and obscure it.
		"""
        s = 'pq://*****:*****@host:port/dbname'
        o = 'pq://*****:*****@host:port/dbname'
        p = pg_iri.parse(s)
        ps = pg_iri.serialize(p, obscure_password=True)
        self.assertEqual(ps, o)
Exemple #5
0
 def testSerializeParse(self):
     for x in sample_structured_parameters:
         xs = pg_iri.serialize(x)
         uxs = pg_iri.parse(xs)
         self.assertTrue(
             x == uxs, "serialize-parse incongruity, %r -> %r -> %r" % (
                 x,
                 xs,
                 uxs,
             ))
Exemple #6
0
    def testIP6Hosts(self):
        """
		Validate that IPv6 hosts are properly extracted.
		"""
        s = [
            ('pq://[::1]/db', '::1'),
            ('pq://[::1]:1234/db', '::1'),
            ('pq://[1:2:3::1]/db', '1:2:3::1'),
            ('pq://[1:2:3::1]:1234/db', '1:2:3::1'),
            ('pq://[]:1234/db', ''),
            ('pq://[]/db', ''),
        ]
        for i, h in s:
            p = pg_iri.parse(i)
            self.assertEqual(p['host'], h)