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('GenericsAPI'): 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': 'GenericsAPI', 'method': 'please_never_use_it_in_production', 'method_params': [] }], 'authenticated': 1}) cls.wsURL = cls.cfg['workspace-url'] cls.wsClient = workspaceService(cls.wsURL) cls.serviceImpl = GenericsAPI(cls.cfg) cls.scratch = cls.cfg['scratch'] cls.callback_url = os.environ['SDK_CALLBACK_URL'] cls.dfu = DataFileUtil(cls.callback_url) cls.pca_util = PCAUtil(cls.cfg) suffix = int(time.time() * 1000) cls.wsName = "test_pca_util_" + str(suffix) ret = cls.wsClient.create_workspace({'workspace': cls.wsName}) cls.wsId = ret[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('GenericsAPI'): 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(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': 'GenericsAPI', 'method': 'please_never_use_it_in_production', 'method_params': [] }], 'authenticated': 1 }) cls.wsURL = cls.cfg['workspace-url'] cls.wsClient = workspaceService(cls.wsURL) cls.serviceImpl = GenericsAPI(cls.cfg) cls.scratch = cls.cfg['scratch'] cls.callback_url = os.environ['SDK_CALLBACK_URL'] cls.shockURL = cls.cfg['shock-url'] cls.dfu = DataFileUtil(cls.callback_url) cls.sample_uploader = sample_uploader(cls.callback_url, service_ver="dev") cls.sample_url = cls.cfg.get('kbase-endpoint') + '/sampleservice' cls.sample_ser = SampleService(cls.sample_url) cls.hs = HandleService(url=cls.cfg['handle-service-url'], token=cls.token) suffix = int(time.time() * 1000) cls.wsName = "test_GenericsAPI_" + str(suffix) ret = cls.wsClient.create_workspace({'workspace': cls.wsName}) cls.wsId = ret[0] small_file = os.path.join(cls.scratch, 'test.txt') with open(small_file, "w") as f: f.write("empty content") cls.test_shock = cls.dfu.file_to_shock({ 'file_path': small_file, 'make_handle': True }) cls.handles_to_delete = [] cls.nodes_to_delete = [] cls.handles_to_delete.append(cls.test_shock['handle']['hid']) cls.nodes_to_delete.append(cls.test_shock['shock_id']) cls.prepare_data()
def setUpClass(cls): cls.maxDiff = 70000 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('GenericsAPI'): 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(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': 'GenericsAPI', 'method': 'please_never_use_it_in_production', 'method_params': [] }], 'authenticated': 1}) cls.wsURL = cls.cfg['workspace-url'] cls.wsClient = workspaceService(cls.wsURL) cls.serviceImpl = GenericsAPI(cls.cfg) cls.serviceUtils = AttributesUtil(cls.cfg) cls.shockURL = cls.cfg['shock-url'] cls.scratch = cls.cfg['scratch'] cls.callback_url = os.environ['SDK_CALLBACK_URL'] cls.dfu = DataFileUtil(cls.callback_url) cls.hs = HandleService(url=cls.cfg['handle-service-url'], token=cls.token) suffix = int(time.time() * 1000) cls.wsName = "test_CompoundSetUtils_" + str(suffix) ret = cls.wsClient.create_workspace({'workspace': cls.wsName}) cls.wsId = ret[0] cls.attribute_mapping = json.load(open('data/AM1.json')) info = cls.dfu.save_objects({ "id": cls.wsId, "objects": [{ "type": "KBaseExperiments.AttributeMapping", "data": cls.attribute_mapping, "name": "test_cond_set" }] })[0] cls.attribute_mapping_ref = "%s/%s/%s" % (info[6], info[0], info[4]) cls.attribute_mapping_2 = json.load(open('data/AM2.json')) small_file = os.path.join(cls.scratch, 'test.txt') with open(small_file, "w") as f: f.write("empty content") cls.test_shock = cls.dfu.file_to_shock({'file_path': small_file, 'make_handle': True}) cls.handles_to_delete = [] cls.nodes_to_delete = [] cls.handles_to_delete.append(cls.test_shock['handle']['hid']) cls.nodes_to_delete.append(cls.test_shock['shock_id'])
def setUpClass(cls): cls.maxDiff = 70000 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('GenericsAPI'): 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': 'GenericsAPI', 'method': 'please_never_use_it_in_production', 'method_params': [] }], 'authenticated': 1}) cls.wsURL = cls.cfg['workspace-url'] cls.wsClient = workspaceService(cls.wsURL) cls.serviceImpl = GenericsAPI(cls.cfg) cls.serviceUtils = AttributesUtil(cls.cfg) cls.scratch = cls.cfg['scratch'] cls.callback_url = os.environ['SDK_CALLBACK_URL'] cls.dfu = DataFileUtil(cls.callback_url) suffix = int(time.time() * 1000) #cls.wsName = "test_CompoundSetUtils_" + str(suffix) cls.wsName = "man4ish_gupta:narrative_1568644342277" ret = cls.wsClient.create_workspace({'workspace': cls.wsName}) #exit(cls.wsId) #cls.wsId = ret[0] cls.wsid = 44071 cls.attribute_mapping = json.load(open('data/AM1.json')) info = cls.dfu.save_objects({ "id": cls.wsId, "objects": [{ "type": "KBaseExperiments.AttributeMapping", "data": cls.attribute_mapping, "name": "test_cond_set" }] })[0] cls.attribute_mapping_ref = "%s/%s/%s" % (info[6], info[0], info[4]) cls.attribute_mapping_2 = json.load(open('data/AM2.json'))
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 'GenericsAPI'): retconfig[nameval[0]] = nameval[1] return retconfig config = get_config() from GenericsAPI.GenericsAPIImpl import GenericsAPI # noqa @IgnorePep8 impl_GenericsAPI = GenericsAPI(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):
def test_link_matrix_to_samples(self): matrix_obj = { 'data': { 'col_ids': [ 'Sample0', 'Sample1', 'Sample2', 'Sample3', ] } } sample_set_obj = { 'samples': [{ 'name': 'Sample0', 'id': '0', 'version': 100, }, { 'name': 'Sample1', 'id': '1', 'version': 100, }, { 'name': 'Sample2', 'id': '2', 'version': 100, }, { 'name': 'Sample4', 'id': '4', 'version': 100 }] } get_sample_rets = [ { 'node_tree': [{ 'id': 'Sample0' }] }, { 'node_tree': [{ 'id': 'Sample1' }] }, { 'node_tree': [{ 'id': 'Sample2' }] }, ] mock_dfu = create_autospec(DataFileUtil, instance=True, spec_set=True) mock_dfu.get_objects.return_value = { 'data': [{ 'data': sample_set_obj }] } mock_ss = create_autospec(SampleService, instance=True, spec_set=True) mock_ss.get_sample.side_effect = get_sample_rets serviceImpl = GenericsAPI(self.cfg) serviceImpl.matrix_util.dfu = mock_dfu serviceImpl.matrix_util.sample_ser = mock_ss serviceImpl.matrix_util._link_matrix_to_samples( 'dummy/matrix/ref', matrix_obj, 'dummy/ss/ref', ) mock_ss.create_data_link.assert_has_calls([ call({ 'upa': 'dummy/matrix/ref', 'dataid': 'Sample0', 'id': '0', 'version': 100, 'node': 'Sample0', 'update': 1, }), call({ 'upa': 'dummy/matrix/ref', 'dataid': 'Sample1', 'id': '1', 'version': 100, 'node': 'Sample1', 'update': 1, }), call({ 'upa': 'dummy/matrix/ref', 'dataid': 'Sample2', 'id': '2', 'version': 100, 'node': 'Sample2', 'update': 1, }) ])