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 = os.environ.get("KB_AUTH_TOKEN") config_file = os.environ.get("KB_DEPLOYMENT_CONFIG") cls.cfg = dict() config = ConfigParser() config.read(config_file) for nameval in config.items("NarrativeService"): cls.cfg[nameval[0]] = nameval[1] if "auth-service-url" not in cls.cfg: raise RuntimeError("Missing auth-service-url from config") auth_client = KBaseAuth(cls.cfg["auth-service-url"]) user_id = auth_client.get_user(token) cls.ctx = MethodContext(None) cls.ctx.update({ "token": token, "user_id": user_id, "provenance": [{ "service": "NarrativeService", "method": "please_never_use_it_in_producation", "method_params": [] }], "authenticated": 1 }) cls.service_impl = NarrativeService(cls.cfg)
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)
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)] })
def get_config(): if not get_config_file(): return None retconfig = {} config = ConfigParser() config.read(get_config_file()) for nameval in config.items(get_service_name() or 'NarrativeService'): retconfig[nameval[0]] = nameval[1] return retconfig config = get_config() from NarrativeService.NarrativeServiceImpl import NarrativeService # noqa @IgnorePep8 impl_NarrativeService = NarrativeService(config) class JSONObjectEncoder(json.JSONEncoder): def default(self, obj): if isinstance(obj, set): return list(obj) if isinstance(obj, frozenset): return list(obj) if hasattr(obj, 'toJSONable'): return obj.toJSONable() return json.JSONEncoder.default(self, obj) class JSONRPCServiceCustom(JSONRPCService): def call(self, ctx, jsondata):