def setUpClass(cls):
     token = os.environ.get('KB_AUTH_TOKEN', None)
     config_file = os.environ.get('KB_DEPLOYMENT_CONFIG', None)
     cls.cfg = {}
     config = ConfigParser()
     config.read(config_file)
     for nameval in config.items('NarrativeService'):
         cls.cfg[nameval[0]] = nameval[1]
     authServiceUrl = cls.cfg.get(
         'auth-service-url',
         "https://kbase.us/services/authorization/Sessions/Login")
     auth_client = _KBaseAuth(authServiceUrl)
     cls.user_id = auth_client.get_user(token)
     # WARNING: don't call any logging methods on the context object,
     # it'll result in a NoneType error
     cls.ctx = MethodContext(None)
     cls.ctx.update({
         'token':
         token,
         'user_id':
         cls.user_id,
         'provenance': [{
             'service': 'NarrativeService',
             'method': 'please_never_use_it_in_production',
             'method_params': []
         }],
         'authenticated':
         1
     })
     cls.nmsURL = cls.cfg['narrative-method-store']
     cls.catalogURL = cls.cfg['catalog-url']
     cls.wsURL = cls.cfg['workspace-url']
     cls.serviceImpl = NarrativeService(cls.cfg)
 def setUpClass(cls):
     token = environ.get('KB_AUTH_TOKEN', None)
     config_file = environ.get('KB_DEPLOYMENT_CONFIG', None)
     cls.cfg = {}
     config = ConfigParser()
     config.read(config_file)
     for nameval in config.items('kb_muscle'):
         cls.cfg[nameval[0]] = nameval[1]
     # Getting username from Auth profile for token
     authServiceUrl = cls.cfg['auth-service-url']
     auth_client = _KBaseAuth(authServiceUrl)
     user_id = auth_client.get_user(token)
     # WARNING: don't call any logging methods on the context object,
     # it'll result in a NoneType error
     cls.ctx = MethodContext(None)
     cls.ctx.update({'token': token,
                     'user_id': user_id,
                     'provenance': [
                         {'service': 'kb_muscle',
                          'method': 'please_never_use_it_in_production',
                          'method_params': []
                          }],
                     'authenticated': 1})
     cls.wsURL = cls.cfg['workspace-url']
     cls.wsClient = workspaceService(cls.wsURL)
     cls.serviceImpl = kb_muscle(cls.cfg)
     cls.scratch = cls.cfg['scratch']
     cls.callback_url = os.environ['SDK_CALLBACK_URL']
def get_authors(config, wsid):
    ws = Workspace(url=config.narrative_session.ws_url,
                   token=config.narrative_session.token)
    ws_info = ws.get_workspace_info({"id": wsid})
    author_id_list = [ws_info[2]]

    other_authors = ws.get_permissions({"id": wsid})

    for author in sorted(other_authors.keys()):
        if author != "*" and other_authors[author] in [
                "w", "a"
        ] and author not in author_id_list:
            author_id_list.append(author)

    auth = _KBaseAuth(config.narrative_session.auth_url)
    disp_names = auth.get_display_names(config.narrative_session.token,
                                        author_id_list)
    author_list = []
    for author in author_id_list:
        author_list.append({
            "id":
            author,
            "name":
            html.escape(disp_names.get(author, author)),
            "path":
            config.narrative_session.profile_page_url + author
        })
    return author_list
