def test_metadata_filter_sample_ids_category_unknown_expect_404(self): with patch('microsetta_public_api.repo._metadata_repo.MetadataRepo.' 'categories', new_callable=PropertyMock) as \ mock_categories: mock_categories.return_value = ['age_cat', 'bmi'] response, code = filter_sample_ids(some_other_cat='bar') self.assertEqual(code, 404)
def test_metadata_filter_sample_ids_bmi(self): with patch.object(MetadataRepo, 'sample_id_matches') as mock_matches, \ patch('microsetta_public_api.repo._metadata_repo.MetadataRepo.' 'categories', new_callable=PropertyMock) as mock_categories: mock_matches.return_value = ['sample-1', 'sample-3'] mock_categories.return_value = ['bmi'] response, code = filter_sample_ids(bmi='normal') self.assertEqual(code, 200) exp = {'sample_ids': ['sample-1', 'sample-3']} obs = json.loads(response) self.assertDictEqual(exp, obs)
def test_metadata_filter_sample_ids_taxonomy_filter(self): with patch.object(MetadataRepo, 'sample_id_matches') as mock_matches, \ patch('microsetta_public_api.repo._metadata_repo.MetadataRepo.' 'categories', new_callable=PropertyMock) as \ mock_categories, \ patch('microsetta_public_api.api.metadata' '.TaxonomyRepo.exists') as mock_exists, \ patch('microsetta_public_api.api.metadata.validate_resource' '') as mock_invalid_resource: mock_matches.return_value = ['sample-1', 'sample-2', 'sample-3'] mock_categories.return_value = ['age_cat'] mock_exists.side_effect = [False, True, True] mock_invalid_resource.return_value = False response, code = filter_sample_ids(age_cat='30s', taxonomy='agp') self.assertEqual(200, code) exp = {'sample_ids': ['sample-2', 'sample-3']} obs = json.loads(response) self.assertDictEqual(exp, obs)