Example #1
0
    def test_prep_template_jobs_get_req(self):
        # Create a new template:
        metadata = pd.DataFrame.from_dict(
            {
                'SKD6.640190': {
                    'center_name': 'ANL',
                    'target_subfragment': 'V4',
                    'center_project_name': 'Test Project',
                    'ebi_submission_accession': None,
                    'EMP_status': 'EMP',
                    'str_column': 'Value for sample 1',
                    'primer': 'GTGCCAGCMGCCGCGGTAA',
                    'barcode': 'GTCCGCAAGTTA',
                    'run_prefix': "s_G1_L001_sequences",
                    'platform': 'Illumina',
                    'instrument_model': 'Illumina MiSeq',
                    'library_construction_protocol': 'AAAA',
                    'experiment_design_description': 'BBBB'
                }
            },
            orient='index',
            dtype=str)
        pt = PrepTemplate.create(metadata, Study(1), '16S')

        # Check that it returns an empty dictionary when there are no jobs
        # attached to the prep template
        self.assertEqual(prep_template_jobs_get_req(pt.id, '*****@*****.**'), {})

        # Create a job on the template
        prep_template_patch_req('*****@*****.**', 'remove',
                                '/%s/10/columns/target_subfragment/' % pt.id)
        # To ensure a deterministic result, wait until the job is completed
        self._wait_for_parallel_job('prep_template_%s' % pt.id)
        obs = prep_template_jobs_get_req(pt.id, '*****@*****.**')
        self.assertEqual(len(obs), 1)
        self.assertCountEqual(obs.values(), [{
            'error': '',
            'status': 'success',
            'step': None
        }])

        obs = prep_template_jobs_get_req(pt.id, '*****@*****.**')
        exp = {
            'status': 'error',
            'message': 'User does not have access to study'
        }
        self.assertEqual(obs, exp)
 def test_prep_template_patch_req_errors(self):
     # Operation not supported
     obs = prep_template_patch_req('*****@*****.**', 'add',
                                   '/1/investigation_type',
                                   'Cancer Genomics')
     exp = {
         'status':
         'error',
         'message':
         'Operation "add" not supported. '
         'Current supported operations: replace'
     }
     self.assertEqual(obs, exp)
     # Incorrect path parameter
     obs = prep_template_patch_req('*****@*****.**', 'replace',
                                   '/investigation_type', 'Cancer Genomics')
     exp = {'status': 'error', 'message': 'Incorrect path parameter'}
     self.assertEqual(obs, exp)
     # Incorrect attribute
     obs = prep_template_patch_req('*****@*****.**', 'replace',
                                   '/1/other_attribute', 'Cancer Genomics')
     exp = {
         'status':
         'error',
         'message':
         'Attribute "other_attribute" not found. '
         'Please, check the path parameter'
     }
     self.assertEqual(obs, exp)
     # User doesn't have access
     obs = prep_template_patch_req('*****@*****.**', 'replace',
                                   '/1/investigation_type',
                                   'Cancer Genomics')
     exp = {
         'status': 'error',
         'message': 'User does not have access to study'
     }
     self.assertEqual(obs, exp)
     # File does not exists
     obs = prep_template_patch_req('*****@*****.**', 'replace', '/1/data',
                                   'unknown_file.txt')
     exp = {
         'status': 'error',
         'message': 'file does not exist',
         'file': 'unknown_file.txt'
     }
     self.assertEqual(obs, exp)
