def test_two_users_sharing_dp(self):
     dps = DataPaletteService(
         self.__class__.serviceWizardURL,
         token=self.getContext2()['token'],
         service_ver=self.__class__.DataPalette_version)
     ws_name1 = self.createWs()
     # Injecting reads object (real copy) into workspace1
     orig_reads_obj_ref = self.__class__.example_reads_ref
     target_name = "TestReads"
     self.getWsClient().copy_object({
         'from': {
             'ref': orig_reads_obj_ref
         },
         'to': {
             'workspace': ws_name1,
             'name': target_name
         }
     })
     copy_reads_obj_ref = ws_name1 + '/' + target_name
     # Making DP-copy of reads object by user2
     ws_name2 = self.createWs2()
     # Check that user2 can't import reads object until workspace is shared
     try:
         dps.add_to_palette({
             'workspace': ws_name2,
             'new_refs': [{
                 'ref': copy_reads_obj_ref
             }]
         })
         raise ValueError(
             "We shouldn't be able to import reads object to DataPalette")
     except Exception, e:
         self.assertTrue("Object TestReads cannot be accessed" in str(e))
Example #2
0
 def test_copy_object_two_users(self):
     ws_name1 = self.createWs()
     orig_reads_ref = self.__class__.example_reads_ref
     # Adding DP object:
     dps1 = DataPaletteService(self.__class__.serviceWizardURL, 
                               token=self.getContext()['token'],
                               service_ver=self.__class__.DataPalette_version)
     dps1.add_to_palette({'workspace': ws_name1, 'new_refs': [{'ref': orig_reads_ref}]})
     # Share this workspace with user2 so that user2 can make DataPalette ref
     ws1 = self.getWsClient()
     ws1.set_permissions({'workspace': ws_name1, 'new_permission': 'r',
                          'users': [self.getContext2()['user_id']]})
     # Get ref-path to reads object
     ret = self.getImpl().list_objects_with_sets(self.getContext(),
                                                 {"ws_name": ws_name1})[0]['data']
     reads_ref_path = None
     for item in ret:
         if 'dp_info' in item:
             info = item['object_info']
             reads_ref_path = (item['dp_info']['ref'] + ';' + 
                               str(info[6]) + '/' + str(info[0]) + '/' + str(info[4]))
     # Adding Reads to DP of second user
     ws_name2 = self.createWs2()
     dps2 = DataPaletteService(self.__class__.serviceWizardURL, 
                               token=self.getContext2()['token'],
                               service_ver=self.__class__.DataPalette_version)
     dps2.add_to_palette({'workspace': ws_name2, 'new_refs': [{'ref': reads_ref_path}]})
Example #3
0
    def test_copy_narrative_two_users(self):
        # Create workspace with Reads object for user1
        ws_name1 = self.createWs()
        orig_reads_ref = self.__class__.example_reads_ref
        target_reads_name = "MyReads.copy.1"
        ws1 = self.getWsClient()
        reads_info = ws1.copy_object({'from': {'ref': orig_reads_ref},
                                      'to': {'workspace': ws_name1,
                                             'name': target_reads_name}})
        # Share this workspace with user2 so that user2 can make DataPalette ref
        ws1.set_permissions({'workspace': ws_name1, 'new_permission': 'r',
                             'users': [self.getContext2()['user_id']]})
        reads_ref = str(reads_info[6]) + '/' + str(reads_info[0]) + '/' + str(reads_info[4])
        
        # Create workspace with Narrative for user2
        ws2 = self.getWsClient2()
        with open("/kb/module/test/data/narrative1.json", "r") as f1:
            nar_obj_data = json.load(f1)
        user_id = self.getContext2()['user_id']
        ws_name2 = self.createWs2()
        nar_obj_data['metadata']['creator'] = user_id
        nar_obj_data['metadata']['ws_name'] = ws_name2
        nar_obj_data['metadata']['kbase']['creator'] = user_id
        nar_obj_data['metadata']['kbase']['ws_name'] = ws_name2
        nar_obj_name = "Narrative." + str(int(round(time.time() * 1000)))
        nar_obj_type = "KBaseNarrative.Narrative-4.0"
        job_info = json.dumps({"queue_time": 0, "running": 0, "completed": 0,
                               "run_time": 0, "error": 0})
        nar_obj_meta = {"description": "",
                        "format": "ipynb",
                        "creator": user_id,
                        "job_info": job_info,
                        "data_dependencies": "[]",
                        "jupyter.markdown": "1",
                        "ws_name": ws_name2,
                        "type": "KBaseNarrative.Narrative",
                        "name": "NarrativeCopyTest"}
        ws2.save_objects({'workspace': ws_name2, 'objects':
                         [{'type': nar_obj_type,
                           'data': nar_obj_data,
                           'name': nar_obj_name,
                           'meta': nar_obj_meta}]})
        # Adding DP object:
        dps = DataPaletteService(self.__class__.serviceWizardURL, 
                                  token=self.getContext2()['token'],
                                  service_ver=self.__class__.DataPalette_version)
        dps.add_to_palette({'workspace': ws_name2, 'new_refs': [{'ref': reads_ref}]})
        target_reads_name2 = "MyReads.copy.2"
        ws2.copy_object({'from': {'ref': reads_ref},
                         'to': {'workspace': ws_name2,
                                'name': target_reads_name2}})

        #Un-share ws_name1 with user2
        ws1.set_permissions({'workspace': ws_name1, 'new_permission': 'n',
                             'users': [self.getContext2()['user_id']]})
        try:
            self.getWsClient2().get_object_info_new({'objects': [{'ref': reads_ref}]})
            raise ValueError("We shouldn't be able to access reads object")
        except Exception, e:
            self.assertTrue("cannot be accessed" in str(e))