Example #4
0
 def __init__(self):
     submod = get_service_name() or 'nmdc_metaassembly'
     self.userlog = log.log(submod,
                            ip_address=True,
                            authuser=True,
                            module=True,
                            method=True,
                            call_id=True,
                            changecallback=self.logcallback,
                            config=get_config_file())
     self.serverlog = log.log(submod,
                              ip_address=True,
                              authuser=True,
                              module=True,
                              method=True,
                              call_id=True,
                              logfile=self.userlog.get_log_file())
     self.serverlog.set_log_level(6)
     self.rpc_service = JSONRPCServiceCustom()
     self.method_authentication = dict()
     self.rpc_service.add(impl_nmdc_metaassembly.run_nmdc_metaassembly,
                          name='nmdc_metaassembly.run_nmdc_metaassembly',
                          types=[dict])
     self.method_authentication[
         'nmdc_metaassembly.run_nmdc_metaassembly'] = 'required'  # noqa
     self.rpc_service.add(impl_nmdc_metaassembly.status,
                          name='nmdc_metaassembly.status',
                          types=[dict])
     authurl = config.get(AUTH) if config else None
     self.auth_client = _KBaseAuth(authurl)
Example #5
0
 def setUpClass(cls):
     cls.token = environ.get('KB_AUTH_TOKEN', None)
     config_file = environ.get('KB_DEPLOYMENT_CONFIG', None)
     cls.cfg = {}
     config = ConfigParser()
     config.read(config_file)
     for nameval in config.items('kb_quast'):
         cls.cfg[nameval[0]] = nameval[1]
     authServiceUrl = cls.cfg.get(
         'auth-service-url',
         "https://kbase.us/services/authorization/Sessions/Login")
     auth_client = _KBaseAuth(authServiceUrl)
     user_id = auth_client.get_user(cls.token)
     # WARNING: don't call any logging methods on the context object,
     # it'll result in a NoneType error
     cls.ctx = MethodContext(None)
     cls.ctx.update({
         'token':
         cls.token,
         'user_id':
         user_id,
         'provenance': [{
             'service': 'kb_quast',
             'method': 'please_never_use_it_in_production',
             'method_params': []
         }],
         'authenticated':
         1
     })
     cls.shockURL = cls.cfg['shock-url']
     cls.ws = Workspace(cls.cfg['workspace-url'], token=cls.token)
     cls.hs = HandleService(url=cls.cfg['handle-service-url'],
                            token=cls.token)
     cls.au = AssemblyUtil(os.environ['SDK_CALLBACK_URL'])
     cls.impl = kb_quast(cls.cfg)
     cls.scratch = cls.cfg['scratch']
     shutil.rmtree(cls.scratch)
     os.mkdir(cls.scratch)
     suffix = int(time.time() * 1000)
     wsName = "test_ReadsUtils_" + str(suffix)
     cls.ws_info = cls.ws.create_workspace({'workspace': wsName})
     cls.dfu = DataFileUtil(os.environ['SDK_CALLBACK_URL'])
     cls.staged = {}
     cls.nodes_to_delete = []
     cls.handles_to_delete = []
     #         cls.setupTestData()
     print('\n\n=============== Starting tests ==================')
Example #6
0
    def setUpClass(cls):
        token = os.environ.get('KB_AUTH_TOKEN', None)
        config_file = os.environ.get('KB_DEPLOYMENT_CONFIG', None)
        cls.cfg = {}
        config = ConfigParser()
        config.read(config_file)
        for nameval in config.items('NarrativeService'):
            cls.cfg[nameval[0]] = nameval[1]
        authServiceUrl = cls.cfg.get(
            'auth-service-url',
            "https://kbase.us/services/authorization/Sessions/Login")
        auth_client = _KBaseAuth(authServiceUrl)
        user_id = auth_client.get_user(token)
        # WARNING: don't call any logging methods on the context object,
        # it'll result in a NoneType error
        cls.ctx = MethodContext(None)
        cls.ctx.update({
            'token':
            token,
            'user_id':
            user_id,
            'provenance': [{
                'service': 'NarrativeService',
                'method': 'please_never_use_it_in_production',
                'method_params': []
            }],
            'authenticated':
            1
        })
        # Set up test Workspace
        cls.ws_url = cls.cfg['workspace-url']
        cls.ws_client = Workspace(cls.ws_url, token=token)
        cls.test_ws_info = cls._make_workspace()
        cls.test_ws_name = cls.test_ws_info[1]
        # Build test data stuff.
        # 1. Make a fake reads object - test for report (should be null)
        cls.fake_reads_upa = cls._make_fake_reads(cls.test_ws_name,
                                                  "FakeReads")

        # 2. Make a report, give it that reads object - test for report, should find it
        cls.fake_report_upa = cls._make_fake_report(cls.fake_reads_upa,
                                                    cls.test_ws_name)

        cls.service_impl = NarrativeService(cls.cfg)