Example #3
0
 def test_prep_template_patch_req_errors(self):
     # Operation not supported
     obs = prep_template_patch_req(
         '*****@*****.**', 'add', '/1/investigation_type',
         'Cancer Genomics')
     exp = {'status': 'error',
            'message': 'Operation "add" not supported. '
                       'Current supported operations: replace'}
     self.assertEqual(obs, exp)
     # Incorrect path parameter
     obs = prep_template_patch_req(
         '*****@*****.**', 'replace', '/investigation_type',
         'Cancer Genomics')
     exp = {'status': 'error',
            'message': 'Incorrect path parameter'}
     self.assertEqual(obs, exp)
     # Incorrect attribute
     obs = prep_template_patch_req(
         '*****@*****.**', 'replace', '/1/other_attribute',
         'Cancer Genomics')
     exp = {'status': 'error',
            'message': 'Attribute "other_attribute" not found. '
                       'Please, check the path parameter'}
     self.assertEqual(obs, exp)
     # User doesn't have access
     obs = prep_template_patch_req(
         '*****@*****.**', 'replace', '/1/investigation_type',
         'Cancer Genomics')
     exp = {'status': 'error',
            'message': 'User does not have access to study'}
     self.assertEqual(obs, exp)
     # File does not exists
     obs = prep_template_patch_req(
         '*****@*****.**', 'replace', '/1/data', 'unknown_file.txt')
     exp = {'status': 'error',
            'message': 'file does not exist',
            'file': 'unknown_file.txt'}
     self.assertEqual(obs, exp)
Example #4
0
    def test_prep_template_jobs_get_req(self):
        # Create a new template:
        metadata = pd.DataFrame.from_dict(
            {'SKD6.640190': {'center_name': 'ANL',
                             'target_subfragment': 'V4',
                             'center_project_name': 'Test Project',
                             'ebi_submission_accession': None,
                             'EMP_status': 'EMP',
                             'str_column': 'Value for sample 1',
                             'primer': 'GTGCCAGCMGCCGCGGTAA',
                             'barcode': 'GTCCGCAAGTTA',
                             'run_prefix': "s_G1_L001_sequences",
                             'platform': 'ILLUMINA',
                             'instrument_model': 'Illumina MiSeq',
                             'library_construction_protocol': 'AAAA',
                             'experiment_design_description': 'BBBB'}},
            orient='index', dtype=str)
        pt = PrepTemplate.create(metadata, Study(1), '16S')

        # Check that it returns an empty dictionary when there are no jobs
        # attached to the prep template
        self.assertEqual(prep_template_jobs_get_req(pt.id, '*****@*****.**'), {})

        # Create a job on the template
        prep_template_patch_req(
            '*****@*****.**', 'remove',
            '/%s/10/columns/target_subfragment/' % pt.id)
        # To ensure a deterministic result, wait until the job is completed
        self._wait_for_parallel_job('prep_template_%s' % pt.id)
        obs = prep_template_jobs_get_req(pt.id, '*****@*****.**')
        self.assertEqual(len(obs), 1)
        self.assertEqual(obs.values(),
                         [{'error': '', 'status': 'success', 'step': None}])

        obs = prep_template_jobs_get_req(pt.id, '*****@*****.**')
        exp = {'status': 'error',
               'message': 'User does not have access to study'}
        self.assertEqual(obs, exp)
