Commit b47655ef authored by Tanner Prestegard's avatar Tanner Prestegard

Merge branch 'offline_param' into 'master'

Introduction of 'offline' parameter

See merge request !16
parents 91485612 e5a27180
......@@ -535,19 +535,20 @@ class GraceDb(GsiRest):
# Search and filecontents are optional when creating an event.
def createEvent(self, group, pipeline, filename, search=None, labels=[],
filecontents=None, **kwargs):
offline=False, filecontents=None, **kwargs):
"""Create a new GraceDB event
Required args: group, pipeline, filename
Optional args: search, labels, filecontents
Optional args: search, labels, offline, filecontents
The filename is the path to a file containing information about the
event. The values for 'group', 'pipeline', and 'search' are restricted
to those stored in the database. 'labels' should be a list of strings
corresponding to labels (values restricted to those stored in the
database). 'labels' can be a string if only a single label is
being applied.
being applied. 'offline' is a boolean which indicates whether the
analysis is offline (True) or online/low-latency (False).
Example:
......@@ -565,6 +566,9 @@ class GraceDb(GsiRest):
errors += ["bad pipeline"]
if search and search not in self.searches:
errors += ["bad search"]
# Process offline arg
if not isinstance(offline, bool):
errors += ["offline should be True or False"]
# Process label args
if isinstance(labels, str):
# Convert to list
......@@ -599,6 +603,7 @@ class GraceDb(GsiRest):
('group', group),
('pipeline', pipeline),
('labels', label_str),
('offline', offline),
]
if search:
fields.append(('search', search))
......
......@@ -316,6 +316,18 @@ class TestGracedb(unittest.TestCase):
r = gracedb.writeFile(eventId, uploadFile)
self.assertEqual(r.status, 201) # CREATED
def test_offline_param(self):
"""
Tests whether offline parameter is transmitted to database
properly or not. Creates an event with offline=True and checks it;
also checks createdEvent, which uses offline=False.
"""
self.assertEqual(createdEvent['offline'], offline)
r = gracedb.createEvent("Test", "gstlal", eventFile,
search="LowMass",offline=True)
temp = r.json()
self.assertEqual(temp['offline'], True)
def test_logger(self):
import logging
import ligo.gracedb.rest
......@@ -388,7 +400,7 @@ class TestGracedb(unittest.TestCase):
if __name__ == "__main__":
global gracedb, testdatadir, createdEvent, eventId, labelName
global gracedb, testdatadir, createdEvent, eventId, labelName, offline
# Hacky "global" fixture.
# Do not want to create a million events
......@@ -402,12 +414,13 @@ if __name__ == "__main__":
gracedb = GraceDb(service)
labelName = "DQV"
offline = False
#gracedb = GraceDbBasic(service)
print("Using service", service)
eventFile = os.path.join(testdatadir, "cbc-lm.xml")
createdEvent = gracedb.createEvent(
"Test", "gstlal", eventFile, "LowMass").json()
createdEvent = gracedb.createEvent("Test", "gstlal", eventFile,
"LowMass", offline=offline).json()
eventId = createdEvent["graceid"]
unittest.main()
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