Example #7
0
    def setUpClass(cls):
        token = os.environ.get('KB_AUTH_TOKEN', None)
        config_file = os.environ.get('KB_DEPLOYMENT_CONFIG', None)
        cls.cfg = {}
        config = ConfigParser()
        config.read(config_file)
        for nameval in config.items('GenericsIndexer'):
            cls.cfg[nameval[0]] = nameval[1]
        # Getting username from Auth profile for token
        authServiceUrl = cls.cfg['auth-service-url']
        auth_client = _KBaseAuth(authServiceUrl)
        user_id = auth_client.get_user(token)
        # WARNING: don't call any logging methods on the context object,
        # it'll result in a NoneType error
        cls.ctx = MethodContext(None)
        cls.ctx.update({
            'token':
            token,
            'user_id':
            user_id,
            'provenance': [{
                'service': 'GenericsIndexer',
                'method': 'please_never_use_it_in_production',
                'method_params': []
            }],
            'authenticated':
            1
        })
        cls.wsURL = cls.cfg['workspace-url']
        cls.wsClient = Workspace(cls.wsURL)
        cls.impl = GenericsIndexer(cls.cfg)
        cls.scratch = cls.cfg['scratch']
        cls.test_dir = os.path.dirname(os.path.abspath(__file__))
        cls.mock_dir = os.path.join(cls.test_dir, 'data')
        cls.schema_dir = cls.cfg['schema-dir']

        cls.amplicon_matrix = cls.read_mock('AmpliconMatrix.json')
        cls.attribute_mapping = cls.read_mock('AttributeMapping.json')
        cls.parsed_attribute_mapping = cls.read_mock(
            'ParsedAttributeMapping.json')

        cls.params = {'upa': '1/2/3'}
        cls.impl.indexer.ws.get_objects2 = Mock()
Example #8
0
 def setUpClass(cls):
     token = os.environ.get('KB_AUTH_TOKEN', None)
     config_file = os.environ.get('KB_DEPLOYMENT_CONFIG', None)
     cls.cfg = {}
     config = ConfigParser()
     config.read(config_file)
     cls.tdir = os.path.dirname(os.path.realpath(__file__))
     with open(os.path.join(cls.tdir, 'meta.json.ex')) as f:
         cls.meta = json.loads(f.read())
     for nameval in config.items('jgi_mg_assembly_wdl'):
         cls.cfg[nameval[0]] = nameval[1]
     # Getting username from Auth profile for token
     authServiceUrl = cls.cfg['auth-service-url']
     auth_client = _KBaseAuth(authServiceUrl)
     user_id = auth_client.get_user(token)
     # WARNING: don't call any logging methods on the context object,
     # it'll result in a NoneType error
     cls.ctx = MethodContext(None)
     cls.ctx.update({
         'token':
         token,
         'user_id':
         user_id,
         'provenance': [{
             'service': 'jgi_mg_assembly_wdl',
             'method': 'please_never_use_it_in_production',
             'method_params': []
         }],
         'authenticated':
         1
     })
     cls.wsURL = cls.cfg['workspace-url']
     cls.wsClient = Workspace(cls.wsURL)
     cls.serviceImpl = jgi_mg_assembly_wdl(cls.cfg)
     cls.scratch = cls.cfg['scratch']
     cls.callback_url = os.environ['SDK_CALLBACK_URL']
     suffix = int(time.time() * 1000)
     cls.wsName = "test_jgi_mg_assemb_" + str(suffix)
     ret = cls.wsClient.create_workspace({'workspace': cls.wsName})  # noqa
     cls.testWS = 'KBaseTestData'
     cls.testReads = 'small.interlaced_reads'
