Removing VOEvent file text hack

Removing hack which includes the VOEvent file text in the response
for VOEvent gets and creation.  This has been deprecated for a few
months and users have had time to adapt to the necessity of
getting the file content separately.
parent 9fab46cd
......@@ -122,16 +122,6 @@ class ProxyHTTPSConnection(ProxyHTTPConnection):
else:
self.sock = self.context.wrap_socket(self.sock)
# Hacky fake response type for kludging response object
# Has json() and read() methods
class FakeResponse(object):
def __init__(self, json, status, *args, **kwargs):
self._data = json
self.status = status
def json(self): return self._data
def read(self): return json.dumps(self._data)
#-----------------------------------------------------------------
# Generic GSI REST
......@@ -1642,22 +1632,17 @@ class GraceDb(GsiRest):
return self.get(self.links['self'])
@event_or_superevent
def voevents(self, object_id, voevent_num=None, get_voevent_file_text=True,
*args, **kwargs):
def voevents(self, object_id, voevent_num=None, *args, **kwargs):
"""
Get a list of VOEvents or a single VOEvent for an event or superevent.
Signature:
voevents(object_id, voevent_num=None, get_voevent_file_text=True)
voevents(object_id, voevent_num=None)
Arguments:
object_id: event graceid or superevent id
voevent_num: number of VOEvent to retrieve (optional)
get_voevent_file_text is a temporary deprecation measure to provide
the text of the VOEvent file in the output of this function. This
will not be provided in the future.
Example 1: get a list of VOEvents
>>> g = GraceDb()
......@@ -1688,45 +1673,14 @@ class GraceDb(GsiRest):
uri_kwargs['N'] = voevent_num
uri = template.format(**uri_kwargs)
response = self.get(uri)
# Temporary hack to get voevent file text and include it in a
# response-like object for user consumption. Will be removed in a
# future release.
if get_voevent_file_text:
# print a deprecation warning
print("WARNING: the VOEvent file text will not be included in the "
"response JSON in a future release. Users can still get the "
"content of this file by using the files() method along with "
"the filename which is included in the response JSON. You may "
"call this method with the keyword argument "
"get_voevent_file_text=False if you do not need the file "
"content and would like to remove this warning message.")
# Get actual response JSON
r_json = response.json()
if 'voevents' in r_json:
# list of voevents - iterate and get file text
for v in r_json['voevents']:
v[u'text'] = self.files(object_id, v['filename']) \
.read().decode()
else:
file_text = self.files(object_id, r_json['filename']).read()
r_json[u'text'] = file_text.decode()
response = FakeResponse(r_json, response.status)
# Return response
return response
return self.get(uri)
@event_or_superevent
def createVOEvent(self, object_id, voevent_type, skymap_type=None,
skymap_filename=None, skymap_image_filename=None, internal=True,
vetted=False, open_alert=False, hardware_inj=False,
CoincComment=False, ProbHasNS=None, ProbHasRemnant=None,
get_voevent_file_text=True, *args, **kwargs):
# TBD for superevents - requires a lot of changes to server code
*args, **kwargs):
"""Create a new VOEvent
Signature:
......@@ -1808,30 +1762,7 @@ class GraceDb(GsiRest):
if ProbHasRemnant:
body['ProbHasRemnant'] = ProbHasRemnant
response = self.post(uri, body=body)
# Temporary hack to get voevent file text and include it in a
# response-like object for user consumption. Will be removed in a
# future release.
if get_voevent_file_text:
# print a deprecation warning
print("WARNING: the VOEvent file text will not be included in the "
"response JSON in a future release. Users can still get the "
"content of this file by using the files() method along with "
"the filename which is included in the response JSON. You may "
"call this method with the keyword argument "
"get_voevent_file_text=False if you do not need the file "
"content and would like to remove this warning message.")
# Get actual response JSON
r_json = response.json()
# Get file and add text
file_text = self.files(object_id, r_json['filename']).read()
r_json[u'text'] = file_text.decode()
response = FakeResponse(r_json, response.status)
return response
return self.post(uri, body=body)
@event_or_superevent
def permissions(self, object_id, group_name=None, *args, **kwargs):
......
......@@ -44,10 +44,15 @@ class TestVOEvents(TestGraceDb):
filecontents="Fake skymap image.", tagname="sky_loc")
# Helper functions --------------------------------------------------------
def get_citations_dict(self, voevent):
def get_citations_dict(self, graceid, voevent_filename):
"""Gets a dictionary of ivorns and citation types"""
voevent_xml = ET.fromstring(voevent['text'])
# Get voevent file
voevent_file_text = self._gracedb.files(graceid,
voevent_filename).read()
# Parse XML
voevent_xml = ET.fromstring(voevent_file_text)
citations_dict = {}
for citations in voevent_xml.iterfind('Citations'):
for e in citations.iterfind('EventIVORN'):
......@@ -55,9 +60,12 @@ class TestVOEvents(TestGraceDb):
citations_dict[ivorn] = e.attrib['cite']
return citations_dict
def get_ivorn(self, voevent):
def get_ivorn(self, graceid, voevent_filename):
"""Extracts ivorn"""
return ET.fromstring(voevent['text']).get('ivorn')
# Get voevent file
voevent_file_text = self._gracedb.files(graceid,
voevent_filename).read()
return ET.fromstring(voevent_file_text).get('ivorn')
# Tests -------------------------------------------------------------------
def test_create_preliminary_voevent(self):
......@@ -90,8 +98,10 @@ class TestVOEvents(TestGraceDb):
# Make sure the ivorns are different
voevent_dict = {v['voevent_type']: v for v in voevent_list}
preliminary_ivorn = self.get_ivorn(voevent_dict['PR'])
update_ivorn = self.get_ivorn(voevent_dict['UP'])
preliminary_ivorn = self.get_ivorn(self._graceid,
voevent_dict['PR']['filename'])
update_ivorn = self.get_ivorn(self._graceid,
voevent_dict['UP']['filename'])
self.assertNotEqual(preliminary_ivorn, update_ivorn)
def test_citation_section(self):
......@@ -100,8 +110,10 @@ class TestVOEvents(TestGraceDb):
voevent_list = r.json()['voevents']
voevent_dict = {v['voevent_type']: v for v in voevent_list}
preliminary_ivorn = self.get_ivorn(voevent_dict['PR'])
update_citations = self.get_citations_dict(voevent_dict['UP'])
preliminary_ivorn = self.get_ivorn(self._graceid,
voevent_dict['PR']['filename'])
update_citations = self.get_citations_dict(self._graceid,
voevent_dict['UP']['filename'])
self.assertEqual(update_citations[preliminary_ivorn], 'supersedes')
def test_create_retraction_voevent(self):
......@@ -117,9 +129,12 @@ class TestVOEvents(TestGraceDb):
voevent_dict = {v['voevent_type']: v for v in voevent_list}
# Parse retraction voevent and check for correct citations
retraction_citations = self.get_citations_dict(voevent_dict['RE'])
preliminary_ivorn = self.get_ivorn(voevent_dict['PR'])
update_ivorn = self.get_ivorn(voevent_dict['UP'])
retraction_citations = self.get_citations_dict(self._graceid,
voevent_dict['RE']['filename'])
preliminary_ivorn = self.get_ivorn(self._graceid,
voevent_dict['PR']['filename'])
update_ivorn = self.get_ivorn(self._graceid,
voevent_dict['UP']['filename'])
self.assertTrue(retraction_citations[preliminary_ivorn] == 'retraction'
and retraction_citations[update_ivorn] == 'retraction')
......
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