Пример #1
0
 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('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.wsClient = Workspace(cls.wsURL, token=token)
     cls.serviceImpl = NarrativeService(cls.cfg)
 def __init__(self):
     submod = get_service_name() or 'DataPaletteService'
     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_DataPaletteService.list_data,
                          name='DataPaletteService.list_data',
                          types=[dict])
     self.method_authentication[
         'DataPaletteService.list_data'] = 'optional'  # noqa
     self.rpc_service.add(impl_DataPaletteService.add_to_palette,
                          name='DataPaletteService.add_to_palette',
                          types=[dict])
     self.method_authentication[
         'DataPaletteService.add_to_palette'] = 'required'  # noqa
     self.rpc_service.add(impl_DataPaletteService.remove_from_palette,
                          name='DataPaletteService.remove_from_palette',
                          types=[dict])
     self.method_authentication[
         'DataPaletteService.remove_from_palette'] = 'required'  # noqa
     self.rpc_service.add(impl_DataPaletteService.copy_palette,
                          name='DataPaletteService.copy_palette',
                          types=[dict])
     self.method_authentication[
         'DataPaletteService.copy_palette'] = 'required'  # noqa
     self.rpc_service.add(impl_DataPaletteService.set_palette_for_ws,
                          name='DataPaletteService.set_palette_for_ws',
                          types=[dict])
     self.method_authentication[
         'DataPaletteService.set_palette_for_ws'] = 'required'  # noqa
     self.rpc_service.add(impl_DataPaletteService.status,
                          name='DataPaletteService.status',
                          types=[dict])
     authurl = config.get(AUTH) if config else None
     self.auth_client = _KBaseAuth(authurl)
Пример #3
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)
Пример #4
0
 def _setup_ctx(self):
     self.token = environ.get('KB_AUTH_TOKEN', None)
     authServiceUrl = self._cfg['auth-service-url']
     auth_client = _KBaseAuth(authServiceUrl)
     user_id = auth_client.get_user(self.token)
     self._ctx = MethodContext(None)
     self._ctx.update({
         'token':
         self.token,
         'user_id':
         user_id,
         'provenance': [{
             'service': 'DataPaletteService',
             'method': 'please_never_use_it_in_production',
             'method_params': []
         }],
         'authenticated':
         1
     })
 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('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(StringIO.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)]
     })