Example #9
0
 def setUpClass(cls):
     token = environ.get('KB_AUTH_TOKEN', None)
     os.environ['USE_DP'] = "1"
     config_file = environ.get('KB_DEPLOYMENT_CONFIG', None)
     cls.NARRATIVE_TYPE = "KBaseNarrative.Narrative-4.0"
     cls.cfg = {}
     config = ConfigParser()
     config.read(config_file)
     for nameval in config.items('NarrativeService'):
         cls.cfg[nameval[0]] = nameval[1]
     authServiceUrl = cls.cfg.get('auth-service-url',
             "https://kbase.us/services/authorization/Sessions/Login")
     auth_client = _KBaseAuth(authServiceUrl)
     user_id = auth_client.get_user(token)
     # WARNING: don't call any logging methods on the context object,
     # it'll result in a NoneType error
     cls.ctx = MethodContext(None)
     cls.ctx.update({'token': token,
                     'user_id': user_id,
                     'provenance': [
                         {'service': 'NarrativeService',
                          'method': 'please_never_use_it_in_production',
                          'method_params': []
                          }],
                     'authenticated': 1})
     cls.wsURL = cls.cfg['workspace-url']
     cls.serviceWizardURL = cls.cfg['service-wizard']
     cls.wsClient1 = Workspace(cls.wsURL, token=token)
     cls.serviceImpl = NarrativeService(cls.cfg)
     cls.SetAPI_version = cls.cfg['setapi-version']
     cls.DataPalette_version = cls.cfg['datapaletteservice-version']
     cls.intro_text_file = cls.cfg['intro-markdown-file']
     # Second user
     test_cfg_file = '/kb/module/work/test.cfg'
     test_cfg_text = "[test]\n"
     with open(test_cfg_file, "r") as f:
         test_cfg_text += f.read()
     config = ConfigParser()
     config.readfp(io.StringIO(test_cfg_text))
     test_cfg_dict = dict(config.items("test"))
     if 'test_token2' not in test_cfg_dict:
         raise ValueError("Configuration in <module>/test_local/test.cfg file should " +
                          "include second user credentials ('test_token2' key)")
     token2 = test_cfg_dict['test_token2']
     user2 = auth_client.get_user(token2)
     print(("Test user2: " + user2))
     cls.ctx2 = MethodContext(None)
     cls.ctx2.update({'token': token2,
                      'user_id': user2,
                      'provenance': [
                         {'service': 'NarrativeService',
                          'method': 'please_never_use_it_in_production',
                          'method_params': []
                          }],
                      'authenticated': 1})
     cls.wsClient2 = Workspace(cls.wsURL, token=token2)
     cls.wsClients = [cls.wsClient1, cls.wsClient2]
     cls.createdWorkspaces = [[], []]
     # Example objects:
     cls.example_ws_name = cls.createWsStatic(0)
     # Reads
     cls.example_reads_name = "example_reads.1"
     foft = FakeObjectsForTests(os.environ['SDK_CALLBACK_URL'])
     info1 = foft.create_fake_reads({'ws_name': cls.example_ws_name,
                                     'obj_names': [cls.example_reads_name]})[0]
     cls.example_reads_ref = str(info1[6]) + '/' + str(info1[0]) + '/' + str(info1[4])
     # # Genome
     # cls.example_genome_name = "example_genome.1"
     # foft = FakeObjectsForTests(os.environ['SDK_CALLBACK_URL'])
     # info2 = foft.create_fake_genomes({'ws_name': cls.example_ws_name,
     #                                   'obj_names': [cls.example_genome_name]})[0]
     # cls.example_genome_ref = str(info2[6]) + '/' + str(info2[0]) + '/' + str(info2[4])
     # Other objects
     foft.create_any_objects({'ws_name': cls.example_ws_name,
                              'obj_names': ['any_obj_' + str(i) for i in range(0, 30)]})