Skip to content

Commit

Permalink
fix and test issue with is_temporary field in ws metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
briehl committed Jan 8, 2018
1 parent 9dd35cf commit aed0b0c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lib/NarrativeService/NarrativeManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def copy_narrative(self, newName, workspaceRef, workspaceId):
time_ms = int(round(time.time() * 1000))
newWsName = self.user_id + ':narrative_' + str(time_ms)
# add the 'narrative' field to newWsMeta later.
newWsMeta = {"is_temporary": "false", "narrative_nice_name": newName}
newWsMeta = {"narrative_nice_name": newName}

# start with getting the existing narrative object.
currentNarrative = self.ws.get_objects([{'ref': workspaceRef}])[0]
Expand Down Expand Up @@ -207,8 +207,9 @@ def copy_narrative(self, newName, workspaceRef, workspaceId):
newNarMetadata['ws_name'] = newWsName
newNarMetadata['job_info'] = json.dumps({'queue_time': 0, 'running': 0,
'completed': 0, 'run_time': 0, 'error': 0})

is_temporary = newNarMetadata.get('is_temporary', 'false')
if 'is_temporary' not in newNarMetadata:
is_temporary = 'false'
if newNarMetadata['name'] == 'Untitled' or newNarMetadata['name'] is None:
is_temporary = 'true'
newNarMetadata['is_temporary'] = is_temporary
Expand All @@ -228,8 +229,15 @@ def copy_narrative(self, newName, workspaceRef, workspaceId):
# now, just update the workspace metadata to point
# to the new narrative object
newNarId = newNarInfo[0][0]
self.ws.alter_workspace_metadata({'wsi': {'id': newWsId},
'new': {'narrative': str(newNarId)}})
self.ws.alter_workspace_metadata({
'wsi': {
'id': newWsId
},
'new': {
'narrative': str(newNarId),
'is_temporary': is_temporary
}
})
return {'newWsId': newWsId, 'newNarId': newNarId}
except:
# let's delete copy of workspace so it's out of the way - it's broken
Expand Down
32 changes: 32 additions & 0 deletions test/NarrativeService_server_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@ def test_copy_temp_narrative(self):
"""
Now copy a Narrative flagged as temporary. E.g. create a new narrative, then make
a copy right away. Test that it contains the right 'is_temporary' key in metadata.
Also, for kicks, copy one that's NOT temporary and make sure the 'false' propagates.
"""
ws = self.getWsClient()

Expand All @@ -337,6 +339,7 @@ def test_copy_temp_narrative(self):
'ref': '{}/{}'.format(copied_nar_info['newWsId'], copied_nar_info['newNarId'])
}]
})
copied_ws_info = ws.get_workspace_info({'id': copied_nar_info['newWsId']})

# second, tweak the source to remove its 'is_temporary' field all together. then
# copy and test it.
Expand All @@ -361,14 +364,43 @@ def test_copy_temp_narrative(self):
'ref': '{}/{}'.format(copied_nar_info2['newWsId'], copied_nar_info2['newNarId'])
}]
})
copied_ws_info2 = ws.get_workspace_info({'id': copied_nar_info2['newWsId']})

# Finally, create a new non-temporary narrative, copy it, and ensure everything has
# 'is_temporary': 'false' in the right metadata places.
source_nar_info2 = self.getImpl().create_new_narrative(self.getContext(), {
'title': 'Not Temporary'
})[0]
source_ws_id2 = source_nar_info2['workspaceInfo']['id']
source_nar_id2 = source_nar_info2['narrativeInfo']['id']
copied_nar_info3 = self.getImpl().copy_narrative(self.getContext(), {
'workspaceRef': '{}/{}'.format(source_ws_id2, source_nar_id2),
'newName': 'Still Not Temporary'
})[0]
copied_nar3 = ws.get_objects2({
'objects': [{
'ref': '{}/{}'.format(copied_nar_info3['newWsId'], copied_nar_info3['newNarId'])
}]
})
copied_ws_info3 = ws.get_workspace_info({'id': copied_nar_info3['newWsId']})

try:
self.assertEquals(source_nar_info['workspaceInfo']['metadata']['is_temporary'], 'true')
self.assertEquals(source_nar_info['narrativeInfo']['metadata']['is_temporary'], 'true')
self.assertEquals(copied_nar['data'][0]['info'][10]['is_temporary'], 'true')
self.assertEquals(copied_ws_info[8]['is_temporary'], 'true')
self.assertEquals(copied_nar2['data'][0]['info'][10]['is_temporary'], 'true')
self.assertEquals(copied_ws_info2[8]['is_temporary'], 'true')
self.assertEquals(source_nar_info2['workspaceInfo']['metadata']['is_temporary'], 'false')
self.assertEquals(source_nar_info2['narrativeInfo']['metadata']['is_temporary'], 'false')
self.assertEquals(copied_nar3['data'][0]['info'][10]['is_temporary'], 'false')
self.assertEquals(copied_ws_info3[8]['is_temporary'], 'false')
finally:
self.getWsClient().delete_workspace({'id': source_ws_id})
self.getWsClient().delete_workspace({'id': source_ws_id2})
self.getWsClient().delete_workspace({'id': copied_nar_info['newWsId']})
self.getWsClient().delete_workspace({'id': copied_nar_info2['newWsId']})
self.getWsClient().delete_workspace({'id': copied_nar_info3['newWsId']})

def test_copy_narrative_two_users(self):
# Create workspace with Reads object for user1
Expand Down

0 comments on commit aed0b0c

Please sign in to comment.