def setUpClass(cls): token = os.environ.get('KB_AUTH_TOKEN', None) # 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, 'provenance': [{ 'service': 'GenomeAnnotationAPI', 'method': 'please_never_use_it_in_production', 'method_params': [] }], 'authenticated': 1 }) config_file = os.environ.get('KB_DEPLOYMENT_CONFIG', None) config = ConfigParser.ConfigParser() config.read(config_file) cls.cfg = {n[0]: n[1] for n in config.items('GenomeAnnotationAPI')} cls.ws = Workspace(cls.cfg['workspace-url'], token=token) cls.impl = GenomeAnnotationAPI(cls.cfg) cls.ga_ref = "8020/81/1" cls.genome_ref = "8020/83/1"
def setUpClass(cls): print('Setting up class') token = os.environ.get('KB_AUTH_TOKEN', None) config_file = os.environ.get('KB_DEPLOYMENT_CONFIG', None) config = configparser.ConfigParser() config.read(config_file) cls.cfg = {n[0]: n[1] for n in config.items('GenomeAnnotationAPI')} 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': 'GenomeAnnotationAPI', 'method': 'please_never_use_it_in_production', 'method_params': [] }], 'authenticated': 1}) cls.ws = Workspace(cls.cfg['workspace-url'], token=token) cls.impl = GenomeAnnotationAPI(cls.cfg) # 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.ConfigParser() config.read_file(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')") token2 = test_cfg_dict['test_token2'] user2 = auth_client.get_user(token2) 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}) # create one WS for all tests suffix = int(time.time() * 1000) wsName = "test_GenomeAnnotationAPI_" + str(suffix) ret = cls.ws.create_workspace({'workspace': wsName}) cls.wsName = wsName # preload with reference data with open ('data/rhodobacter.json', 'r') as file: data_str=file.read() data = json.loads(data_str) # save old genome info = cls.impl.save_one_genome_v1(cls.ctx, { 'workspace': wsName, 'name': "rhodobacter", 'data': data, })[0]['info'] cls.rhodobacter_ref = str(info[6]) +'/' + str(info[0]) + '/' + str(info[4]) print('created rhodobacter test genome: ' + cls.rhodobacter_ref) assembly_file_path = os.path.join(cls.cfg['scratch'], 'e_coli_assembly.fasta') shutil.copy('data/e_coli_assembly.fasta', assembly_file_path) au = AssemblyUtil(os.environ['SDK_CALLBACK_URL']) assembly_ref = au.save_assembly_from_fasta({ 'workspace_name': cls.wsName, 'assembly_name': 'ecoli.assembly', 'file': {'path': assembly_file_path} }) data = json.load(open('data/new_ecoli_genome.json')) data['assembly_ref'] = assembly_ref # save new genome save_info = { 'workspace': wsName, 'objects': [{ 'type': 'KBaseGenomes.Genome', 'data': data, 'name': 'new_ecoli' }] } info = cls.ws.save_objects(save_info)[0] cls.new_genome_ref = str(info[6]) + '/' + str(info[0]) + '/' + str( info[4]) print('created new test genome')
def setUpClass(cls): token = os.environ.get('KB_AUTH_TOKEN', None) config_file = os.environ.get('KB_DEPLOYMENT_CONFIG', None) config = configparser.ConfigParser() config.read(config_file) cls.cfg = {n[0]: n[1] for n in config.items('GenomeAnnotationAPI')} 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': 'GenomeAnnotationAPI', 'method': 'please_never_use_it_in_production', 'method_params': [] }], 'authenticated': 1 }) cls.ws = Workspace(cls.cfg['workspace-url'], token=token) cls.impl = GenomeAnnotationAPI(cls.cfg) test_gbk_file = "/kb/module/test/data/kb_g.399.c.1.gbk" temp_gbk_file = "/kb/module/work/tmp/kb_g.399.c.1.gbk" shutil.copy(test_gbk_file, temp_gbk_file) suffix = int(time.time() * 1000) wsName = "test_GenomeAnnotationAPI_" + str(suffix) cls.ws.create_workspace({'workspace': wsName}) cls.wsName = wsName data = json.load(open('data/rhodobacter_contigs.json')) # save to ws save_info = { 'workspace': wsName, 'objects': [{ 'type': 'KBaseGenomes.ContigSet', 'data': data, 'name': 'rhodo_contigs' }] } info = cls.ws.save_objects(save_info)[0] contigset_ref = str(info[6]) + '/' + str(info[0]) + '/' + str(info[4]) data = json.load(open('data/rhodobacter.json')) data['contigset_ref'] = contigset_ref # save to ws info = cls.impl.save_one_genome_v1(cls.ctx, { 'workspace': wsName, 'name': "rhodobacter", 'data': data, })[0]['info'] cls.old_genome_ref = str(info[6]) + '/' + str(info[0]) + '/' + str( info[4]) print('created old test genome') assembly_file_path = os.path.join(cls.cfg['scratch'], 'e_coli_assembly.fasta') shutil.copy('data/e_coli_assembly.fasta', assembly_file_path) au = AssemblyUtil(os.environ['SDK_CALLBACK_URL']) assembly_ref = au.save_assembly_from_fasta({ 'workspace_name': cls.wsName, 'assembly_name': 'ecoli.assembly', 'file': { 'path': assembly_file_path } }) data = json.load(open('data/new_ecoli_genome.json')) data['assembly_ref'] = assembly_ref # save to ws save_info = { 'workspace': wsName, 'objects': [{ 'type': 'KBaseGenomes.Genome', 'data': data, 'name': 'new_ecoli' }] } info = cls.ws.save_objects(save_info)[0] cls.new_genome_ref = str(info[6]) + '/' + str(info[0]) + '/' + str( info[4]) print('created new test genome')
def setUpClass(cls): print('Setting up class') token = os.environ.get('KB_AUTH_TOKEN', None) config_file = os.environ.get('KB_DEPLOYMENT_CONFIG', None) config = ConfigParser.ConfigParser() config.read(config_file) cls.cfg = {n[0]: n[1] for n in config.items('GenomeAnnotationAPI')} 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': 'GenomeAnnotationAPI', 'method': 'please_never_use_it_in_production', 'method_params': [] }], 'authenticated': 1 }) cls.ws = Workspace(cls.cfg['workspace-url'], token=token) cls.impl = GenomeAnnotationAPI(cls.cfg) # 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.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')") token2 = test_cfg_dict['test_token2'] user2 = auth_client.get_user(token2) 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 }) # create one WS for all tests suffix = int(time.time() * 1000) wsName = "test_GenomeAnnotationAPI_" + str(suffix) ret = cls.ws.create_workspace({'workspace': wsName}) cls.wsName = wsName # preload with reference data with open('data/rhodobacter.json', 'r') as file: data_str = file.read() data = json.loads(data_str) data['cdss'] = [] # Support for new Genome type structure data['mrnas'] = [] # Support for new Genome type structure # save to ws result = cls.ws.save_objects({ 'workspace': wsName, 'objects': [{ 'type': 'KBaseGenomes.Genome', 'data': data, 'name': 'rhodobacter' }] }) info = result[0] cls.rhodobacter_ref = str(info[6]) + '/' + str(info[0]) + '/' + str( info[4]) print('created rhodobacter test genome: ' + cls.rhodobacter_ref)
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 'GenomeAnnotationAPI'): retconfig[nameval[0]] = nameval[1] return retconfig config = get_config() from GenomeAnnotationAPI.GenomeAnnotationAPIImpl import GenomeAnnotationAPI # noqa @IgnorePep8 impl_GenomeAnnotationAPI = GenomeAnnotationAPI(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):