Esempio n. 1
0
 def __init__(self):
     submod = get_service_name() or 'SetAPI'
     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_SetAPI.get_reads_set_v1,
                          name='SetAPI.get_reads_set_v1',
                          types=[dict])
     self.method_authentication[
         'SetAPI.get_reads_set_v1'] = 'optional'  # noqa
     self.rpc_service.add(impl_SetAPI.save_reads_set_v1,
                          name='SetAPI.save_reads_set_v1',
                          types=[dict])
     self.method_authentication[
         'SetAPI.save_reads_set_v1'] = 'required'  # noqa
     self.rpc_service.add(impl_SetAPI.get_assembly_set_v1,
                          name='SetAPI.get_assembly_set_v1',
                          types=[dict])
     self.method_authentication[
         'SetAPI.get_assembly_set_v1'] = 'optional'  # noqa
     self.rpc_service.add(impl_SetAPI.save_assembly_set_v1,
                          name='SetAPI.save_assembly_set_v1',
                          types=[dict])
     self.method_authentication['SetAPI.save_assembly_set_v1'] = 'required'
     self.rpc_service.add(impl_SetAPI.get_genome_set_v1,
                          name='SetAPI.get_genome_set_v1',
                          types=[dict])
     self.method_authentication['SetAPI.get_genome_set_v1'] = 'optional'
     self.rpc_service.add(impl_SetAPI.save_genome_set_v1,
                          name='SetAPI.save_genome_set_v1',
                          types=[dict])
     self.method_authentication['SetAPI.save_genome_set_v1'] = 'required'
     self.rpc_service.add(impl_SetAPI.list_sets,
                          name='SetAPI.list_sets',
                          types=[dict])
     self.method_authentication['SetAPI.list_sets'] = 'optional'  # noqa
     self.rpc_service.add(impl_SetAPI.get_set_items,
                          name='SetAPI.get_set_items',
                          types=[dict])
     self.method_authentication['SetAPI.get_set_items'] = 'optional'  # noqa
     self.rpc_service.add(impl_SetAPI.status,
                          name='SetAPI.status',
                          types=[dict])
     authurl = config.get(AUTH) if config else None
     self.auth_client = _KBaseAuth(authurl)
Esempio n. 2
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('SetAPI'):
            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': 'SetAPI',
                'method': 'please_never_use_it_in_production',
                'method_params': []
            }],
            'authenticated':
            1
        })
        cls.wsURL = cls.cfg['workspace-url']
        cls.wsClient = workspaceService(cls.wsURL, token=token)
        cls.serviceImpl = SetAPI(cls.cfg)

        # setup data at the class level for now (so that the code is run
        # once for all tests, not before each test case.  Not sure how to
        # do that outside this function..)
        suffix = int(time.time() * 1000)
        wsName = "test_SetAPI_" + str(suffix)
        cls.wsClient.create_workspace({'workspace': wsName})
        cls.wsName = wsName

        foft = FakeObjectsForTests(os.environ['SDK_CALLBACK_URL'])

        # Make fake genomes
        [fake_genome, fake_genome2] = foft.create_fake_genomes({
            "ws_name":
            wsName,
            "obj_names": ["fake_genome", "fake_genome2"]
        })
        cls.genome_refs = [info_to_ref(fake_genome), info_to_ref(fake_genome2)]

        # Make some fake feature sets
        cls.featureset_refs = [
            make_fake_feature_set("feature_set_{}".format(i),
                                  cls.genome_refs[0], wsName, cls.wsClient)
            for i in range(3)
        ]
Esempio n. 3
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('SetAPI'):
            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': 'SetAPI',
                'method': 'please_never_use_it_in_production',
                'method_params': []
            }],
            'authenticated':
            1
        })
        cls.wsURL = cls.cfg['workspace-url']
        cls.wsClient = workspaceService(cls.wsURL, token=token)
        cls.serviceImpl = SetAPI(cls.cfg)

        # setup data at the class level for now (so that the code is run
        # once for all tests, not before each test case.  Not sure how to
        # do that outside this function..)
        suffix = int(time.time() * 1000)
        wsName = "test_SetAPI_" + str(suffix)
        ret = cls.wsClient.create_workspace({'workspace': wsName})
        cls.wsName = wsName

        foft = FakeObjectsForTests(os.environ['SDK_CALLBACK_URL'])
        [info1, info2, info3] = foft.create_fake_reads({
            'ws_name':
            wsName,
            'obj_names': ['reads1', 'reads2', 'reads3']
        })
        cls.read1ref = str(info1[6]) + '/' + str(info1[0]) + '/' + str(
            info1[4])
        cls.read2ref = str(info2[6]) + '/' + str(info2[0]) + '/' + str(
            info2[4])
        cls.read3ref = str(info3[6]) + '/' + str(info3[0]) + '/' + str(
            info3[4])

        cls.fake_sampleset_ref = make_fake_sampleset(
            "test_sampleset", [cls.read1ref, cls.read2ref, cls.read3ref],
            ['wt', 'cond1', 'cond2'], cls.wsName, cls.wsClient)
Esempio n. 4
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('SetAPI'):
            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': 'SetAPI',
                             'method': 'please_never_use_it_in_production',
                             'method_params': []
                             }],
                        'authenticated': 1})
        cls.wsURL = cls.cfg['workspace-url']
        cls.wsClient = workspaceService(cls.wsURL, token=token)
        cls.serviceImpl = SetAPI(cls.cfg)

        # setup data at the class level for now (so that the code is run
        # once for all tests, not before each test case.  Not sure how to
        # do that outside this function..)
        suffix = int(time.time() * 1000)
        wsName = "test_SetAPI_" + str(suffix)
        ret = cls.wsClient.create_workspace({'workspace': wsName})
