Commit 6f1a8fec authored by Branson Stephens's avatar Branson Stephens

Fixed some bugs resulting from the merger.

parent 0174775a
This diff is collapsed.
# -*- coding: utf-8 -*-
# Copyright (C) Brian Moe, Branson Stephens (2015)
#
# This file is part of gracedb
#
# gracedb is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# It is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with gracedb. If not, see <http://www.gnu.org/licenses/>.
import unittest
import random
import os
from datetime import datetime
import time
from ligo.gracedb.rest import GraceDb, GraceDbBasic
......@@ -36,8 +55,9 @@ from ligo.gracedb.rest import GraceDb, GraceDbBasic
# X509_USER_KEY
TEST_SERVICE = "https://moe.phys.uwm.edu/branson/apiweb/"
TEST_SP_SESSION_ENDPOINT = "https://moe.phys.uwm.edu/Shibboleth.sso/Session"
TEST_SERVICE = "https://gracedb-test.ligo.org/apiweb/"
TEST_SP_SESSION_ENDPOINT = "https://gracedb-test.ligo.org/Shibboleth.sso/Session"
SLEEP_TIME = 1
class TestGracedb(unittest.TestCase):
"""
......@@ -81,22 +101,31 @@ class TestGracedb(unittest.TestCase):
self.assertTrue('numRows' in logs)
pass
def test_create_embb_log(self):
"""Create an EMBB log entry."""
def test_create_emobservation(self):
"""Create an EM observation entry."""
comment = "Message is {0}".format(random.random())
resp = gracedb.writeEel(eventId, 'Test', 'em.gamma',
'FO', 'TE', comment=comment, instrument='Test')
# Let's put in some made-up values
raList = [1.0,1.0,1.0]
raWidthList = 1.0
decList = [1.0,1.0,1.0]
decWidthList = 1.0
dt = datetime(1900,1,1,1,1,1)
startTimeList = [dt.isoformat() for i in range(3)]
durationList = 1.0
resp = gracedb.writeEMObservation(eventId, 'Test',
raList, raWidthList, decList, decWidthList,
startTimeList, durationList, comment)
self.assertEqual(resp.status, 201)
new_embb_log_uri = resp.info().getheader('Location')
new_embb_log = resp.json()
self.assertEqual(new_embb_log_uri, new_embb_log['self'])
check_new_embb_log = gracedb.get(new_embb_log_uri).json()
self.assertEqual(check_new_embb_log['comment'], comment)
new_emobservation_uri = resp.info().getheader('Location')
new_emobservation = resp.json()
self.assertEqual(new_emobservation_uri, new_emobservation['self'])
check_new_emobservation = gracedb.get(new_emobservation_uri).json()
self.assertEqual(check_new_emobservation['comment'], comment)
def test_get_embb_log(self):
"""Retrieve EMBB event log"""
eels = gracedb.eels(eventId).json()
self.assertTrue('numRows' in eels)
def test_get_emobservations(self):
"""Retrieve EM Observation List"""
emos = gracedb.emobservations(eventId).json()
self.assertTrue('numRows' in emos)
def test_upload_large_file(self):
"""Upload a large file. Issue https://bugs.ligo.org/redmine/issues/951"""
......@@ -176,13 +205,14 @@ class TestGracedb(unittest.TestCase):
def test_create_cwb(self):
"""Create a CWB event"""
"""burst-cwb.txt"""
time.sleep(SLEEP_TIME)
eventFile = os.path.join(testdatadir, "burst-cwb.txt")
r = gracedb.createEvent("Test", "CWB", eventFile)
self.assertEqual(r.status, 201) # CREATED
cwb_event = r.json()
self.assertEqual(cwb_event['group'], "Test")
self.assertEqual(cwb_event['pipeline'], "CWB")
self.assertEqual(cwb_event['gpstime'], 1042312876)
self.assertEqual(float(cwb_event['gpstime']), 1042312876.5090)
def test_create_lowmass(self):
"""Create a Low Mass event"""
......@@ -193,21 +223,36 @@ class TestGracedb(unittest.TestCase):
def test_create_mbta(self):
"""Create an MBTA event"""
"""cbc-mbta.xml"""
time.sleep(SLEEP_TIME)
eventFile = os.path.join(testdatadir, "cbc-mbta.xml")
mbta_event = gracedb.createEvent(
"Test", "MBTAOnline", eventFile).json()
self.assertEqual(mbta_event['group'], "Test")
self.assertEqual(mbta_event['pipeline'], "MBTAOnline")
self.assertEqual(mbta_event['gpstime'], 1078903329)
self.assertEqual(float(mbta_event['gpstime']), 1078903329.421037)
self.assertEqual(mbta_event['far'], 4.006953918826065e-7)
def test_create_hardwareinjection(self):
"""Create a HardwareInjection event"""
"""sim-inj.xml"""
time.sleep(SLEEP_TIME)
eventFile = os.path.join(testdatadir, "sim-inj.xml")
hardwareinjection_event = gracedb.createEvent(
"Test", "HardwareInjection", eventFile,
instrument="H1", source_channel="",
destination_channel="").json()
self.assertEqual(hardwareinjection_event['group'], "Test")
self.assertEqual(hardwareinjection_event['pipeline'], "HardwareInjection")
self.assertEqual(hardwareinjection_event['instruments'], "H1")
def test_replace_event(self):
time.sleep(SLEEP_TIME)
graceid = eventId
old_event = gracedb.event(graceid).json()
self.assertEqual(old_event['group'], "Test")
self.assertEqual(old_event['search'], "LowMass")
self.assertEqual(old_event['gpstime'], 971609248)
self.assertEqual(float(old_event['gpstime']), 971609248.151741)
replacementFile = os.path.join(testdatadir, "cbc-lm2.xml")
......@@ -217,7 +262,7 @@ class TestGracedb(unittest.TestCase):
new_event = gracedb.event(graceid).json()
self.assertEqual(new_event['group'], "Test")
self.assertEqual(new_event['search'], "LowMass")
self.assertEqual(new_event['gpstime'], 971609249)
self.assertEqual(float(new_event['gpstime']), 971609249.151741)
def test_upload_binary(self):
"""
......@@ -271,7 +316,7 @@ class TestGracedb(unittest.TestCase):
def test_gittag(self):
# try to make sure GIT_TAG is set properly.
import errno
version = "1.17"
version = "1.20"
try:
# If we are in the source dir (setup.py is available)
# make sure the version above agrees.
......
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