Commit 04222ab7 authored by Brian Moe's avatar Brian Moe
Browse files

Fixed typos. Added cli tests and more unit tests.

parent 55259bd3
......@@ -302,7 +302,7 @@ class Client:
headers = {'connection' : 'keep-alive'}
headers = {}
# If absolute URL, use, otherwise pre-append the REST service URL.
if self._is_absoute_url(resource):
if self._is_absolute_url(resource):
url = resource
else:
url = "%s%s" % (self.rest_url, resource)
......
......@@ -23,7 +23,7 @@ import os
import sys
import json
DEFAULT_SERVICE_URL = "https://gracedb.ligo.org/api"
DEFAULT_SERVICE_URL = "https://gracedb.ligo.org/api/"
#-----------------------------------------------------------------
# Exception(s)
......
......@@ -5,6 +5,36 @@ import os
from ligo.gracedb.rest import GraceDb, HTTPError
# Test the GraceDb REST API class.
#
# To run:
#
# python $PATH_TO_GRACEDB_LIB/test/test.py
#
# Environment Variables:
#
# TEST_SERVICE
# defaults to https://moe.phys.uwm.edu/gracedb/api/
# live site would be https://gracedb.ligo.org/api/
#
# TEST_DATA_DIR
# defaults to $PATH_TO_GRACEDB_LIB/test/data/
#
# Files expected:
#
# burst-cwb.txt
# cbc-lm2.xml
# cbc-lm.xml
# cbc-mbta.gwf
# upload2.data
# upload.data
#
# X509_USER_PROXY
#
# X509_USER_CERT
# X509_USER_KEY
TEST_SERVICE = "https://moe.phys.uwm.edu/gracedb/api/"
class TestGracedb(unittest.TestCase):
......@@ -171,6 +201,9 @@ if __name__ == "__main__":
testdatadir = os.path.join(os.path.dirname(__file__), "data")
service = os.environ.get('TEST_SERVICE', TEST_SERVICE)
testdatadir = os.environ.get('TEST_DATA_DIR', testdatadir)
gracedb = GraceDb(TEST_SERVICE)
eventFile = os.path.join(testdatadir, "cbc-lm.xml")
......
#!/bin/bash
# Test the gracedb command line client
#
: ${GRACEDB:="gracedb"}
: ${DATADIR:=$(dirname $0)/data}
: ${GRACEDB_SERVICE_URL:="https://moe.phys.uwm.edu/gracedb/cli"}
export GRACEDB_SERVICE_URL
N=0
NSUCC=0
NFAIL=0
NERR=0
function recordTest() {
TESTNAME=$1
RETCODE=$2
OUT="$3"
case $RETCODE in
0) NSUCC=$[$NSUCC+1]
MESSAGE="Succeeded"
;;
1) NFAIL=$[$NFAIL+1]
MESSAGE="Failed $OUT"
;;
*) NERR=$[$NERR+1]
MESSAGE="Error $OUT"
;;
esac
N=$[$N+1]
echo $TESTNAME $MESSAGE
}
function showStats() {
echo "Success: " $NSUCC
echo "Fail: " $NFAIL
echo "Error: " $NERR
echo "Total: " $N
}
OUT="$(${GRACEDB} ping 2>&1)"
recordTest "ping" "$?" "$OUT"
# Try creating events of various types
#
OUT="$(${GRACEDB} Test LowMass $DATADIR/cbc-lm.xml 2>&1)"
RETCODE=$?
recordTest "create LowMass" "$RETCODE" "$OUT"
# Remember the LM event. We will use it later
#
if [ $RETCODE -eq 0 ]
then
GRACEID=$OUT
else
GRACEID="NOID"
fi
OUTFILE=$(mktemp)
${GRACEDB} Test MBTAOnline $DATADIR/cbc-mbta.gwf >$OUTFILE 2>&1
recordTest "create MBTA" "$?" "$(cat $OUTFILE)"
rm $OUTFILE
OUTFILE=$(mktemp)
${GRACEDB} Test CWB $DATADIR/burst-cwb.txt >$OUTFILE 2>&1
recordTest "create CWB" "$?" "$(cat $OUTFILE)"
rm $OUTFILE
# Try a simple search
#
OUTFILE=$(mktemp)
${GRACEDB} search $GRACEID >$OUTFILE 2>&1
recordTest "search $GRACEID" "$?" "$(cat $OUTFILE)"
rm $OUTFILE
# Make sure FAR of created LM event is correct.
#
OUTFILE=$(mktemp)
${GRACEDB} search "--columns=gpstime" $GRACEID > $OUTFILE 2>&1
RETCODE=$?
if [ $RETCODE == 0 ]
then
if [ $(grep -v '#' <$OUTFILE) == 971609248 ]
then
RETCODE=0
else
RETCODE=1
fi
fi
recordTest "verify GPS time $GRACEID" "$RETCODE" "$(cat $OUTFILE)"
rm $OUTFILE
# Replace LM event with new data
#
OUTFILE=$(mktemp)
${GRACEDB} replace $GRACEID $DATADIR/cbc-lm2.xml >$OUTFILE 2>&1
RETCODE=$?
recordTest "replace $GRACEID" "$RETCODE" "$(cat $OUTFILE)"
rm $OUTFILE
# Make sure FAR of replaced LM event is correct.
#
OUTFILE=$(mktemp)
${GRACEDB} search "--columns=gpstime" $GRACEID > $OUTFILE 2>&1
RETCODE=$?
if [ $RETCODE == 0 ]
then
if [ $(grep -v '#' <$OUTFILE) == 971609249 ]
then
RETCODE=0
else
RETCODE=1
fi
fi
recordTest "verify new GPS time $GRACEID" "$RETCODE" "$(cat $OUTFILE)"
rm $OUTFILE
# Upload a file
#
OUTFILE=$(mktemp)
${GRACEDB} upload $GRACEID "$DATADIR/upload.data" > $OUTFILE 2>&1
recordTest "upload file $GRACEID" "$?" "$(cat $OUTFILE)"
rm $OUTFILE
# Download that uploaded file
#
DOWNLOAD=$(mktemp)
${GRACEDB} download $GRACEID "upload.data" - > $DOWNLOAD 2>&1
recordTest "download file" "$?" "$(cat $DOWNLOAD)"
# Verify that the uploaded file and downloaded file were the same
#
cmp --silent "$DOWNLOAD" "$DATADIR/upload.data"
recordTest "verify uploaded file" "$?" "$(cat $DOWNLOAD)"
rm $DOWNLOAD
# Log
#
OUTFILE=$(mktemp)
${GRACEDB} log $GRACEID "test the" "logging" > $OUTFILE 2>&1
recordTest "log message" "$?" "$(cat $OUTFILE)"
rm $OUTFILE
# Label
#
OUTFILE=$(mktemp)
${GRACEDB} label $GRACEID DQV > $OUTFILE 2>&1
recordTest "label $GRACEID" "$?" "$(cat $OUTFILE)"
rm $OUTFILE
# Verify labelling
#
OUTFILE=$(mktemp)
${GRACEDB} search $GRACEID |grep DQV > $OUTFILE 2>&1
recordTest "verify label" "$?" "$(cat $OUTFILE)"
rm $OUTFILE
showStats
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment