Пример #1
0
def _initialize_api(client_id,
                    client_secret,
                    base_url,
                    username,
                    password,
                    timeout_multiplier,
                    max_wait_time=20):
    """
    Creates the ApiCalls object from the api layer.
    Sets the instance to use the global _api_instance variable so it behaves as a singleton that can be easily re-init

    :param client_id:
    :param client_secret:
    :param base_url:
    :param username:
    :param password:
    :param timeout_multiplier:
    :param max_wait_time:
    :return: The ApiCalls instance
    """
    global _api_instance
    _api_instance = api.ApiCalls(client_id, client_secret, base_url, username,
                                 password, timeout_multiplier, max_wait_time)
    if not base_url.endswith('/api/'):
        logging.warning(
            "base_url does not end in /api/, this configuration might be incorrect"
        )
    _api_instance = api.ApiCalls(client_id, client_secret, base_url, username,
                                 password, max_wait_time)
    return _api_instance
Пример #2
0
 def setUp(self):
     print("\nStarting " + self.__module__ + ": " + self._testMethodName)
     self.test_api = api.ApiCalls(
         client_id=tests_integration.client_id,
         client_secret=tests_integration.client_secret,
         base_url=tests_integration.base_url,
         username=tests_integration.username,
         password=tests_integration.password)
Пример #3
0
    def test_valid_assemblies_directory_upload(self):
        """
        Test a valid directory of assemblies for upload end to end
        :return:
        """
        # Set our sample config file to use miseq parser and the correct irida credentials
        self.write_to_config_file(
            client_id=tests_integration.client_id,
            client_secret=tests_integration.client_secret,
            username=tests_integration.username,
            password=tests_integration.password,
            base_url=tests_integration.base_url,
            parser="directory")

        # instance an api
        test_api = api.ApiCalls(client_id=tests_integration.client_id,
                                client_secret=tests_integration.client_secret,
                                base_url=tests_integration.base_url,
                                username=tests_integration.username,
                                password=tests_integration.password)

        # Create a test project, the uploader does not make new projects on its own
        # so one must exist to upload samples into
        # This may not be the project that the files get uploaded to,
        # but one will be made in the case this is the only test being run
        project_name = "test_project_assemblies"
        project_description = "test_project_description_assemblies"
        project = model.Project(name=project_name,
                                description=project_description)
        test_api.send_project(project)
        # We always upload to project "1" so that tests will be consistent no matter how many / which tests are run
        project_id = "1"

        # Do the upload
        upload_result = upload_run_single_entry(directory=path.join(
            path_to_module, "fake_assemblies_data"),
                                                upload_assemblies=True)

        # Make sure the upload was a success
        self.assertEqual(upload_result.exit_code, 0)

        # Verify the files were uploaded
        sample_list = test_api.get_samples(project_id)
        test_sample = sample_list[0]
        sequence_files = test_api.get_assemblies_files(project_id,
                                                       test_sample.sample_name)
        self.assertEqual(len(sequence_files), 1)
        self.assertEqual(sequence_files[0]['fileName'], 'file_1.fasta')
Пример #4
0
def _initialize_api(client_id, client_secret, base_url, username, password, max_wait_time=20):
    """
    Creates the ApiCalls object from the api layer.
    Sets the instance to use the global _api_instance variable so it behaves as a singleton that can be easily re-init

    :param client_id:
    :param client_secret:
    :param base_url:
    :param username:
    :param password:
    :param max_wait_time:
    :return: The ApiCalls instance
    """
    global _api_instance
    _api_instance = api.ApiCalls(client_id, client_secret, base_url, username, password, max_wait_time)
    return _api_instance
Пример #5
0
    def test_upload_to_nonexistent_project(self):
        """
        Everything is correct except the sample sheet file specifies an invalid project
        Samples should not be uploaded
        :return:
        """
        # try to upload to a non existent project
        # Set our sample config file to use miseq parser and the correct irida credentials
        self.write_to_config_file(
            client_id=tests_integration.client_id,
            client_secret=tests_integration.client_secret,
            username=tests_integration.username,
            password=tests_integration.password,
            base_url=tests_integration.base_url,
            parser="miseq",
            readonly=False)

        # instance an api
        test_api = api.ApiCalls(client_id=tests_integration.client_id,
                                client_secret=tests_integration.client_secret,
                                base_url=tests_integration.base_url,
                                username=tests_integration.username,
                                password=tests_integration.password)

        # Create a test project, the uploader does not make new projects on its own
        # so one must exist to upload samples into
        # This may not be the project that the files get uploaded to,
        # but one will be made in the case this is the only test being run
        project_name = "test_project"
        project_description = "test_project_description"
        project = model.Project(name=project_name,
                                description=project_description)
        test_api.send_project(project)

        # Do the upload
        upload_result = upload_run_single_entry(
            path.join(path_to_module, "fake_ngs_data_nonexistent_project"))

        # Make sure the upload was a failure
        self.assertEqual(upload_result.exit_code, 1)

        # Verify that the project does not exist
        project_id = "1000"
        with self.assertRaises(api.exceptions.IridaKeyError):
            test_api.get_samples(project_id)
