2013-04-01 23:02:24 +02:00
|
|
|
#!/bin/bash -e
|
|
|
|
|
|
|
|
function migration_status {
|
|
|
|
./manage.py migrate --list | sed 's/*/ /' > "$1"
|
|
|
|
}
|
2013-03-05 23:08:55 +01:00
|
|
|
|
2013-05-08 05:30:42 +02:00
|
|
|
template_grep_error_code=$(echo "SELECT 1 from pg_database WHERE datname='humbug_test_template';" | python manage.py dbshell --settings=humbug.test_settings | grep -q "1 row"; echo $?)
|
|
|
|
|
|
|
|
if [ $template_grep_error_code == "0" ]; then
|
2013-04-01 23:02:24 +02:00
|
|
|
migration_status zephyr/fixtures/available-migrations
|
|
|
|
if [ -e zephyr/fixtures/migration-status ] &&
|
|
|
|
cmp -s zephyr/fixtures/available-migrations zephyr/fixtures/migration-status &&
|
|
|
|
[ "$1" != "--force" ]; then
|
2013-05-08 05:30:42 +02:00
|
|
|
psql -h localhost postgres humbug_test << EOF
|
|
|
|
DROP DATABASE humbug_test;
|
|
|
|
CREATE DATABASE humbug_test TEMPLATE humbug_test_template;
|
|
|
|
EOF
|
2013-03-05 23:08:55 +01:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2012-09-04 22:31:56 +02:00
|
|
|
mkdir -p zephyr/fixtures
|
2013-01-10 22:58:01 +01:00
|
|
|
|
|
|
|
# Remove time.pyc to try to prevent it from screwing people importing
|
|
|
|
# time from inside zephyr.lib. We can drop this hack after a bit.
|
|
|
|
rm -f zephyr/lib/time.pyc
|
|
|
|
|
2013-05-08 05:30:42 +02:00
|
|
|
|
|
|
|
echo "DROP SCHEMA humbug CASCADE; CREATE SCHEMA humbug;" | python manage.py dbshell --settings=humbug.test_settings
|
2012-10-11 00:10:48 +02:00
|
|
|
python manage.py syncdb --noinput --settings=humbug.test_settings
|
2013-01-09 18:16:07 +01:00
|
|
|
python manage.py migrate --settings=humbug.test_settings --all
|
2013-04-01 23:02:24 +02:00
|
|
|
migration_status "zephyr/fixtures/migration-status"
|
|
|
|
|
2013-01-08 21:59:52 +01:00
|
|
|
# This next line can be simplified to "-n0" once we fix our app with 0 messages.
|
|
|
|
python manage.py populate_db --settings=humbug.test_settings --test-suite -n2 \
|
|
|
|
--threads=1 --huddles=0 --personals=0 --percent-huddles=0 --percent-personals=0
|
2013-06-12 17:39:10 +02:00
|
|
|
# Ensure that the local user's API key is synced from ~/.humbugrc
|
|
|
|
python manage.py sync_api_key
|
2012-10-25 06:11:28 +02:00
|
|
|
python manage.py dumpdata --settings=humbug.test_settings \
|
2013-04-04 19:02:47 +02:00
|
|
|
zephyr.UserProfile zephyr.Stream zephyr.Recipient \
|
2012-10-25 06:11:28 +02:00
|
|
|
zephyr.Subscription zephyr.Message zephyr.Huddle zephyr.Realm \
|
2012-11-27 18:26:51 +01:00
|
|
|
zephyr.UserMessage zephyr.Client \
|
|
|
|
zephyr.DefaultStream > zephyr/fixtures/messages.json
|
2013-03-05 23:08:55 +01:00
|
|
|
|
2013-05-08 05:30:42 +02:00
|
|
|
# create pristine template database, for fast fixture restoration after tests are run.
|
|
|
|
psql -h localhost postgres humbug_test << EOF
|
|
|
|
DROP DATABASE humbug_test_template;
|
|
|
|
CREATE DATABASE humbug_test_template TEMPLATE humbug_test;
|
|
|
|
EOF
|