Ejemplo n.º 1
0
    def test_validate_error(self):
        httpretty.register_uri(
            httpretty.POST,
            "https://test_server.com/qiita_db/jobs/job-id/step/",
            body='{"success": true, "error": ""}'
        )
        httpretty.register_uri(
            httpretty.GET,
            "https://test_server.com/qiita_db/prep_template/1/data",
            body='{"data": "", "success": false, "error": "Some error"}')

        with self.assertRaises(ValueError):
            validate(self.qclient, 'job-id', self.parameters, self.out_dir)
Ejemplo n.º 2
0
    def test_validate_prefix(self):
        httpretty.register_uri(
            httpretty.POST,
            "https://test_server.com/qiita_db/jobs/job-id/step/")
        httpretty.register_uri(
            httpretty.GET,
            "https://test_server.com/qiita_db/prep_template/1/data",
            body='{"data": {"1.S1": {"orig_name": "S1"}, "1.S2": '
            '{"orig_name": "S2"}, "1.S3": {"orig_name": "S3"}}}')

        fd, biom_fp = mkstemp(suffix=".biom")
        close(fd)
        data = np.asarray([[0, 0, 1], [1, 3, 42]])
        table = Table(data, ['O1', 'O2'], ['S1', 'S2', 'S3'])
        with biom_open(biom_fp, 'w') as f:
            table.to_hdf5(f, "Test")

        self._clean_up_files.append(biom_fp)

        self.parameters['files'] = '{"BIOM": ["%s"]}' % biom_fp

        obs_success, obs_ainfo, obs_error = validate(self.qclient, 'job-id',
                                                     self.parameters,
                                                     self.out_dir)
        exp_biom_fp = join(self.out_dir, basename(biom_fp))
        self._clean_up_files.append(exp_biom_fp)
        self.assertTrue(obs_success)
        self.assertEqual(obs_ainfo, [[None, 'BIOM', [exp_biom_fp, 'biom']]])
        self.assertEqual(obs_error, "")
        obs_t = load_table(exp_biom_fp)
        self.assertItemsEqual(obs_t.ids(), ["1.S1", "1.S2", "1.S3"])
Ejemplo n.º 3
0
 def test_validate_unknown_type(self):
     self.parameters['artifact_type'] = 'UNKNOWN'
     obs = validate(self.qclient, 'job-id', self.parameters, self.out_dir)
     exp = {'success': False,
            'error': 'Unknown artifact type UNKNOWN. Supported types: BIOM',
            'artifacts': None}
     self.assertEqual(obs, exp)
Ejemplo n.º 4
0
    def test_validate_prefix(self):
        httpretty.register_uri(
            httpretty.POST,
            "https://test_server.com/qiita_db/jobs/job-id/step/")
        httpretty.register_uri(
            httpretty.GET,
            "https://test_server.com/qiita_db/prep_template/1/data",
            body='{"data": {"1.S1": {"orig_name": "S1"}, "1.S2": '
                 '{"orig_name": "S2"}, "1.S3": {"orig_name": "S3"}}}')

        fd, biom_fp = mkstemp(suffix=".biom")
        close(fd)
        data = np.asarray([[0, 0, 1], [1, 3, 42]])
        table = Table(data, ['O1', 'O2'], ['S1', 'S2', 'S3'])
        with biom_open(biom_fp, 'w') as f:
            table.to_hdf5(f, "Test")

        self._clean_up_files.append(biom_fp)

        self.parameters['files'] = '{"BIOM": ["%s"]}' % biom_fp

        obs_success, obs_ainfo, obs_error = validate(
            self.qclient, 'job-id', self.parameters, self.out_dir)
        exp_biom_fp = join(self.out_dir, basename(biom_fp))
        self._clean_up_files.append(exp_biom_fp)
        self.assertTrue(obs_success)
        self.assertEqual(obs_ainfo, [[None, 'BIOM', [exp_biom_fp, 'biom']]])
        self.assertEqual(obs_error, "")
        obs_t = load_table(exp_biom_fp)
        self.assertItemsEqual(obs_t.ids(), ["1.S1", "1.S2", "1.S3"])