Пример #6
0
    def test_invalid_read_only_miseq_upload(self):
        """
        Test failing to upload a readonly miseq directory because readonly is turned off
        :return:
        """
        # Set our sample config file to use miseq parser and the correct irida credentials
        self.write_to_config_file(
            client_id=tests_integration.client_id,
            client_secret=tests_integration.client_secret,
            username=tests_integration.username,
            password=tests_integration.password,
            base_url=tests_integration.base_url,
            parser="miseq",
            readonly=False)

        # instance an api
        test_api = api.ApiCalls(client_id=tests_integration.client_id,
                                client_secret=tests_integration.client_secret,
                                base_url=tests_integration.base_url,
                                username=tests_integration.username,
                                password=tests_integration.password)

        # Create a test project, the uploader does not make new projects on its own
        # so one must exist to upload samples into
        # This may not be the project that the files get uploaded to,
        # but one will be made in the case this is the only test being run
        project_name = "test_read_only_project_fail"
        project_description = "test_project_description"
        project = model.Project(name=project_name,
                                description=project_description)
        test_api.send_project(project)

        # try the upload
        upload_result = upload_run_single_entry(path.join(
            path_to_module, "fake_ngs_data_read_only"),
                                                force_upload=False,
                                                upload_mode=api.MODE_DEFAULT)

        # Make sure the upload was a failure
        self.assertEqual(upload_result.exit_code, 1)
Пример #7
0
def generate_api_instance(config_in):
    '''
    PURPOSE:
        Generate api instance for IRIDA platform based on input keys found in csv file

    INPUTS:
        - KEY_CONFIG --> IRIDA Uploader config file

    RETURNS:
        - IRIDA_API --> API class instance based on the input keys given in the config
    '''

    config = configparser.ConfigParser()
    config.read(config_in)

    settings = config['Settings']

    irida_api = api.ApiCalls(settings['client_id'], settings['client_secret'],
                             settings['base_url'], settings['username'],
                             settings['password'])

    return irida_api
Пример #8
0
    def test_upload_parse_fail(self):
        """
        Given an invalid sample sheet, make sure that the upload does not happen
        :return:
        """
        # try to upload to a non existent project
        # Set our sample config file to use miseq parser and the correct irida credentials
        self.write_to_config_file(
            client_id=tests_integration.client_id,
            client_secret=tests_integration.client_secret,
            username=tests_integration.username,
            password=tests_integration.password,
            base_url=tests_integration.base_url,
            parser="miseq")

        # instance an api
        test_api = api.ApiCalls(client_id=tests_integration.client_id,
                                client_secret=tests_integration.client_secret,
                                base_url=tests_integration.base_url,
                                username=tests_integration.username,
                                password=tests_integration.password)

        # Create a test project, the uploader does not make new projects on its own
        # so one must exist to upload samples into
        # This may not be the project that the files get uploaded to,
        # but one will be made in the case this is the only test being run
        project_name = "test_project"
        project_description = "test_project_description"
        project = model.Project(name=project_name,
                                description=project_description)
        test_api.send_project(project)

        # Do the upload
        upload_result = upload_run_single_entry(
            path.join(path_to_module, "fake_ngs_data_parse_fail"))

        # Make sure the upload was a failure
        self.assertEqual(upload_result.exit_code, 1)
