Exemplo n.º 1
0
def test_mysql():
    from openid.store import sqlstore
    try:
        import MySQLdb
    except ImportError:
        pass
    else:
        db_user = '******'
        db_passwd = ''
        db_name = getTmpDbName()

        from MySQLdb.constants import ER

        # Change this connect line to use the right user and password
        conn = MySQLdb.connect(user=db_user, passwd=db_passwd, host = db_host)

        conn.query('CREATE DATABASE %s;' % db_name)
        try:
            conn.query('USE %s;' % db_name)

            # OK, we're in the right environment. Create store and
            # create the tables.
            store = sqlstore.MySQLStore(conn)
            store.createTables()

            # At last, we get to run the test.
            testStore(store)
        finally:
            # Remove the database. If you want to do post-mortem on a
            # failing test, comment out this line.
            conn.query('DROP DATABASE %s;' % db_name)
Exemplo n.º 2
0
def test_mysql():
    from openid.store import sqlstore

    try:
        import MySQLdb
    except ImportError:
        raise unittest.SkipTest("Skipping MySQL store tests. "
                                "Could not import MySQLdb.")

    else:
        db_host = os.environ.get("TEST_MYSQL_HOST", "localhost")
        db_user = os.environ.get("TEST_MYSQL_USER", "openid_test")
        db_passwd = os.environ.get("TEST_MYSQL_PASSWORD", "password")
        db_name = getTmpDbName()

        from MySQLdb.constants import ER

        # Change this connect line to use the right user and password
        try:
            conn = MySQLdb.connect(user=db_user,
                                   passwd=db_passwd,
                                   host=db_host)
        except MySQLdb.OperationalError as why:
            if why.args[0] == 2005:
                raise unittest.SkipTest(
                    "Skipping MySQL store test. "
                    "Cannot connect to server on host %r." % (db_host, ))
            else:
                raise

        conn.query("CREATE DATABASE %s;" % db_name)
        try:
            conn.query("USE %s;" % db_name)

            # OK, we're in the right environment. Create store and
            # create the tables.
            store = sqlstore.MySQLStore(conn)
            store.createTables()

            # At last, we get to run the test.
            testStore(store)
        finally:
            # Remove the database. If you want to do post-mortem on a
            # failing test, comment out this line.
            conn.query("DROP DATABASE %s;" % db_name)
Exemplo n.º 3
0
def test_mysql():
    # TODO fix
    from openid.store import sqlstore
    try:
        import MySQLdb
    except ImportError:
        warnings.warn("Could not import MySQLdb. Skipping MySQL store tests.")
        pass
    else:
        db_user = '******'
        db_passwd = ''
        db_name = getTmpDbName()

        from MySQLdb.constants import ER

        # Change this connect line to use the right user and password
        try:
            conn = MySQLdb.connect(user=db_user,
                                   passwd=db_passwd,
                                   host=db_host)
        except MySQLdb.OperationalError as why:
            if int(why) == 2005:
                print(('Skipping MySQL store test (cannot connect '
                       'to test server on host %r)' % (db_host, )))
                return
            else:
                raise

        conn.query('CREATE DATABASE %s;' % db_name)
        try:
            conn.query('USE %s;' % db_name)

            # OK, we're in the right environment. Create store and
            # create the tables.
            store = sqlstore.MySQLStore(conn)
            store.createTables()

            # At last, we get to run the test.
            testStore(store)
        finally:
            # Remove the database. If you want to do post-mortem on a
            # failing test, comment out this line.
            conn.query('DROP DATABASE %s;' % db_name)