forked from victims/victims-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#! /usr/bin/env bash | ||
|
||
function usage() | ||
{ | ||
echo "USAGE: $0 <start|stop|restart]>" | ||
exit 1 | ||
} | ||
|
||
if [ $# -ne 1 ]; then | ||
usage | ||
fi | ||
ARG=$1 | ||
|
||
BASE=$(dirname $(dirname $0)) | ||
TEST_DBPATH=$BASE/testdb | ||
LOGFILE=$TEST_DBPATH/victims.mongo.log | ||
LOCKFILE="${TEST_DBPATH}/mongod.lock" | ||
|
||
function start() | ||
{ | ||
if [ ! -f "${LOCKFILE}" ]; then | ||
if [ ! -d "${TEST_DBPATH}" ]; then | ||
mkdir -p "${TEST_DBPATH}" | ||
NEW="new" | ||
fi | ||
nohup mongod --logpath "${LOGFILE}" --dbpath "${TEST_DBPATH}" >> /dev/null 2>&1 & | ||
echo "Waiting for mongodb to be ready..." | ||
sleep 1 | ||
while true; do | ||
match=$(grep -m 1 "waiting for connections on port" "${LOGFILE}") | ||
if [ ! -z "$match" ]; then | ||
if [ ! -z $NEW ]; then | ||
mongoimport -d victims -c hashes "$BASE/test/mongo_test.json" | ||
fi | ||
break; | ||
else | ||
match=$(grep -m 1 "dbexit" "${LOGFILE}") | ||
if [ ! -z "$match" ]; then | ||
echo "ERROR starting database" | ||
if [ ! -z $NEW ]; then | ||
cat ${LOGFILE} | ||
rm -rf ${TEST_DBPATH} | ||
fi | ||
break; | ||
else | ||
sleep 2 | ||
fi | ||
fi | ||
done | ||
echo "Data: ${TEST_DBPATH}, Log: ${LOGFILE}" | ||
else | ||
echo "Datase already running" | ||
fi | ||
} | ||
|
||
function stop() | ||
{ | ||
mongod --shutdown --dbpath "${TEST_DBPATH}" | ||
rm -f "${LOCKFILE}" | ||
} | ||
|
||
case "$ARG" in | ||
"start" ) | ||
start ;; | ||
"stop" ) | ||
stop ;; | ||
"restart" ) | ||
stop; start ;; | ||
* ) | ||
echo "Invalid argument."; usage ;; | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#! /usr/bin/env bash | ||
# to be run in the dev environment | ||
|
||
SCRIPT_DIR=$(dirname $0) | ||
|
||
MONGOSH="$SCRIPT_DIR/mongo-db-ctl.sh" | ||
# gracefully start db | ||
bash "$MONGOSH" start | ||
|
||
# execute tests | ||
BASE=$(dirname "$SCRIPT_DIR") | ||
python /usr/bin/nosetests --with-coverage --cover-package=victims_web --cover-min-percentage=0 -v ${BASE}/test/*.py | ||
|
||
# stop db | ||
bash "$MONGOSH" stop | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Usage: source <script> | ||
# Switch to dev environment | ||
# Sets up the development environment if it does not exist | ||
|
||
ENV_PREFIX=victims | ||
ENV_PYTHON=python | ||
ENV_DIR=${ENV_PREFIX}.dev | ||
ENV_PROMPT=${ENV_PREFIX}.dev | ||
|
||
# We know pip is installed, so use it | ||
CMD="pip install" | ||
|
||
function initialize { | ||
$CMD "$(pwd)" | ||
$CMD coverage nose pep8 --use-mirrors | ||
$CMD -e . --use-mirrors | ||
} | ||
|
||
function vitualize { | ||
if [ ! -d "$ENV_DIR" ]; then | ||
virtualenv -p $(which ${ENV_PYTHON}) --prompt=${ENV_PROMPT} ${ENV_DIR} | ||
source ${ENV_DIR}/bin/activate | ||
initialize | ||
else | ||
source ${ENV_DIR}/bin/activate | ||
fi | ||
|
||
} | ||
|
||
|
||
# We require virtuaenv and (easy_install/pip) to be installed | ||
{ command -v virtualenv >/dev/null 2>&1 && vitualize; } || { echo >&2 "ERROR: virtualenv command not found, not switching"; } | ||
|