def test_cleanup(self):
     ''' Cleanup objects created by tests. '''
     
     # Delete all of the objects in the test workspace.
     wsClient = Workspace(self._config["workspace_url"], token=self._token)
     listObjectsParams = dict()
     listObjectsParams['workspaces'] = [ self._config['test_ws'] ]
     objectList = wsClient.list_objects(listObjectsParams)
     deleteList = list()
     for object in objectList:
         deleteList.append( { 'wsid': object[6], 'objid': object[0], 'ver': object[4] })
     wsClient.delete_objects(deleteList)
     objectList = wsClient.list_objects(listObjectsParams)
     for object in objectList:
         print 'After delete Object %s %s' %(object[1], object[4])
    def test_cleanup(self):
        ''' Cleanup objects created by tests. '''

        # Delete all of the objects in the test workspace.
        wsClient = Workspace(self._config["workspace_url"], token=self._token)
        listObjectsParams = dict()
        listObjectsParams['workspaces'] = [self._config['test_ws']]
        objectList = wsClient.list_objects(listObjectsParams)
        deleteList = list()
        for object in objectList:
            deleteList.append({
                'wsid': object[6],
                'objid': object[0],
                'ver': object[4]
            })
        wsClient.delete_objects(deleteList)
        objectList = wsClient.list_objects(listObjectsParams)
        for object in objectList:
            print 'After delete Object %s %s' % (object[1], object[4])
Ejemplo n.º 3
0
    def setUp(cls):

        token = environ.get('KB_AUTH_TOKEN', None)

        if token is None:
            sys.stderr.write(
                "Error: Unable to run tests without authentication token!\n")
            sys.exit(1)

        token_file = open('ltest/script_test/token.txt', 'w')
        token_file.write(token)

        config_file = environ.get('KB_DEPLOYMENT_CONFIG', None)
        cls.cfg = {}
        config = ConfigParser()
        config.read(config_file)
        for nameval in config.items('CoExpression'):
            cls.cfg[nameval[0]] = nameval[1]
        auth_service_url = cls.cfg.get(
            'auth-service-url',
            "https://kbase.us/services/authorization/Sessions/Login")
        ws_url = cls.cfg['ws_url']
        auth_service_url_allow_insecure = cls.cfg[
            'auth-service-url-allow-insecure']
        auth_client = _KBaseAuth(auth_service_url)
        user_id = auth_client.get_user(token)

        ws = Workspace(
            url=ws_url,
            token=token,
            auth_svc=auth_service_url,
            trust_all_ssl_certificates=auth_service_url_allow_insecure)

        # update input data in reverse order of references
        ordered_file_list = [
            INPUT_META_DATA_DIR + '/test_diff_p_distribution_input_ref2.json',
            INPUT_META_DATA_DIR + '/test_diff_p_distribution_input_ref1.json',
            INPUT_META_DATA_DIR + '/test_diff_p_distribution_input.json',
            INPUT_META_DATA_DIR + '/test_view_heatmap_input_ref1.json',
            INPUT_META_DATA_DIR + '/test_view_heatmap_input.json',
            INPUT_META_DATA_DIR + '/test_coex_clust_input.json',
            INPUT_META_DATA_DIR + '/test_filter_genes_input.json'
        ]

        for filename in ordered_file_list:
            with open(filename, 'r') as infile:
                input_meta_data = json.load(infile)

            # create workspace that is local to the user if it does not exist
            workspace_name_t = Template(
                str(input_meta_data['params'][0]['workspace_name']))
            workspace_name = workspace_name_t.substitute(user_id=user_id)
            print('workspace_name: ' + workspace_name)

            try:
                ws_info = ws.get_workspace_info({'workspace': workspace_name})
                print("workspace already exists: " + str(ws_info))
            except:
                ws_info = ws.create_workspace({
                    'workspace':
                    workspace_name,
                    'description':
                    'Workspace for ' + str(input_meta_data['method'])
                })
                print("Created new workspace: " + str(ws_info))

            print('reading input file: ' + filename)
            object_name = str(input_meta_data['params'][0]['object_name'])
            print('object_name: ' + object_name)

            input_data_filename = INPUT_DATA_DIR + '/' + object_name + '.json'
            print('input data filename: ' + input_data_filename)

            with open(input_data_filename, 'r') as infile:
                input_data = json.load(infile)

            # update workspace name in input data
            input_data_str = json.dumps(input_data)
            input_data_t = Template(input_data_str)
            input_data_str = input_data_t.substitute(
                workspace_name=workspace_name)
            input_data = json.loads(input_data_str)

            print('type: ' + input_data[0]['info'][2])

            #upload data (no effect if data already exists in workspace)
            print('uploading input data to workspace')
            ws.save_objects({
                'workspace':
                workspace_name,
                'objects': [{
                    'type': input_data[0]['info'][2],
                    'data': input_data[0]['data'],
                    'name': object_name
                }]
            })
        print('ws objects: ' +
              str(ws.list_objects({'workspaces': [workspace_name]})))
