Add integration tests for signoffs and permissions

parent c5fba5a2
......@@ -16,8 +16,10 @@
# You should have received a copy of the GNU General Public License
# along with gracedb. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function
from collections import defaultdict
import datetime
import os
from six import iteritems
from six.moves import range
import unittest
......@@ -633,5 +635,160 @@ class TestSuperevents(TestGraceDb):
# Check response data
self.assertEqual(ret_data['voevent_type'], 'PR')
def test_signoffs(self):
"""Create, update, delete, and retrieve signoffs"""
# We have to test advocate signoffs only, because operator signoff
# groups are assigned based on IP address.
# Add "signoff requested" label to superevent
response = self._gracedb.writeLabel(self._superevent, 'ADVREQ')
self.assertEqual(response.status, 201)
# Create a signoff
response = self._gracedb.create_signoff(self._superevent, 'ADV', 'OK',
"looks good")
ret_data = response.json()
self.assertEqual(response.status, 201)
self.assertEqual(ret_data['status'], 'OK')
self.assertEqual(ret_data['comment'], 'looks good')
self.assertEqual(ret_data['instrument'], '')
self.assertEqual(ret_data['signoff_type'], 'advocate')
# Check signoff from API signoff list
response = self._gracedb.signoffs(self._superevent)
self.assertEqual(response.status, 200)
ret_data = response.json()
self.assertEqual(len(ret_data['signoffs']), 1)
signoff = ret_data['signoffs'][0]
self.assertEqual(signoff['status'], 'OK')
self.assertEqual(signoff['comment'], 'looks good')
self.assertEqual(signoff['instrument'], '')
self.assertEqual(signoff['signoff_type'], 'advocate')
# Test retrieving the same signoff directly rather than from
# the list of signoffs for this superevent
response = self._gracedb.signoffs(self._superevent,
signoff_type='ADV')
self.assertEqual(response.status, 200)
signoff = response.json()
self.assertEqual(signoff['status'], 'OK')
self.assertEqual(signoff['comment'], 'looks good')
self.assertEqual(signoff['instrument'], '')
self.assertEqual(signoff['signoff_type'], 'advocate')
# Check label status
response = self._gracedb.labels(self._superevent)
ret_data = response.json()
self.assertEqual(response.status, 200)
label_names = [l['name'] for l in ret_data['labels']]
self.assertNotIn('ADVREQ', label_names)
self.assertIn('ADVOK', label_names)
self.assertNotIn('ADVNO', label_names)
# Update signoff
response = self._gracedb.update_signoff(self._superevent, 'ADV',
status='NO', comment='not OK')
ret_data = response.json()
self.assertEqual(response.status, 200)
self.assertEqual(ret_data['status'], 'NO')
self.assertEqual(ret_data['comment'], 'not OK')
self.assertEqual(ret_data['instrument'], '')
self.assertEqual(ret_data['signoff_type'], 'advocate')
# Check signoff from API
response = self._gracedb.signoffs(self._superevent)
ret_data = response.json()
self.assertEqual(response.status, 200)
self.assertEqual(len(ret_data['signoffs']), 1)
signoff = ret_data['signoffs'][0]
self.assertEqual(signoff['status'], 'NO')
self.assertEqual(signoff['comment'], 'not OK')
self.assertEqual(signoff['instrument'], '')
self.assertEqual(signoff['signoff_type'], 'advocate')
# Check label status
response = self._gracedb.labels(self._superevent)
ret_data = response.json()
self.assertEqual(response.status, 200)
label_names = [l['name'] for l in ret_data['labels']]
self.assertNotIn('ADVREQ', label_names)
self.assertNotIn('ADVOK', label_names)
self.assertIn('ADVNO', label_names)
# Delete signoff
response = self._gracedb.delete_signoff(self._superevent, 'ADV')
self.assertEqual(response.status, 204)
ret_data = response.json()
self.assertEqual(ret_data, {})
# Check signoff from API
response = self._gracedb.signoffs(self._superevent)
self.assertEqual(response.status, 200)
ret_data = response.json()
self.assertEqual(len(ret_data['signoffs']), 0)
# Check label status
response = self._gracedb.labels(self._superevent)
ret_data = response.json()
self.assertEqual(response.status, 200)
label_names = [l['name'] for l in ret_data['labels']]
self.assertIn('ADVREQ', label_names)
self.assertNotIn('ADVOK', label_names)
self.assertNotIn('ADVNO', label_names)
def test_permissions(self):
"""Retrieve and modify permissions"""
# Get permissions for superevent, should be blank
response = self._gracedb.permissions(self._superevent)
self.assertEqual(response.status, 200)
data = response.json()
self.assertEqual(data['permissions'], [])
# Expose superevent to public
response = self._gracedb.modify_permissions(self._superevent, 'expose')
self.assertEqual(response.status, 200)
data = response.json()
self.assertEqual(len(data), 3)
# Compile response data into dict with group name keys
group_perms = defaultdict(list)
for p in data:
group_perms[p['group']].append(p['permission'])
# Check contents
for group, perms in iteritems(group_perms):
if (group == 'public_users'):
self.assertEqual(len(perms), 1)
self.assertIn('view_superevent', perms)
elif (group == 'gw-astronomy:LV-EM:Observers'):
self.assertEqual(len(perms), 2)
self.assertIn('view_superevent', perms)
self.assertIn('annotate_superevent', perms)
# Test permissions list
response = self._gracedb.permissions(self._superevent)
self.assertEqual(response.status, 200)
data = response.json()['permissions']
self.assertEqual(len(data), 3)
# Compile response data into dict with group name keys
group_perms = defaultdict(list)
for p in data:
group_perms[p['group']].append(p['permission'])
# Check contents
for group, perms in iteritems(group_perms):
if (group == 'public_users'):
self.assertEqual(len(perms), 1)
self.assertIn('view_superevent', perms)
elif (group == 'gw-astronomy:LV-EM:Observers'):
self.assertEqual(len(perms), 2)
self.assertIn('view_superevent', perms)
self.assertIn('annotate_superevent', perms)
# Hide superevent from public
response = self._gracedb.modify_permissions(self._superevent, 'hide')
self.assertEqual(response.status, 200)
data = response.json()
self.assertEqual(data, [])
if __name__ == "__main__":
unittest.main(verbosity=2, failfast=True)
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