1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-07-01 01:12:41 +00:00
seahub/tests/seahubtests.sh

108 lines
3.2 KiB
Bash
Raw Normal View History

2014-08-18 08:04:23 +00:00
#!/bin/bash
2014-08-27 03:08:39 +00:00
: ${PYTHON=python}
2014-09-06 03:38:20 +00:00
: ${SEAHUB_TEST_USERNAME="test@seafiletest.com"}
: ${SEAHUB_TEST_PASSWORD="testtest"}
: ${SEAHUB_TEST_ADMIN_USERNAME="admin@seafiletest.com"}
: ${SEAHUB_TEST_ADMIN_PASSWORD="adminadmin"}
export SEAHUB_TEST_USERNAME
export SEAHUB_TEST_PASSWORD
export SEAHUB_TEST_ADMIN_USERNAME
export SEAHUB_TEST_ADMIN_PASSWORD
2014-08-19 08:43:47 +00:00
# If you run this script on your local machine, you must set CCNET_CONF_DIR
# and SEAFILE_CONF_DIR like this:
#
# export CCNET_CONF_DIR=/your/path/to/ccnet
# export SEAFILE_CONF_DIR=/your/path/to/seafile-data
#
set -e
2014-08-19 09:46:48 +00:00
if [[ ${TRAVIS} != "" ]]; then
set -x
fi
2014-08-19 08:43:47 +00:00
set -x
SEAHUB_TESTSDIR=$(python -c "import os; print os.path.dirname(os.path.realpath('$0'))")
2014-08-19 08:43:47 +00:00
SEAHUB_SRCDIR=$(dirname "${SEAHUB_TESTSDIR}")
2014-09-06 03:53:46 +00:00
local_settings_py=${SEAHUB_SRCDIR}/seahub/local_settings.py
2014-08-19 08:43:47 +00:00
export PYTHONPATH="/usr/local/lib/python2.7/site-packages:/usr/lib/python2.7/site-packages:${SEAHUB_SRCDIR}/thirdpart:${PYTHONPATH}"
cd "$SEAHUB_SRCDIR"
set +x
2014-08-19 08:43:47 +00:00
2014-08-18 08:04:23 +00:00
function init() {
2014-08-19 08:43:47 +00:00
###############################
# create database and two new users: an admin, and a normal user
2014-08-19 08:43:47 +00:00
###############################
$PYTHON ./manage.py migrate --noinput
# create normal user
2014-09-06 03:38:20 +00:00
$PYTHON -c "import ccnet; pool = ccnet.ClientPool('${CCNET_CONF_DIR}'); ccnet_threaded_rpc = ccnet.CcnetThreadedRpcClient(pool, req_pool=True); ccnet_threaded_rpc.add_emailuser('${SEAHUB_TEST_USERNAME}', '${SEAHUB_TEST_PASSWORD}', 0, 1);"
# create admin
2014-09-06 03:38:20 +00:00
$PYTHON -c "import ccnet; pool = ccnet.ClientPool('${CCNET_CONF_DIR}'); ccnet_threaded_rpc = ccnet.CcnetThreadedRpcClient(pool, req_pool=True); ccnet_threaded_rpc.add_emailuser('${SEAHUB_TEST_ADMIN_USERNAME}', '${SEAHUB_TEST_ADMIN_PASSWORD}', 1, 1);"
2014-09-06 03:53:46 +00:00
2015-01-06 07:31:41 +00:00
# enlarge anon api throttling settings in settings.py, this is a workaround
# to make tests pass, otherwise a few tests will be throttlled.
# TODO: cache api token.
echo "REST_FRAMEWORK = {'DEFAULT_THROTTLE_RATES': {'ping': '600/minute', 'anon': '5000/minute', 'user': '300/minute',},}" >> "${local_settings_py}"
2014-08-19 08:43:47 +00:00
}
2014-08-18 08:04:23 +00:00
2014-08-19 08:43:47 +00:00
function start_seahub() {
2014-09-06 04:37:52 +00:00
$PYTHON ./manage.py runserver 1>/tmp/seahub.access.log 2>&1 &
2014-08-27 03:08:39 +00:00
sleep 5
2014-08-18 08:04:23 +00:00
}
2014-08-19 08:43:47 +00:00
function make_dist() {
echo "Making dist files ..."
make dist
}
2015-05-04 07:01:08 +00:00
function check_phantom_js() {
if ! which phantomjs >/dev/null; then
echo "Please install phantojs first:"
echo
echo " On ubuntu: sudo apt-get install phantomjs"
echo " On MacOSX: Download the binary from http://phantomjs.org/download.html"
exit 1
fi
}
2014-08-19 08:56:40 +00:00
function run_tests() {
2015-05-04 07:01:08 +00:00
check_phantom_js
2014-09-06 04:37:52 +00:00
set +e
2015-05-15 03:23:56 +00:00
py.test $nose_opts tests
2014-09-06 04:37:52 +00:00
rvalue=$?
if [[ ${TRAVIS} != "" ]]; then
# On travis-ci, dump seahub logs when test finished
for logfile in /tmp/ccnet/*.log /tmp/seafile-data/*.log /tmp/seahub*.log; do
2014-09-06 04:37:52 +00:00
echo -e "\nLog file $logfile:\n"
cat "${logfile}"
echo
done
fi
exit $rvalue
2014-08-18 08:04:23 +00:00
}
case $1 in
"init")
init
;;
2014-08-19 09:01:31 +00:00
"runserver")
2014-08-19 08:43:47 +00:00
start_seahub
2014-08-19 09:01:31 +00:00
;;
"dist")
make_dist
;;
2014-08-19 09:01:31 +00:00
"test")
2014-09-06 03:38:20 +00:00
shift
2014-09-06 04:37:52 +00:00
nose_opts=$*
2014-08-19 08:56:40 +00:00
run_tests
2014-08-18 08:04:23 +00:00
;;
*)
2014-08-19 08:43:47 +00:00
echo "unknow command \"$1\""
2014-08-18 08:04:23 +00:00
;;
esac