Example #5
0
    def test_prep_template_patch_req(self):
        pt = PrepTemplate(1)
        # Update investigation type
        obs = prep_template_patch_req(
            '*****@*****.**', 'replace', '/1/investigation_type',
            'Cancer Genomics')
        exp = {'status': 'success', 'message': ''}
        self.assertEqual(obs, exp)
        self.assertEqual(pt.investigation_type, 'Cancer Genomics')
        # Update prep template data
        obs = prep_template_patch_req(
            '*****@*****.**', 'replace', '/1/data', 'update.txt')
        self.assertEqual(obs, exp)
        obs = r_client.get('prep_template_1')
        self.assertIsNotNone(obs)

        # This is needed so the clean up works - this is a distributed system
        # so we need to make sure that all processes are done before we reset
        # the test database
        redis_info = loads(r_client.get(obs))
        while redis_info['status_msg'] == 'Running':
            sleep(0.05)
            redis_info = loads(r_client.get(obs))
    def test_prep_template_patch_req(self):
        pt = PrepTemplate(1)
        # Update investigation type
        obs = prep_template_patch_req('*****@*****.**', 'replace',
                                      '/1/investigation_type',
                                      'Cancer Genomics')
        exp = {'status': 'success', 'message': ''}
        self.assertEqual(obs, exp)
        self.assertEqual(pt.investigation_type, 'Cancer Genomics')
        # Update prep template data
        obs = prep_template_patch_req('*****@*****.**', 'replace', '/1/data',
                                      'update.txt')
        self.assertEqual(obs, exp)
        obs = r_client.get('prep_template_1')
        self.assertIsNotNone(obs)

        # This is needed so the clean up works - this is a distributed system
        # so we need to make sure that all processes are done before we reset
        # the test database
        redis_info = loads(r_client.get(loads(obs)['job_id']))
        while redis_info['status_msg'] == 'Running':
            sleep(0.05)
            redis_info = loads(r_client.get(loads(obs)['job_id']))
    def test_prep_template_patch_req(self):
        metadata = pd.DataFrame.from_dict(
            {
                'SKD6.640190': {
                    'center_name': 'ANL',
                    'target_subfragment': 'V4',
                    'center_project_name': 'Test Project',
                    'ebi_submission_accession': None,
                    'EMP_status': 'EMP',
                    'str_column': 'Value for sample 1',
                    'primer': 'GTGCCAGCMGCCGCGGTAA',
                    'barcode': 'GTCCGCAAGTTA',
                    'run_prefix': "s_G1_L001_sequences",
                    'platform': 'ILLUMINA',
                    'instrument_model': 'Illumina MiSeq',
                    'library_construction_protocol': 'AAAA',
                    'experiment_design_description': 'BBBB'
                }
            },
            orient='index',
            dtype=str)
        pt = PrepTemplate.create(metadata, Study(1), '16S')
        # Update investigation type
        obs = prep_template_patch_req('*****@*****.**', 'replace',
                                      '/%s/investigation_type' % pt.id,
                                      'Cancer Genomics')
        exp = {'status': 'success', 'message': ''}
        self.assertEqual(obs, exp)
        self.assertEqual(pt.investigation_type, 'Cancer Genomics')
        # Update prep template data
        obs = prep_template_patch_req('*****@*****.**', 'replace',
                                      '/%s/data' % pt.id, 'update.txt')
        self.assertEqual(obs, exp)
        obs = r_client.get('prep_template_%s' % pt.id)
        self.assertIsNotNone(obs)

        self._wait_for_parallel_job('prep_template_%s' % pt.id)

        # Delete a prep template column
        obs = prep_template_patch_req(
            '*****@*****.**', 'remove',
            '/%s/10/columns/target_subfragment/' % pt.id)
        exp = {'status': 'success', 'message': '', 'row_id': '10'}
        self.assertEqual(obs, exp)
        self._wait_for_parallel_job('prep_template_%s' % pt.id)
        self.assertNotIn('target_subfragment', pt.categories())

        # Test all the errors
        # Operation not supported
        obs = prep_template_patch_req('*****@*****.**', 'add',
                                      '/1/investigation_type',
                                      'Cancer Genomics')
        exp = {
            'status': 'error',
            'message': 'Operation "add" not supported. '
            'Current supported operations: replace, remove',
            'row_id': '0'
        }
        self.assertEqual(obs, exp)
        # Incorrect path parameter
        obs = prep_template_patch_req('*****@*****.**', 'replace',
                                      '/investigation_type', 'Cancer Genomics')
        exp = {'status': 'error', 'message': 'Incorrect path parameter'}
        self.assertEqual(obs, exp)
        # Incorrect attribute
        obs = prep_template_patch_req('*****@*****.**', 'replace',
                                      '/1/other_attribute', 'Cancer Genomics')
        exp = {
            'status':
            'error',
            'message':
            'Attribute "other_attribute" not found. '
            'Please, check the path parameter'
        }
        self.assertEqual(obs, exp)
        # User doesn't have access
        obs = prep_template_patch_req('*****@*****.**', 'replace',
                                      '/%s/investigation_type' % pt.id,
                                      'Cancer Genomics')
        exp = {
            'status': 'error',
            'message': 'User does not have access to study'
        }
        self.assertEqual(obs, exp)
        # File does not exists
        obs = prep_template_patch_req('*****@*****.**', 'replace', '/1/data',
                                      'unknown_file.txt')
        exp = {
            'status': 'error',
            'message': 'file does not exist',
            'file': 'unknown_file.txt'
        }
        self.assertEqual(obs, exp)
Example #8
0
    def test_prep_template_patch_req(self):
        metadata = pd.DataFrame.from_dict(
            {'SKD6.640190': {'center_name': 'ANL',
                             'target_subfragment': 'V4',
                             'center_project_name': 'Test Project',
                             'ebi_submission_accession': None,
                             'EMP_status': 'EMP',
                             'str_column': 'Value for sample 1',
                             'primer': 'GTGCCAGCMGCCGCGGTAA',
                             'barcode': 'GTCCGCAAGTTA',
                             'run_prefix': "s_G1_L001_sequences",
                             'platform': 'ILLUMINA',
                             'instrument_model': 'Illumina MiSeq',
                             'library_construction_protocol': 'AAAA',
                             'experiment_design_description': 'BBBB'}},
            orient='index', dtype=str)
        pt = PrepTemplate.create(metadata, Study(1), '16S')
        # Update investigation type
        obs = prep_template_patch_req(
            '*****@*****.**', 'replace', '/%s/investigation_type' % pt.id,
            'Cancer Genomics')
        exp = {'status': 'success', 'message': ''}
        self.assertEqual(obs, exp)
        self.assertEqual(pt.investigation_type, 'Cancer Genomics')
        # Update prep template data
        obs = prep_template_patch_req(
            '*****@*****.**', 'replace', '/%s/data' % pt.id, 'update.txt')
        self.assertEqual(obs, exp)
        obs = r_client.get('prep_template_%s' % pt.id)
        self.assertIsNotNone(obs)

        self._wait_for_parallel_job('prep_template_%s' % pt.id)

        # Delete a prep template column
        obs = prep_template_patch_req(
            '*****@*****.**', 'remove',
            '/%s/10/columns/target_subfragment/' % pt.id)
        exp = {'status': 'success', 'message': '', 'row_id': '10'}
        self.assertEqual(obs, exp)
        self._wait_for_parallel_job('prep_template_%s' % pt.id)
        self.assertNotIn('target_subfragment', pt.categories())

        # Change the name of the prep template
        obs = prep_template_patch_req(
            '*****@*****.**', 'replace', '/%s/name' % pt.id, ' My New Name ')
        exp = {'status': 'success', 'message': ''}
        self.assertEqual(obs, exp)
        self.assertEqual(pt.name, 'My New Name')

        # Test all the errors
        # Operation not supported
        obs = prep_template_patch_req(
            '*****@*****.**', 'add', '/1/investigation_type',
            'Cancer Genomics')
        exp = {'status': 'error',
               'message': 'Operation "add" not supported. '
                          'Current supported operations: replace, remove',
               'row_id': '0'}
        self.assertEqual(obs, exp)
        # Incorrect path parameter
        obs = prep_template_patch_req(
            '*****@*****.**', 'replace', '/investigation_type',
            'Cancer Genomics')
        exp = {'status': 'error',
               'message': 'Incorrect path parameter'}
        self.assertEqual(obs, exp)
        # Incorrect attribute
        obs = prep_template_patch_req(
            '*****@*****.**', 'replace', '/1/other_attribute',
            'Cancer Genomics')
        exp = {'status': 'error',
               'message': 'Attribute "other_attribute" not found. '
                          'Please, check the path parameter'}
        self.assertEqual(obs, exp)
        # User doesn't have access
        obs = prep_template_patch_req(
            '*****@*****.**', 'replace', '/%s/investigation_type' % pt.id,
            'Cancer Genomics')
        exp = {'status': 'error',
               'message': 'User does not have access to study'}
        self.assertEqual(obs, exp)
        # File does not exists
        obs = prep_template_patch_req(
            '*****@*****.**', 'replace', '/1/data', 'unknown_file.txt')
        exp = {'status': 'error',
               'message': 'file does not exist',
               'file': 'unknown_file.txt'}
        self.assertEqual(obs, exp)