Skip to content

Commit

Permalink
feat: Rewrite travis tests to use postgres
Browse files Browse the repository at this point in the history
Replaces mysql tests with postgres tests. No new tests are added, the
old tests are just rewriten for postgres.
  • Loading branch information
Martin Norling committed Feb 13, 2019
1 parent d6b1111 commit aad4484
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 25 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ scripts/importer/downloaded_files
postgres-data
# local personal things
personal
# travis test remnants
master-schema.sql
settings.json.tmp
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,20 @@ python:
- "3.5"
services:
- docker
- postgresql
before_install:
- test/travis_before_install.sh
install:
- pip install -r backend/requirements.txt
- pip install coverage coveralls
script:
- test/travis_script.sh
addons:
postgresql: "10"
apt:
packages:
- postgresql-10
- postgresql-client-10
env:
global:
- PGPORT=5433
2 changes: 1 addition & 1 deletion backend/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def tearDown(self):
try:
u = db.User.select(db.User).where(db.User.email==self.USER).get()
try:
u.access.get().delete_instance()
u.dataset_access.get().delete_instance()
except peewee.PeeweeException:
pass
try:
Expand Down
16 changes: 11 additions & 5 deletions settings_sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@
"googleSecret" : "a secret from google",
"redirectUri" : "https://google oauth redirect uri",

"postgresHost": "postgres host",
"postgresPort": 5432,
"postgresUser": "postgres",
"postgresPass": "",
"postgresName": "",
"mysqlHost" : "127.0.0.1",
"mysqlPasswd" : "password",
"mysqlSchema" : "swefreq",
"mysqlUser" : "swefreq",
"mysqlPort" : 3306,

"postgresHost" : "postgres host",
"postgresPort" : 5432,
"postgresUser" : "postgres",
"postgresPass" : "",
"postgresName" : "",

"mongoHost" : "mongodb host",
"mongoPassword" : "password",
Expand Down
13 changes: 7 additions & 6 deletions test/travis_before_install.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/usr/bin/env bash
set -x

docker pull mysql:5.7
docker pull ubuntu:16.04
PSQL_VERSION="10"
UBUNTU_VERSION="18.04"
PSQL_PORT="5433"

VOLUME='mysql-data-volume'
MYSQL_PORT=3366
docker pull postgres:"${PSQL_VERSION}"
docker pull ubuntu:"${UBUNTU_VERSION}"

scripts/download_and_create_docker_db_volume.sh
docker run -v $VOLUME:/var/lib/mysql --rm --name mysql -d -p $MYSQL_PORT:3306 mysql:5.7
docker run --rm --name swefreq_postgres_${PSQL_VERSION} \
-d -p $PSQL_PORT:5432 postgres:"${PSQL_VERSION}"
26 changes: 13 additions & 13 deletions test/travis_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ set -xe

## SETUP SETTINGS
cp settings_sample.json settings.json
sed -i 's/password//' settings.json
sed -i 's/"mysqlSchema" : "swefreq"/"mysqlSchema" : "swefreq_test"/' settings.json
sed -i 's/"mysqlPort" : 3306/"mysqlPort" : 3366/' settings.json
sed -i.tmp 's/"postgresHost" : "postgres host"/"postgresHost" : "127.0.0.1"/' settings.json
sed -i.tmp 's/"postgresPort" : 5432/"postgresPort" : 5433/' settings.json

echo "SETTINGS"
cat settings.json
Expand All @@ -14,21 +13,22 @@ echo "/SETTINGS"
echo ">>> Test 1. The SQL Patch"

LATEST_RELEASE=$(git tag | grep '^v' | sort -V | tail -n 1)
git show ${LATEST_RELEASE}:sql/swefreq.sql > master-schema.sql
git show ${LATEST_RELEASE}:sql/*_schema.sql > master-schema.sql

psql -U postgres -h 127.0.0.1 -p 5433 -f master-schema.sql
psql -U postgres -h 127.0.0.1 -p 5433 -f sql/patch-master-db.sql

mysql -u swefreq -h 127.0.0.1 -P 3366 swefreq_test < master-schema.sql
mysql -u swefreq -h 127.0.0.1 -P 3366 swefreq_test < sql/patch-master-db.sql
# Empty the database
mysql -u swefreq -h 127.0.0.1 -P 3366 swefreq_test <<__END__
DROP DATABASE swefreq_test;
CREATE DATABASE swefreq_test;
psql -U postgres -h 127.0.0.1 -p 5433 <<__END__
DROP SCHEMA data;
DROP SCHEMA users;
__END__


echo ">>> Test 2. Load the swefreq schema"
mysql -u swefreq -h 127.0.0.1 -P 3366 swefreq_test < sql/swefreq.sql
mysql -u swefreq -h 127.0.0.1 -P 3366 swefreq_test < test/data/load_dummy_data.sql

psql -U postgres -h 127.0.0.1 -p 5433 -f sql/data_schema.sql
psql -U postgres -h 127.0.0.1 -p 5433 -f sql/user_schema.sql
psql -U postgres -h 127.0.0.1 -p 5433 -f test/data/load_dummy_data.sql

echo ">>> Test 3. Check that the backend starts"

Expand All @@ -44,7 +44,7 @@ sleep 2 # Lets wait a little bit so the server has started
exit_handler() {
rv=$?
# Ignore errors in the exit handler
set +e
set +e
# We want to make sure the background process has stopped, otherwise the
# travis test will stall for a long time.
kill -9 $BACKEND_PID
Expand Down

0 comments on commit aad4484

Please sign in to comment.