diff --git a/.travis.yml b/.travis.yml index bd4e1030..dd01fc9e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,6 +29,7 @@ before_install: DB=mysql bash ci/init-db.sh pip install 'mysql-connector-python' elif [[ $JUPYTERHUB_TEST_DB_URL == postgresql* ]]; then + psql -c "CREATE USER $PGUSER WITH PASSWORD '$PGPASSWORD';" -U postgres DB=postgres bash ci/init-db.sh pip install psycopg2-binary fi @@ -87,7 +88,10 @@ matrix: - JUPYTERHUB_TEST_DB_URL=mysql+mysqlconnector://root@127.0.0.1:$MYSQL_TCP_PORT/jupyterhub - python: 3.6 env: - - JUPYTERHUB_TEST_DB_URL=postgresql://postgres@127.0.0.1/jupyterhub + - PGUSER=jupyterhub + - PGPASSWORD=hub[test/:? + # password in url is url-encoded (urllib.parse.quote($PGPASSWORD, safe='')) + - JUPYTERHUB_TEST_DB_URL=postgresql://jupyterhub:hub%5Btest%2F%3A%3F@127.0.0.1/jupyterhub - python: 3.7 dist: xenial allow_failures: diff --git a/ci/docker-db.sh b/ci/docker-db.sh index 6f00be03..14e06388 100755 --- a/ci/docker-db.sh +++ b/ci/docker-db.sh @@ -2,7 +2,7 @@ # source this file to setup postgres and mysql # for local testing (as similar as possible to docker) -set -e +set -eu export MYSQL_HOST=127.0.0.1 export MYSQL_TCP_PORT=${MYSQL_TCP_PORT:-13306} @@ -40,6 +40,15 @@ for i in {1..60}; do done $CHECK +case "$DB" in +"mysql") + ;; +"postgres") + # create the user + psql --user postgres -c "CREATE USER $PGUSER WITH PASSWORD '$PGPASSWORD';" + ;; +*) +esac echo -e " Set these environment variables: diff --git a/ci/init-db.sh b/ci/init-db.sh index d9d45721..dfeb12b4 100755 --- a/ci/init-db.sh +++ b/ci/init-db.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # initialize jupyterhub databases for testing -set -e +set -eu MYSQL="mysql --user root --host $MYSQL_HOST --port $MYSQL_TCP_PORT -e " PSQL="psql --user postgres -c " @@ -23,5 +23,5 @@ set -x for SUFFIX in '' _upgrade_072 _upgrade_081 _upgrade_094; do $SQL "DROP DATABASE jupyterhub${SUFFIX};" 2>/dev/null || true - $SQL "CREATE DATABASE jupyterhub${SUFFIX} ${EXTRA_CREATE};" + $SQL "CREATE DATABASE jupyterhub${SUFFIX} ${EXTRA_CREATE:-};" done diff --git a/jupyterhub/tests/test_db.py b/jupyterhub/tests/test_db.py index faf1443f..9369cd77 100644 --- a/jupyterhub/tests/test_db.py +++ b/jupyterhub/tests/test_db.py @@ -30,7 +30,7 @@ def generate_old_db(env_dir, hub_version, db_url): if 'mysql' in db_url: pkgs.append('mysql-connector-python') elif 'postgres' in db_url: - pkgs.append('psycopg2') + pkgs.append('psycopg2-binary') check_call([env_pip, 'install'] + pkgs) check_call([env_py, populate_db, db_url])