1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-31 06:34:40 +00:00
Files
seahub/tests/seahubtests.sh

87 lines
2.4 KiB
Bash
Raw Normal View History

2014-08-18 16:04:23 +08:00
#!/bin/bash
2014-08-27 11:08:39 +08:00
: ${PYTHON=python}
2014-09-06 11:38:20 +08: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 16:43:47 +08: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 17:46:48 +08:00
if [[ ${TRAVIS} != "" ]]; then
set -x
fi
2014-08-19 16:43:47 +08:00
SCRIPT=$(readlink -f "$0")
SEAHUB_TESTSDIR=$(dirname "${SCRIPT}")
SEAHUB_SRCDIR=$(dirname "${SEAHUB_TESTSDIR}")
2014-09-06 11:53:46 +08:00
local_settings_py=${SEAHUB_SRCDIR}/seahub/local_settings.py
2014-08-19 16:43:47 +08:00
export PYTHONPATH="/usr/local/lib/python2.7/site-packages:/usr/lib/python2.7/site-packages:${SEAHUB_SRCDIR}/thirdpart:${PYTHONPATH}"
cd "$SEAHUB_SRCDIR"
2014-08-18 16:04:23 +08:00
function init() {
2014-08-19 16:43:47 +08:00
###############################
# create database and two new users: an admin, and a normal user
2014-08-19 16:43:47 +08:00
###############################
2014-08-27 11:08:39 +08:00
$PYTHON ./manage.py syncdb
# create normal user
2014-09-06 11:38:20 +08: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 11:38:20 +08: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 11:53:46 +08:00
# overwrite api throttling settings in settings.py
echo "REST_FRAMEWORK = {}" >> "${local_settings_py}"
2014-08-19 16:43:47 +08:00
}
2014-08-18 16:04:23 +08:00
2014-08-19 16:43:47 +08:00
function start_seahub() {
2014-09-06 12:37:52 +08:00
$PYTHON ./manage.py runserver 1>/tmp/seahub.access.log 2>&1 &
2014-08-27 11:08:39 +08:00
sleep 5
2014-08-18 16:04:23 +08:00
}
2014-08-19 16:43:47 +08:00
2014-08-19 16:56:40 +08:00
function run_tests() {
2014-09-06 12:37:52 +08:00
set +e
cd tests
nosetests $nose_opts
rvalue=$?
cd -
if [[ ${TRAVIS} != "" ]]; then
# On travis-ci, dump seahub logs when test finished
for logfile in /tmp/seahub*.log; do
echo -e "\nLog file $logfile:\n"
cat "${logfile}"
echo
done
fi
exit $rvalue
2014-08-18 16:04:23 +08:00
}
case $1 in
"init")
init
;;
2014-08-19 17:01:31 +08:00
"runserver")
2014-08-19 16:43:47 +08:00
start_seahub
2014-08-19 17:01:31 +08:00
;;
"test")
2014-09-06 11:38:20 +08:00
shift
2014-09-06 12:37:52 +08:00
nose_opts=$*
2014-08-19 16:56:40 +08:00
run_tests
2014-08-18 16:04:23 +08:00
;;
*)
2014-08-19 16:43:47 +08:00
echo "unknow command \"$1\""
2014-08-18 16:04:23 +08:00
;;
esac