Ejemplo n.º 5
0
 def test_validate_unknown_type(self):
     self.parameters['artifact_type'] = 'UNKNOWN'
     obs_success, obs_ainfo, obs_error = validate(
         self.qclient, 'job-id', self.parameters, self.out_dir)
     self.assertFalse(obs_success)
     self.assertIsNone(obs_ainfo)
     exp = 'Unknown artifact type UNKNOWN. Supported types: BIOM'
     self.assertEqual(obs_error, exp)
Ejemplo n.º 6
0
 def test_validate_unknown_type(self):
     self.parameters['artifact_type'] = 'UNKNOWN'
     obs_success, obs_ainfo, obs_error = validate(self.qclient, 'job-id',
                                                  self.parameters,
                                                  self.out_dir)
     self.assertFalse(obs_success)
     self.assertIsNone(obs_ainfo)
     exp = 'Unknown artifact type UNKNOWN. Supported types: BIOM'
     self.assertEqual(obs_error, exp)
Ejemplo n.º 7
0
    def test_validate_no_changes(self):
        httpretty.register_uri(
            httpretty.POST,
            "https://test_server.com/qiita_db/jobs/job-id/step/")
        httpretty.register_uri(
            httpretty.GET,
            "https://test_server.com/qiita_db/prep_template/1/data",
            body='{"data": {"1.S1": {"run_prefix": "S1"}, "1.S2": '
                 '{"run_prefix": "S2"}, "1.S3": {"run_prefix": "S3"}}}')

        obs_success, obs_ainfo, obs_error = validate(
            self.qclient, 'job-id', self.parameters, self.out_dir)
        self.assertTrue(obs_success)
        self.assertEqual(obs_ainfo, [[None, 'BIOM', [self.biom_fp, 'biom']]])
        self.assertEqual(obs_error, "")
Ejemplo n.º 8
0
 def test_validate_missing_samples(self):
     httpretty.register_uri(
         httpretty.POST,
         "https://test_server.com/qiita_db/jobs/job-id/step/")
     httpretty.register_uri(
         httpretty.GET,
         "https://test_server.com/qiita_db/prep_template/1/data",
         body='{"data": {"1.S11": {"run_prefix": "1.S1"}, "1.S22": '
              '{"run_prefix": "1.S2"}}}')
     obs_success, obs_ainfo, obs_error = validate(
         self.qclient, 'job-id', self.parameters, self.out_dir)
     self.assertFalse(obs_success)
     self.assertIsNone(obs_ainfo)
     exp = ('Your prep information is missing samples that are present in '
            'your BIOM table: 1.S3')
     self.assertEqual(obs_error, exp)
Ejemplo n.º 9
0
    def test_validate_no_changes(self):
        httpretty.register_uri(
            httpretty.POST,
            "https://test_server.com/qiita_db/jobs/job-id/step/")
        httpretty.register_uri(
            httpretty.GET,
            "https://test_server.com/qiita_db/prep_template/1/data",
            body='{"data": {"1.S1": {"run_prefix": "S1"}, "1.S2": '
            '{"run_prefix": "S2"}, "1.S3": {"run_prefix": "S3"}}}')

        obs_success, obs_ainfo, obs_error = validate(self.qclient, 'job-id',
                                                     self.parameters,
                                                     self.out_dir)
        self.assertTrue(obs_success)
        self.assertEqual(obs_ainfo, [[None, 'BIOM', [self.biom_fp, 'biom']]])
        self.assertEqual(obs_error, "")
Ejemplo n.º 10
0
 def test_validate_missing_samples(self):
     httpretty.register_uri(
         httpretty.POST,
         "https://test_server.com/qiita_db/jobs/job-id/step/")
     httpretty.register_uri(
         httpretty.GET,
         "https://test_server.com/qiita_db/prep_template/1/data",
         body='{"data": {"1.S11": {"run_prefix": "1.S1"}, "1.S22": '
         '{"run_prefix": "1.S2"}}}')
     obs_success, obs_ainfo, obs_error = validate(self.qclient, 'job-id',
                                                  self.parameters,
                                                  self.out_dir)
     self.assertFalse(obs_success)
     self.assertIsNone(obs_ainfo)
     exp = ('Your prep information is missing samples that are present in '
            'your BIOM table: 1.S3')
     self.assertEqual(obs_error, exp)
