zulip/zephyr/tests/generate-fixtures

50 lines
2.0 KiB
Plaintext
Raw Normal View History

#!/bin/bash -e
function migration_status {
./manage.py migrate --list | sed 's/*/ /' > "$1"
}
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
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
psql -h localhost postgres humbug_test << EOF
DROP DATABASE humbug_test;
CREATE DATABASE humbug_test TEMPLATE humbug_test_template;
EOF
exit 0
fi
fi
mkdir -p zephyr/fixtures
# 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
echo "DROP SCHEMA humbug CASCADE; CREATE SCHEMA humbug;" | python manage.py dbshell --settings=humbug.test_settings
python manage.py syncdb --noinput --settings=humbug.test_settings
python manage.py migrate --settings=humbug.test_settings --all
migration_status "zephyr/fixtures/migration-status"
# 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
# Ensure that the local user's API key is synced from ~/.humbugrc
python manage.py sync_api_key
python manage.py dumpdata --settings=humbug.test_settings \
zephyr.UserProfile zephyr.Stream zephyr.Recipient \
zephyr.Subscription zephyr.Message zephyr.Huddle zephyr.Realm \
zephyr.UserMessage zephyr.Client \
zephyr.DefaultStream > zephyr/fixtures/messages.json
# 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