def testBytesPassword(self):
        db = pg8000.connect(**db_connect)
        # Create user
        username = '******'
        password = u('cha\uFF6Fs')
        cur = db.cursor()

        # Delete user if left over from previous run
        try:
            cur.execute("drop role " + username)
        except pg8000.ProgrammingError:
            cur.execute("rollback")

        cur.execute("create user " + username + " with password '" + password +
                    "';")
        cur.execute('commit;')
        db.close()

        data = db_connect.copy()
        data['user'] = username
        data['password'] = password.encode('utf8')
        data['database'] = 'pg8000_md5'
        if PY2:
            self.assertRaises(pg8000.ProgrammingError, pg8000.connect, **data)
        else:
            self.assertRaisesRegex(pg8000.ProgrammingError, '3D000',
                                   pg8000.connect, **data)

        db = pg8000.connect(**db_connect)
        cur = db.cursor()
        cur.execute("drop role " + username)
        cur.execute("commit;")
        db.close()
Beispiel #2
0
    def testBytesPassword(self):
        db = pg8000.connect(**db_connect)
        # Create user
        username = '******'
        password = u('cha\uFF6Fs')
        cur = db.cursor()

        # Delete user if left over from previous run
        try:
            cur.execute("drop role " + username)
        except pg8000.ProgrammingError:
            cur.execute("rollback")

        cur.execute(
            "create user " + username + " with password '" + password + "';")
        cur.execute('commit;')
        db.close()

        data = db_connect.copy()
        data['user'] = username
        data['password'] = password.encode('utf8')
        data['database'] = 'pg8000_md5'
        if PY2:
            self.assertRaises(
                pg8000.ProgrammingError, pg8000.connect, **data)
        else:
            self.assertRaisesRegex(
                pg8000.ProgrammingError, '3D000', pg8000.connect, **data)

        db = pg8000.connect(**db_connect)
        cur = db.cursor()
        cur.execute("drop role " + username)
        cur.execute("commit;")
        db.close()
 def testSsl(self):
     data = db_connect.copy()
     data["ssl"] = True
     if PRE_26:
         self.assertRaises(pg8000.InterfaceError, pg8000.connect, **data)
     else:
         db = pg8000.connect(**data)
         db.close()
Beispiel #4
0
 def testSsl(self):
     data = db_connect.copy()
     data["ssl"] = True
     if PRE_26:
         self.assertRaises(pg8000.InterfaceError, pg8000.connect, **data)
     else:
         db = pg8000.connect(**data)
         db.close()
    def testMd5(self):
        data = db_connect.copy()
        data["database"] = "pg8000_md5"

        # Should only raise an exception saying db doesn't exist
        if PY2:
            self.assertRaises(pg8000.ProgrammingError, pg8000.connect, **data)
        else:
            self.assertRaisesRegex(pg8000.ProgrammingError, '3D000',
                                   pg8000.connect, **data)
    def testPassword(self):
        data = db_connect.copy()
        data["database"] = "pg8000_password"

        # Should only raise an exception saying db doesn't exist
        if PY2:
            self.assertRaises(
                pg8000.ProgrammingError, pg8000.connect, **data)
        else:
            self.assertRaisesRegex(
                pg8000.ProgrammingError, '3D000', pg8000.connect, **data)
    def testBytesDatabaseName(self):
        data = db_connect.copy()

        # Should only raise an exception saying db doesn't exist
        if PY2:
            data["database"] = "pg8000_sn\uFF6Fw"
            self.assertRaises(pg8000.ProgrammingError, pg8000.connect, **data)
        else:
            data["database"] = bytes("pg8000_sn\uFF6Fw", 'utf8')
            self.assertRaisesRegex(pg8000.ProgrammingError, '3D000',
                                   pg8000.connect, **data)
    def testGss(self):
        data = db_connect.copy()
        data["database"] = "pg8000_gss"

        # Should raise an exception saying gss isn't supported
        if PY2:
            self.assertRaises(pg8000.InterfaceError, pg8000.connect, **data)
        else:
            self.assertRaisesRegex(
                pg8000.InterfaceError,
                "Authentication method 7 not supported by pg8000.",
                pg8000.connect, **data)
Beispiel #9
0
    def testGss(self):
        data = db_connect.copy()
        data["database"] = "pg8000_gss"

        # Should raise an exception saying gss isn't supported
        if PY2:
            self.assertRaises(pg8000.InterfaceError, pg8000.connect, **data)
        else:
            self.assertRaisesRegex(
                pg8000.InterfaceError,
                "Authentication method 7 not supported by pg8000.",
                pg8000.connect, **data)
Beispiel #10
0
    def testBytesDatabaseName(self):
        data = db_connect.copy()

        # Should only raise an exception saying db doesn't exist
        if PY2:
            data["database"] = "pg8000_sn\uFF6Fw"
            self.assertRaises(
                pg8000.ProgrammingError, pg8000.connect, **data)
        else:
            data["database"] = bytes("pg8000_sn\uFF6Fw", 'utf8')
            self.assertRaisesRegex(
                pg8000.ProgrammingError, '3D000', pg8000.connect, **data)
Beispiel #11
0
    def testApplicatioName(self):
        params = db_connect.copy()
        params['application_name'] = 'my test application name'
        db = pg8000.connect(**params)
        cur = db.cursor()

        if db._server_version >= LooseVersion('9.2'):
            cur.execute('select application_name from pg_stat_activity '
                        ' where pid = pg_backend_pid()')
        else:
            # for pg9.1 and earlier, procpod field rather than pid
            cur.execute('select application_name from pg_stat_activity '
                        ' where procpid = pg_backend_pid()')

        application_name = cur.fetchone()[0]
        self.assertEqual(application_name, 'my test application name')
 def testDatabaseMissing(self):
     data = db_connect.copy()
     data["database"] = "missing-db"
     self.assertRaises(pg8000.ProgrammingError, pg8000.connect, **data)
Beispiel #13
0
 def testDatabaseMissing(self):
     data = db_connect.copy()
     data["database"] = "missing-db"
     self.assertRaises(pg8000.ProgrammingError, pg8000.connect, **data)
Beispiel #14
0
 def testSsl(self):
     data = db_connect.copy()
     data["ssl"] = True
     db = pg8000.connect(**data)
     db.close()
Beispiel #15
0
 def testSsl(self):
     data = db_connect.copy()
     data["ssl"] = True
     db = pg8000.connect(**data)
     db.close()