Exemple #1
0
    def test_postgres(self):
        """
        Postgres URIs should be supported
        """
        p = parseURI('postgres://')
        self.assertEqual(p['scheme'], 'postgres')

        p = parseURI('postgres:///postgres')
        self.assertEqual(p['db'], 'postgres')
        self.assertFalse('user' in p)
        self.assertFalse('host' in p)
        self.assertFalse('port' in p)
        self.assertFalse('password' in p)
        self.assertFalse('sslmode' in p)

        p = parseURI('postgres://user@host:1234/postgres')
        self.assertEqual(p['db'], 'postgres')
        self.assertEqual(p['user'], 'user')
        self.assertEqual(p['host'], 'host')
        self.assertEqual(p['port'], 1234)

        p = parseURI('postgres://*****:*****@')
        self.assertEqual(p['user'], 'user')
        self.assertEqual(p['password'], 'password')

        p = parseURI('postgres:///postgres?sslmode=require')
        self.assertEqual(p['db'], 'postgres')
        self.assertEqual(p['sslmode'], 'require')
Exemple #2
0
    def test_sqlite(self):
        """
        sqlite URIs should be supported
        """
        parsed = parseURI('sqlite:')
        self.assertEqual(parsed['scheme'], 'sqlite')
        self.assertEqual(parsed['file'], '')

        parsed = parseURI('sqlite:/tmp/foo')
        self.assertEqual(parsed['scheme'], 'sqlite')
        self.assertEqual(parsed['file'], '/tmp/foo')

        parsed = parseURI('sqlite:tmp/foo')
        self.assertEqual(parsed['scheme'], 'sqlite')
        self.assertEqual(parsed['file'], 'tmp/foo')
Exemple #3
0
def makePool(uri, connections=1):
    parsed = parseURI(uri)
    if parsed['scheme'] == 'sqlite':
        return _makeSqlite(parsed)
    elif parsed['scheme'] == 'postgres':
        return _makePostgres(parsed, connections)
    else:
        raise Exception('%s is not supported' % (parsed['scheme'],))
Exemple #4
0
 def t(i, expected):
     expected_parts = expected.split(' ')
     parsed = parseURI(i)
     output = mkConnStr(parsed)
     parts = output.split(' ')
     self.assertEqual(set(expected_parts), set(parts),
                      "Expected URI\n    %r\nto become like conn "
                      "string\n    %r\nbut it was\n    %r" % (i,
                      expected, output))
Exemple #5
0
def postgresConnStr():
    if not postgres_url:
        raise SkipTest(skip_postgres)
    return mkConnStr(parseURI(postgres_url))
Exemple #6
0
 def t(self, i, expected):
     parsed = parseURI(i)
     output = mkConnStr(parsed)
     self.assertEqual(output, expected, "Expected URI %r to become conn "
                      "string\n%r\nbut it was\n%r" % (i, expected, output))