Ejemplo n.º 11
0
 def test_validate_missing_samples(self):
     httpretty.register_uri(
         httpretty.POST,
         "https://test_server.com/qiita_db/jobs/job-id/step/",
         body='{"success": true, "error": ""}'
     )
     httpretty.register_uri(
         httpretty.GET,
         "https://test_server.com/qiita_db/prep_template/1/data",
         body='{"data": {"1.S11": {"run_prefix": "1.S1"}, "1.S22": '
              '{"run_prefix": "1.S2"}}, "success": true, "error": ""}')
     obs = validate(self.qclient, 'job-id', self.parameters, self.out_dir)
     exp = {'success': False,
            'error': 'Your prep information is missing samples that are '
                     'present in your BIOM table: 1.S3',
            'artifacts': None}
     self.assertEqual(obs, exp)
Ejemplo n.º 12
0
    def test_validate_no_changes(self):
        httpretty.register_uri(
            httpretty.POST,
            "https://test_server.com/qiita_db/jobs/job-id/step/",
            body='{"success": true, "error": ""}'
        )
        httpretty.register_uri(
            httpretty.GET,
            "https://test_server.com/qiita_db/prep_template/1/data",
            body='{"data": {"1.S1": {"run_prefix": "S1"}, "1.S2": '
                 '{"run_prefix": "S2"}, "1.S3": {"run_prefix": "S3"}}, '
                 '"success": true, "error": ""}')

        obs = validate(self.qclient, 'job-id', self.parameters, self.out_dir)
        exp = {'success': True,
               'error': '',
               'artifacts': {None: {'artifact_type': 'BIOM',
                                    'filepaths': [self.biom_fp, 'biom']}}}
        self.assertEqual(obs, exp)
Ejemplo n.º 13
0
 def test_validate_unknown_samples(self):
     httpretty.register_uri(
         httpretty.POST,
         "https://test_server.com/qiita_db/jobs/job-id/step/")
     httpretty.register_uri(
         httpretty.GET,
         "https://test_server.com/qiita_db/prep_template/1/data",
         body='{"data": {"1.S11": {"orig_name": "S1"}, "1.S22": '
              '{"orig_name": "S2"}, "1.S33": {"orig_name": "S3"}}, '
              '"success": true, "error": ""}')
     obs_success, obs_ainfo, obs_error = validate(
         self.qclient, 'job-id', self.parameters, self.out_dir)
     self.assertFalse(obs_success)
     self.assertIsNone(obs_ainfo)
     exp = ('The sample ids in the BIOM table do not match the ones in the '
            'prep information. Please, provide the column "run_prefix" in '
            'the prep information to map the existing sample ids to the '
            'prep information sample ids.')
     self.assertEqual(obs_error, exp)
Ejemplo n.º 14
0
    def test_validate_run_prefix(self):
        httpretty.register_uri(
            httpretty.POST,
            "https://test_server.com/qiita_db/jobs/job-id/step/")
        httpretty.register_uri(
            httpretty.GET,
            "https://test_server.com/qiita_db/prep_template/1/data",
            body='{"data": {"1.S11": {"run_prefix": "1.S1"}, "1.S22": '
                 '{"run_prefix": "1.S2"}, "1.S33": {"run_prefix": "1.S3"}}}')

        obs_success, obs_ainfo, obs_error = validate(
            self.qclient, 'job-id', self.parameters, self.out_dir)
        exp_biom_fp = join(self.out_dir, basename(self.biom_fp))
        self._clean_up_files.append(exp_biom_fp)
        self.assertTrue(obs_success)
        self.assertEqual(obs_ainfo, [[None, 'BIOM', [exp_biom_fp, 'biom']]])
        self.assertEqual(obs_error, "")
        obs_t = load_table(exp_biom_fp)
        self.assertItemsEqual(obs_t.ids(), ["1.S11", "1.S22", "1.S33"])