#        wsName = 'pranjan77:1477441032423'
        cls.wsName = wsName
        # copy test file to scratch area
        fna_filename = "seq.fna"
        fna_path = os.path.join(cls.cfg['scratch'], fna_filename)
        shutil.copy(os.path.join("data", fna_filename), fna_path)

        ru = AssemblyUtil(os.environ['SDK_CALLBACK_URL'])
        ws_obj_name = 'MyNewAssembly'
        cls.assembly1ref = ru.save_assembly_from_fasta( 
            {
                'file':{'path':fna_path},
                'workspace_name':wsName,
                'assembly_name':'assembly_obj_1'
            })
        cls.assembly2ref = ru.save_assembly_from_fasta( 
            {
                'file':{'path':fna_path},
                'workspace_name':wsName,
                'assembly_name':'assembly_obj_2'
            })
Esempio n. 5
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('SetAPI'):
            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': 'SetAPI',
                'method': 'please_never_use_it_in_production',
                'method_params': []
            }],
            'authenticated':
            1
        })
        cls.wsURL = cls.cfg['workspace-url']
        cls.wsClient = workspaceService(cls.wsURL, token=token)
        cls.serviceImpl = SetAPI(cls.cfg)
        cls.dfu = DataFileUtil(os.environ['SDK_CALLBACK_URL'])

        # setup data at the class level for now (so that the code is run
        # once for all tests, not before each test case.  Not sure how to
        # do that outside this function..)
        suffix = int(time.time() * 1000)
        wsName = "test_SetAPI_" + str(suffix)
        ret = cls.wsClient.create_workspace({'workspace': wsName})
        cls.wsName = wsName
        cls.prepare_data()
Esempio n. 6
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('SetAPI'):
            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': 'SetAPI',
                'method': 'please_never_use_it_in_production',
                'method_params': []
            }],
            'authenticated':
            1
        })
        cls.wsURL = cls.cfg['workspace-url']
        cls.wsClient = workspaceService(cls.wsURL, token=token)
        cls.serviceImpl = SetAPI(cls.cfg)

        # setup data at the class level for now (so that the code is run
        # once for all tests, not before each test case.  Not sure how to
        # do that outside this function..)
        suffix = int(time.time() * 1000)
        wsName = "test_SetAPI_" + str(suffix)
        cls.wsClient.create_workspace({'workspace': wsName})
        cls.wsName = wsName

        foft = FakeObjectsForTests(os.environ['SDK_CALLBACK_URL'])

        # Make a fake genome
        [fake_genome, fake_genome2] = foft.create_fake_genomes({
            "ws_name":
            wsName,
            "obj_names": ["fake_genome", "fake_genome2"]
        })
        cls.genome_refs = [info_to_ref(fake_genome), info_to_ref(fake_genome2)]

        # Make some fake reads objects
        fake_reads_list = foft.create_fake_reads({
            'ws_name':
            wsName,
            "obj_names": ["reads1", "reads2", "reads3"]
        })
        cls.alignment_refs = list()
        cls.reads_refs = list()

        # Make some fake alignments referencing those reads and genome
        dummy_filename = "dummy.txt"
        cls.dummy_path = os.path.join(cls.cfg['scratch'], dummy_filename)
        shutil.copy(os.path.join("data", dummy_filename), cls.dummy_path)

        for idx, reads_info in enumerate(fake_reads_list):
            reads_ref = info_to_ref(reads_info)
            cls.reads_refs.append(reads_ref)
            cls.alignment_refs.append(
                make_fake_alignment(os.environ['SDK_CALLBACK_URL'],
                                    cls.dummy_path,
                                    "fake_alignment_{}".format(idx), reads_ref,
                                    cls.genome_refs[0], wsName, cls.wsClient))

        # Need a fake annotation to get the expression objects
        cls.annotation_ref = make_fake_annotation(
            os.environ['SDK_CALLBACK_URL'], cls.dummy_path, "fake_annotation",
            wsName, cls.wsClient)

        # Now we can phony up some expression objects to build sets out of.
        # name, genome_ref, annotation_ref, alignment_ref, ws_name, ws_client
        cls.expression_refs = list()
        for idx, alignment_ref in enumerate(cls.alignment_refs):
            cls.expression_refs.append(
                make_fake_expression(os.environ['SDK_CALLBACK_URL'],
                                     cls.dummy_path,
                                     "fake_expression_{}".format(idx),
                                     cls.genome_refs[0], cls.annotation_ref,
                                     alignment_ref, wsName, cls.wsClient))

        # Make a fake RNASeq Alignment Set object
        # Make a fake RNASeqSampleSet
        cls.sampleset_ref = make_fake_sampleset("fake_sampleset", [], [],
                                                wsName, cls.wsClient)

        # Finally, make a couple fake RNASeqAlignmentSts objects from those alignments
        cls.fake_rnaseq_alignment_set = make_fake_old_alignment_set(
            "fake_rnaseq_alignment_set", cls.reads_refs, cls.genome_refs[0],
            cls.sampleset_ref, cls.alignment_refs, wsName, cls.wsClient)

        # Make a fake RNASeq Expression Set object
        cls.fake_rnaseq_expression_set = make_fake_old_expression_set(
            "fake_rnaseq_expression_set", cls.genome_refs[0],
            cls.sampleset_ref, cls.alignment_refs,
            cls.fake_rnaseq_alignment_set, cls.expression_refs, wsName,
            cls.wsClient, True)