Example #4
0
 def test_two_users_set_inside_dp(self):
     ws_name1_1 = self.createWs()
     # Injecting reads object (real copy) into workspace1
     orig_reads_obj_ref = self.__class__.example_reads_ref
     reads_obj_name = "TestReads"
     self.getWsClient().copy_object({'from': {'ref': orig_reads_obj_ref},
                                     'to': {'workspace': ws_name1_1,
                                            'name': reads_obj_name}})
     copy_reads_obj_ref = ws_name1_1 + '/' + reads_obj_name
     ws_name1_2 = self.createWs()
     set_obj_name = "MyReadsSet.1"
     sapi = SetAPI(self.__class__.serviceWizardURL, token=self.getContext()['token'],
                   service_ver=self.__class__.SetAPI_version)
     sapi.save_reads_set_v1({'workspace': ws_name1_2, 'output_object_name': set_obj_name,
                             'data': {'description': '', 'items': [{'ref': copy_reads_obj_ref}]}})
     orig_set_ref = ws_name1_2 + '/' + set_obj_name
     # Making DP-copy of reads set object by user2
     ws_name2 = self.createWs2()
     # Let's share workspace containing set with user2
     self.getWsClient().set_permissions({'workspace': ws_name1_2, 'new_permission': 'r',
                                         'users': [self.getContext2()['user_id']]})
     # Import reads set ref into DataPalette of third workspace
     dps = DataPaletteService(self.__class__.serviceWizardURL, 
                               token=self.getContext2()['token'],
                               service_ver=self.__class__.DataPalette_version)
     dps.add_to_palette({'workspace': ws_name2, 'new_refs': [{'ref': orig_set_ref}]})
     dp_ref_map = dps.list_data({'workspaces': [ws_name2]})['data_palette_refs']
     set_ref_path = dp_ref_map.itervalues().next() + ';' + orig_set_ref
     reads_ref_path = set_ref_path + ';' + copy_reads_obj_ref
     # Un-share original workspace 
     self.getWsClient().set_permissions({'workspace': ws_name1_2, 'new_permission': 'n',
                                         'users': [self.getContext2()['user_id']]})
     # Let's check that we can list set and see reads object as set item
     ret = self.getImpl().list_objects_with_sets(self.getContext2(),
                                                 {"ws_name": ws_name2})[0]["data"]
     self.assertEqual(1, len(ret))
     item = ret[0]
     self.assertTrue('set_items' in item)
     self.assertTrue('set_items_info' in item['set_items'])
     self.assertEqual(1, len(item['set_items']['set_items_info']))
     # Check access to reads and to set objects
     info = self.getWsClient2().get_object_info_new({'objects': [{'ref': set_ref_path}]})[0]
     self.assertEqual(set_obj_name, info[1])
     info = self.getWsClient2().get_object_info_new({'objects': [{'ref': reads_ref_path}]})[0]
     self.assertEqual(reads_obj_name, info[1])
 def test_unique_items(self):
     # Create original workspace with reads object + ReadsSet object
     ws_name1 = self.createWs()
     foft = FakeObjectsForTests(os.environ['SDK_CALLBACK_URL'])
     reads_obj_name = "test.reads.1"
     foft.create_fake_reads({
         'ws_name': ws_name1,
         'obj_names': [reads_obj_name]
     })
     reads_obj_ref = ws_name1 + '/' + reads_obj_name
     set_obj_name = "test.reads_set.1"
     sapi = SetAPI(self.__class__.serviceWizardURL,
                   token=self.getContext()['token'],
                   service_ver=self.__class__.SetAPI_version)
     sapi.save_reads_set_v1({
         'workspace': ws_name1,
         'output_object_name': set_obj_name,
         'data': {
             'description': '',
             'items': [{
                 'ref': reads_obj_ref
             }]
         }
     })
     set_obj_ref = ws_name1 + '/' + set_obj_name
     # Create workspace with DataPalette copy of Reads object and copy of ReadsSet
     ws_name2 = self.createWs()
     dps = DataPaletteService(
         self.__class__.serviceWizardURL,
         token=self.getContext()['token'],
         service_ver=self.__class__.DataPalette_version)
     dps.add_to_palette({
         'workspace':
         ws_name2,
         'new_refs': [{
             'ref': reads_obj_ref
         }, {
             'ref': set_obj_ref
         }]
     })
     # Check if listing in both these workspaces at the same time gives unique items
     ret = self.getImpl().list_objects_with_sets(
         self.getContext(), {"workspaces": [ws_name1, ws_name2]})[0]["data"]
     self.assertEqual(2, len(ret))
    def test_list_sets(self):

        workspace = self.getWsName()
        setAPI = self.getImpl()

        # make sure we can see an empty list of sets before WS has any
        res = setAPI.list_sets(self.getContext(), {
            'workspace': workspace,
            'include_set_item_info': 1
        })[0]

        # create the test sets
        self.create_sets()

        res = setAPI.list_sets(self.getContext(), {
            'workspace': workspace,
            'include_set_item_info': 1
        })[0]
        self.assertTrue('sets' in res)
        self.assertEqual(len(res['sets']), len(self.setNames))
        for s in res['sets']:
            self.assertTrue('ref' in s)
            self.assertTrue('info' in s)
            self.assertTrue('items' in s)
            self.assertEqual(len(s['info']), 11)
            self.assertEqual(len(s['items']), 2)
            for item in s['items']:
                self.assertTrue('ref' in item)
                self.assertTrue('info' in item)
                self.assertEqual(len(item['info']), 11)

        res2 = setAPI.list_sets(self.getContext(), {'workspace': workspace})[0]
        self.assertTrue('sets' in res2)
        self.assertEqual(len(res2['sets']), len(self.setNames))
        for s in res2['sets']:
            self.assertTrue('ref' in s)
            self.assertTrue('info' in s)
            self.assertTrue('items' in s)
            self.assertEqual(len(s['info']), 11)
            self.assertEqual(len(s['items']), 2)
            for item in s['items']:
                self.assertTrue('ref' in item)
                self.assertTrue('info' not in item)

        res = setAPI.get_set_items(self.getContext(),
                                   {'set_refs': [{
                                       'ref': self.setRefs[0]
                                   }]})[0]
        self.assertEqual(len(res['sets']), 1)
        for s in res['sets']:
            self.assertTrue('ref' in s)
            self.assertTrue('info' in s)
            self.assertTrue('items' in s)
            self.assertEqual(len(s['info']), 11)
            self.assertEqual(len(s['items']), 2)
            for item in s['items']:
                self.assertTrue('ref' in item)
                self.assertTrue('info' in item)
                self.assertEqual(len(item['info']), 11)

        set_obj_name = self.setNames[0]
        wsName2 = "test_SetAPI_" + str(int(time.time() * 1000)) + "_two"
        self.getWsClient().create_workspace({'workspace': wsName2})
        try:
            set_obj_ref = self.getWsName() + '/' + set_obj_name
            dps = DataPaletteService(
                self.serviceWizardURL,
                token=self.getContext()['token'],
                service_ver=self.dataPaletteServiceVersion)
            dps.add_to_palette({
                'workspace': wsName2,
                'new_refs': [{
                    'ref': set_obj_ref
                }]
            })
            ret = self.getImpl().list_sets(
                self.getContext(), {
                    'workspace': wsName2,
                    'include_set_item_info': 1,
                    'include_raw_data_palettes': 1
                })[0]
            set_list = ret['sets']
            self.assertEqual(1, len(set_list))
            set_info = set_list[0]
            info = set_info['info']
            self.assertEqual(self.getWsName(), info[7])
            self.assertEqual(set_obj_name, info[1])
            self.assertTrue('raw_data_palettes' in ret)
            self.assertEqual(1, len(ret['raw_data_palettes']))
            self.assertIn('info', ret['raw_data_palettes'][0])
            self.assertIn('ref', ret['raw_data_palettes'][0])
            self.assertTrue('raw_data_palette_refs' in ret)
            self.assertEqual(1, len(ret['raw_data_palette_refs']))

            set_list2 = self.getImpl().list_sets(
                self.getContext(), {
                    'workspaces': [workspace, wsName2],
                    'include_set_item_info': 1,
                    'include_metadata': 1
                })[0]['sets']
            self.assertEqual(len(set_list2), len(self.setNames))
            self.assertTrue(len(set_list2) > 0)
            for set_obj in set_list2:
                self.assertIsNotNone(set_obj['info'][10])
                for item in set_obj['items']:
                    self.assertIsNotNone(item['info'][10])
        finally:
            self.getWsClient().delete_workspace({'workspace': wsName2})