Ejemplo n.º 15
0
    def test_validate_run_prefix(self):
        httpretty.register_uri(
            httpretty.POST,
            "https://test_server.com/qiita_db/jobs/job-id/step/")
        httpretty.register_uri(
            httpretty.GET,
            "https://test_server.com/qiita_db/prep_template/1/data",
            body='{"data": {"1.S11": {"run_prefix": "1.S1"}, "1.S22": '
            '{"run_prefix": "1.S2"}, "1.S33": {"run_prefix": "1.S3"}}}')

        obs_success, obs_ainfo, obs_error = validate(self.qclient, 'job-id',
                                                     self.parameters,
                                                     self.out_dir)
        exp_biom_fp = join(self.out_dir, basename(self.biom_fp))
        self._clean_up_files.append(exp_biom_fp)
        self.assertTrue(obs_success)
        self.assertEqual(obs_ainfo, [[None, 'BIOM', [exp_biom_fp, 'biom']]])
        self.assertEqual(obs_error, "")
        obs_t = load_table(exp_biom_fp)
        self.assertItemsEqual(obs_t.ids(), ["1.S11", "1.S22", "1.S33"])
Ejemplo n.º 16
0
 def test_validate_unknown_samples(self):
     httpretty.register_uri(
         httpretty.POST,
         "https://test_server.com/qiita_db/jobs/job-id/step/")
     httpretty.register_uri(
         httpretty.GET,
         "https://test_server.com/qiita_db/prep_template/1/data",
         body='{"data": {"1.S11": {"orig_name": "S1"}, "1.S22": '
         '{"orig_name": "S2"}, "1.S33": {"orig_name": "S3"}}, '
         '"success": true, "error": ""}')
     obs_success, obs_ainfo, obs_error = validate(self.qclient, 'job-id',
                                                  self.parameters,
                                                  self.out_dir)
     self.assertFalse(obs_success)
     self.assertIsNone(obs_ainfo)
     exp = ('The sample ids in the BIOM table do not match the ones in the '
            'prep information. Please, provide the column "run_prefix" in '
            'the prep information to map the existing sample ids to the '
            'prep information sample ids.')
     self.assertEqual(obs_error, exp)
Ejemplo n.º 17
0
 def test_validate_unknown_samples(self):
     httpretty.register_uri(
         httpretty.POST,
         "https://test_server.com/qiita_db/jobs/job-id/step/",
         body='{"success": true, "error": ""}'
     )
     httpretty.register_uri(
         httpretty.GET,
         "https://test_server.com/qiita_db/prep_template/1/data",
         body='{"data": {"1.S11": {"orig_name": "S1"}, "1.S22": '
              '{"orig_name": "S2"}, "1.S33": {"orig_name": "S3"}}, '
              '"success": true, "error": ""}')
     obs = validate(self.qclient, 'job-id', self.parameters, self.out_dir)
     exp = {'success': False,
            'error': 'The sample ids in the BIOM table do not match the '
                     'ones in the prep information. Please, provide the '
                     'column "run_prefix" in the prep information to map '
                     'the existing sample ids to the prep information '
                     'sample ids.',
            'artifacts': None}
     self.assertEqual(obs, exp)
Ejemplo n.º 18
0
    def test_validate_run_prefix(self):
        httpretty.register_uri(
            httpretty.POST,
            "https://test_server.com/qiita_db/jobs/job-id/step/",
            body='{"success": true, "error": ""}'
        )
        httpretty.register_uri(
            httpretty.GET,
            "https://test_server.com/qiita_db/prep_template/1/data",
            body='{"data": {"1.S11": {"run_prefix": "1.S1"}, "1.S22": '
                 '{"run_prefix": "1.S2"}, "1.S33": {"run_prefix": "1.S3"}}, '
                 '"success": true, "error": ""}')

        obs = validate(self.qclient, 'job-id', self.parameters, self.out_dir)
        exp_biom_fp = join(self.out_dir, basename(self.biom_fp))
        self._clean_up_files.append(exp_biom_fp)
        exp = {'success': True,
               'error': '',
               'artifacts': {None: {'artifact_type': 'BIOM',
                                    'filepaths': [exp_biom_fp, 'biom']}}}
        self.assertEqual(obs, exp)
        obs_t = load_table(exp_biom_fp)
        self.assertItemsEqual(obs_t.ids(), ["1.S11", "1.S22", "1.S33"])