Ejemplo n.º 4
0
    def setUp(cls):

      token = environ.get('KB_AUTH_TOKEN', None)

      if token is None:
          sys.stderr.write("Error: Unable to run tests without authentication token!\n")
          sys.exit(1)

      token_file = open('ltest/script_test/token.txt', 'w')
      token_file.write(token)

      config_file = environ.get('KB_DEPLOYMENT_CONFIG', None)
      cls.cfg = {}
      config = ConfigParser()
      config.read(config_file)
      for nameval in config.items('CoExpression'):
          cls.cfg[nameval[0]] = nameval[1]
      auth_service_url = cls.cfg.get('auth-service-url',
                                     "https://kbase.us/services/authorization/Sessions/Login")
      ws_url = cls.cfg['ws_url']
      auth_service_url_allow_insecure = cls.cfg['auth-service-url-allow-insecure']
      auth_client = _KBaseAuth(auth_service_url)
      user_id = auth_client.get_user(token)

      ws = Workspace(url=ws_url, token=token, auth_svc=auth_service_url,
                             trust_all_ssl_certificates=auth_service_url_allow_insecure)

      # update input data in reverse order of references
      ordered_file_list = [INPUT_META_DATA_DIR+'/test_diff_p_distribution_input_ref2.json',
                      INPUT_META_DATA_DIR+'/test_diff_p_distribution_input_ref1.json',
                      INPUT_META_DATA_DIR+'/test_diff_p_distribution_input.json',
                      INPUT_META_DATA_DIR+'/test_view_heatmap_input_ref1.json',
                      INPUT_META_DATA_DIR+'/test_view_heatmap_input.json',
                      INPUT_META_DATA_DIR+'/test_coex_clust_input.json',
                      INPUT_META_DATA_DIR+'/test_filter_genes_input.json']

      for filename in ordered_file_list:
          with open(filename, 'r') as infile:
            input_meta_data = json.load(infile)

          # create workspace that is local to the user if it does not exist
          workspace_name_t = Template(str(input_meta_data['params'][0]['workspace_name']))
          workspace_name = workspace_name_t.substitute(user_id=user_id)
          print('workspace_name: ' + workspace_name)

          try:
              ws_info = ws.get_workspace_info({'workspace': workspace_name})
              print("workspace already exists: " + str(ws_info))
          except:
              ws_info = ws.create_workspace(
                {'workspace': workspace_name, 'description': 'Workspace for ' + str(input_meta_data['method'])})
              print("Created new workspace: " + str(ws_info))

          print('reading input file: '+filename)
          object_name = str(input_meta_data['params'][0]['object_name'])
          print('object_name: '+object_name)

          input_data_filename = INPUT_DATA_DIR + '/' + object_name + '.json'
          print('input data filename: ' + input_data_filename)

          with open(input_data_filename, 'r') as infile:
            input_data = json.load(infile)

          # update workspace name in input data
          input_data_str = json.dumps(input_data)
          input_data_t = Template(input_data_str)
          input_data_str = input_data_t.substitute(workspace_name=workspace_name)
          input_data = json.loads(input_data_str)

          print('type: '+input_data[0]['info'][2])

          #upload data (no effect if data already exists in workspace)
          print('uploading input data to workspace')
          ws.save_objects(
                  {'workspace': workspace_name, 'objects': [{'type': input_data[0]['info'][2],
                                                                  'data': input_data[0]['data'],
                                                                  'name': object_name}]})
      print('ws objects: ' + str(ws.list_objects({'workspaces': [workspace_name]})))