test postgres with url-encoded username+password

This commit is contained in:
Min RK
2019-04-16 12:52:04 +02:00
parent f3878d8216
commit ab00a19be1
4 changed files with 18 additions and 5 deletions

View File

@@ -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:

View File

@@ -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:

View File

@@ -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

View File

@@ -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])