Пример #9
0
    def test_valid_miseq_upload(self):
        """
        Test a valid miseq directory for upload from end to end
        :return:
        """
        # Set our sample config file to use miseq parser and the correct irida credentials
        self.write_to_config_file(
            client_id=tests_integration.client_id,
            client_secret=tests_integration.client_secret,
            username=tests_integration.username,
            password=tests_integration.password,
            base_url=tests_integration.base_url,
            parser="miseq")

        # instance an api
        test_api = api.ApiCalls(client_id=tests_integration.client_id,
                                client_secret=tests_integration.client_secret,
                                base_url=tests_integration.base_url,
                                username=tests_integration.username,
                                password=tests_integration.password)

        # Create a test project, the uploader does not make new projects on its own
        # so one must exist to upload samples into
        # This may not be the project that the files get uploaded to,
        # but one will be made in the case this is the only test being run
        project_name = "test_project"
        project_description = "test_project_description"
        project = model.Project(name=project_name,
                                description=project_description)
        test_api.send_project(project)
        # We always upload to project "1" so that tests will be consistent no matter how many / which tests are run
        project_id = "1"

        # Do the upload
        upload_result = upload_run_single_entry(
            path.join(path_to_module, "fake_ngs_data"))

        # Make sure the upload was a success
        self.assertEqual(upload_result.exit_code, 0)

        # Verify the files were uploaded
        sample_list = test_api.get_samples(project_id)

        sample_1_found = False
        sample_2_found = False
        sample_3_found = False

        for sample in sample_list:
            if sample.sample_name in ["01-1111", "02-2222", "03-3333"]:
                if sample.sample_name == "01-1111":
                    sample_1_found = True
                    sequence_files = test_api.get_sequence_files(
                        project_id, sample.sample_name)
                    self.assertEqual(len(sequence_files), 2)
                    res_sequence_file_names = [
                        sequence_files[0]['fileName'],
                        sequence_files[1]['fileName']
                    ]
                    expected_sequence_file_names = [
                        '01-1111_S1_L001_R1_001.fastq.gz',
                        '01-1111_S1_L001_R2_001.fastq.gz'
                    ]
                    self.assertEqual(res_sequence_file_names.sort(),
                                     expected_sequence_file_names.sort())
                elif sample.sample_name == "02-2222":
                    sample_2_found = True
                    sequence_files = test_api.get_sequence_files(
                        project_id, sample.sample_name)
                    self.assertEqual(len(sequence_files), 2)
                    res_sequence_file_names = [
                        sequence_files[0]['fileName'],
                        sequence_files[1]['fileName']
                    ]
                    expected_sequence_file_names = [
                        '02-2222_S1_L001_R1_001.fastq.gz',
                        '02-2222_S1_L001_R2_001.fastq.gz'
                    ]
                    self.assertEqual(res_sequence_file_names.sort(),
                                     expected_sequence_file_names.sort())
                elif sample.sample_name == "03-3333":
                    sample_3_found = True
                    sequence_files = test_api.get_sequence_files(
                        project_id, sample.sample_name)
                    self.assertEqual(len(sequence_files), 2)
                    res_sequence_file_names = [
                        sequence_files[0]['fileName'],
                        sequence_files[1]['fileName']
                    ]
                    expected_sequence_file_names = [
                        '03-3333_S1_L001_R1_001.fastq.gz',
                        '03-3333_S1_L001_R2_001.fastq.gz'
                    ]
                    self.assertEqual(res_sequence_file_names.sort(),
                                     expected_sequence_file_names.sort())

        self.assertEqual(sample_1_found, True)
        self.assertEqual(sample_2_found, True)
        self.assertEqual(sample_3_found, True)
Пример #10
0
    def test_valid_directory_upload(self):
        """
        Test a valid directory for upload end to end
        :return:
        """
        # Set our sample config file to use miseq parser and the correct irida credentials
        self.write_to_config_file(
            client_id=tests_integration.client_id,
            client_secret=tests_integration.client_secret,
            username=tests_integration.username,
            password=tests_integration.password,
            base_url=tests_integration.base_url,
            parser="directory",
            readonly=False)

        # instance an api
        test_api = api.ApiCalls(client_id=tests_integration.client_id,
                                client_secret=tests_integration.client_secret,
                                base_url=tests_integration.base_url,
                                username=tests_integration.username,
                                password=tests_integration.password)

        # Create a test project, the uploader does not make new projects on its own
        # so one must exist to upload samples into
        # This may not be the project that the files get uploaded to,
        # but one will be made in the case this is the only test being run
        project_name = "test_project_2"
        project_description = "test_project_description_2"
        project = model.Project(name=project_name,
                                description=project_description)
        test_api.send_project(project)
        # We always upload to project "1" so that tests will be consistent no matter how many / which tests are run
        project_id = "1"

        # Do the upload
        upload_result = upload_run_single_entry(
            path.join(path_to_module, "fake_dir_data"))

        # Make sure the upload was a success
        self.assertEqual(upload_result.exit_code, 0)

        # Verify the files were uploaded
        sample_list = test_api.get_samples(project_id)

        sample_1_found = False
        sample_2_found = False
        sample_3_found = False

        for sample in sample_list:
            if sample.sample_name in [
                    "my-sample-1", "my-sample-2", "my-sample-3"
            ]:
                if sample.sample_name == "my-sample-1":
                    sample_1_found = True
                    sequence_files = test_api.get_sequence_files(
                        project_id, sample.sample_name)
                    self.assertEqual(len(sequence_files), 2)
                    self.assertEqual(sequence_files[0]['fileName'],
                                     'file_1.fastq.gz')
                    self.assertEqual(sequence_files[1]['fileName'],
                                     'file_2.fastq.gz')
                elif sample.sample_name == "my-sample-2":
                    sample_2_found = True
                    sequence_files = test_api.get_sequence_files(
                        project_id, sample.sample_name)
                    self.assertEqual(len(sequence_files), 2)
                    self.assertEqual(sequence_files[0]['fileName'],
                                     'samp_F.fastq.gz')
                    self.assertEqual(sequence_files[1]['fileName'],
                                     'samp_R.fastq.gz')
                elif sample.sample_name == "my-sample-3":
                    sample_3_found = True
                    sequence_files = test_api.get_sequence_files(
                        project_id, sample.sample_name)
                    self.assertEqual(len(sequence_files), 2)
                    self.assertEqual(sequence_files[0]['fileName'],
                                     'germ_f.fastq.gz')
                    self.assertEqual(sequence_files[1]['fileName'],
                                     'germ_r.fastq.gz')

        self.assertEqual(sample_1_found, True)
        self.assertEqual(sample_2_found, True)
        self.assertEqual(sample_3_found, True)