diff options
author | Arun Isaac | 2023-12-30 05:17:17 +0000 |
---|---|---|
committer | Arun Isaac | 2023-12-30 05:17:17 +0000 |
commit | 8536431f9c367c55d2ea138ab24b2d12e98f7c81 (patch) | |
tree | 1d7d272066ee675065e4d1e89fa37fdb5293e101 /gn2/tests | |
parent | 21d6de22641cb1b540e03cb963d12593dab16046 (diff) | |
download | genenetwork2-8536431f9c367c55d2ea138ab24b2d12e98f7c81.tar.gz |
Namespace mock paths under gn2.
Diffstat (limited to 'gn2/tests')
20 files changed, 139 insertions, 139 deletions
diff --git a/gn2/tests/unit/base/test_data_set.py b/gn2/tests/unit/base/test_data_set.py index 7341314c..9f9fb132 100644 --- a/gn2/tests/unit/base/test_data_set.py +++ b/gn2/tests/unit/base/test_data_set.py @@ -173,7 +173,7 @@ class TestDataSetTypes(unittest.TestCase): ("All Phenotypes", redis_mock, cursor_mock), "Publish") redis_mock.get.assert_called_once_with("dataset_structure") - @mock.patch('base.data_set.datasettype.requests.get') + @mock.patch('gn2.base.data_set.datasettype.requests.get') def test_data_set_type_with_empty_redis(self, request_mock): """Test that DatasetType returns correctly if the Redis Instance is empty and the name variable exists in the dictionary @@ -204,8 +204,8 @@ class TestDataSetTypes(unittest.TestCase): class TestDatasetAccessionId(unittest.TestCase): """Tests for the DataSetType class""" - @mock.patch("base.data_set.dataset.query_sql") - @mock.patch("base.data_set.dataset.DatasetGroup") + @mock.patch("gn2.base.data_set.dataset.query_sql") + @mock.patch("gn2.base.data_set.dataset.DatasetGroup") def test_get_accession_id(self, mock_dataset_group, mock_query_sql): def mock_fn(): yield MonadicDict({"accession_id": 7}) @@ -221,8 +221,8 @@ class TestDatasetAccessionId(unittest.TestCase): .accession_id\ .bind(lambda x: self.assertEqual(7, x)) - @mock.patch("base.data_set.dataset.query_sql") - @mock.patch("base.data_set.dataset.DatasetGroup") + @mock.patch("gn2.base.data_set.dataset.query_sql") + @mock.patch("gn2.base.data_set.dataset.DatasetGroup") def test_get_accession_id_empty_return(self, mock_dataset_group, mock_query_sql): mock_dataset_group.return_value = MockGroup() diff --git a/gn2/tests/unit/base/test_species.py b/gn2/tests/unit/base/test_species.py index 239e8b3f..d2845b25 100644 --- a/gn2/tests/unit/base/test_species.py +++ b/gn2/tests/unit/base/test_species.py @@ -30,7 +30,7 @@ class MockDataset: (None, "Random Dataset", None, 1))) def test_species(mocker, species_name, dataset, expected_name, chromosome_param): - _c = mocker.patch("base.species.Chromosomes", + _c = mocker.patch("gn2.base.species.Chromosomes", return_value=chromosome_param) test_species = TheSpecies(dataset=dataset, species_name=species_name) diff --git a/gn2/tests/unit/base/test_trait.py b/gn2/tests/unit/base/test_trait.py index 417956ae..2adb1fdf 100644 --- a/gn2/tests/unit/base/test_trait.py +++ b/gn2/tests/unit/base/test_trait.py @@ -31,7 +31,7 @@ class MockTrait(GeneralTrait): class TestRetrieveTraitInfo(unittest.TestCase): """Tests for 'retrieve_trait_info'""" - @mock.patch('base.trait.database_connection') + @mock.patch('gn2.base.trait.database_connection') def test_retrieve_trait_info_with_empty_dataset(self, mock_db): """Test that an exception is raised when dataset is empty""" conn = mock.MagicMock() @@ -40,9 +40,9 @@ class TestRetrieveTraitInfo(unittest.TestCase): retrieve_trait_info(trait=mock.MagicMock(), dataset={}) - @mock.patch('base.trait.requests.get') - @mock.patch('base.trait.g', mock.Mock()) - @mock.patch('base.trait.database_connection') + @mock.patch('gn2.base.trait.requests.get') + @mock.patch('gn2.base.trait.g', mock.Mock()) + @mock.patch('gn2.base.trait.database_connection') def test_retrieve_trait_info_with_empty_trait_info(self, mock_db, requests_mock): @@ -57,9 +57,9 @@ class TestRetrieveTraitInfo(unittest.TestCase): retrieve_trait_info(trait=mock.MagicMock(), dataset=mock.MagicMock()) - @mock.patch('base.trait.requests.get') - @mock.patch('base.trait.g', mock.Mock()) - @mock.patch('base.trait.database_connection') + @mock.patch('gn2.base.trait.requests.get') + @mock.patch('gn2.base.trait.g', mock.Mock()) + @mock.patch('gn2.base.trait.database_connection') def test_retrieve_trait_info_with_non_empty_trait_info(self, mock_db, requests_mock): @@ -80,9 +80,9 @@ class TestRetrieveTraitInfo(unittest.TestCase): self.assertEqual(test_trait.c, 3) self.assertEqual(test_trait.d, 4) - @mock.patch('base.trait.requests.get') - @mock.patch('base.trait.g', mock.Mock()) - @mock.patch('base.trait.database_connection') + @mock.patch('gn2.base.trait.requests.get') + @mock.patch('gn2.base.trait.g', mock.Mock()) + @mock.patch('gn2.base.trait.database_connection') def test_retrieve_trait_info_utf8_parsing(self, mock_db, requests_mock): @@ -120,9 +120,9 @@ class TestRetrieveTraitInfo(unittest.TestCase): @unittest.skip("Too complicated") - @mock.patch('base.trait.requests.get') - @mock.patch('base.trait.database_connection') - @mock.patch('base.trait.get_resource_id') + @mock.patch('gn2.base.trait.requests.get') + @mock.patch('gn2.base.trait.database_connection') + @mock.patch('gn2.base.trait.get_resource_id') def test_retrieve_trait_info_with_non_empty_lrs(self, resource_id_mock, mock_db, @@ -169,9 +169,9 @@ class TestRetrieveTraitInfo(unittest.TestCase): "2.4") @unittest.skip("Too complicated") - @mock.patch('base.trait.requests.get') - @mock.patch('base.trait.g') - @mock.patch('base.trait.get_resource_id') + @mock.patch('gn2.base.trait.requests.get') + @mock.patch('gn2.base.trait.g') + @mock.patch('gn2.base.trait.get_resource_id') def test_retrieve_trait_info_with_empty_lrs_field(self, resource_id_mock, g_mock, @@ -215,9 +215,9 @@ class TestRetrieveTraitInfo(unittest.TestCase): "Chr2: 3.000000") @unittest.skip("Too complicated") - @mock.patch('base.trait.requests.get') - @mock.patch('base.trait.g') - @mock.patch('base.trait.get_resource_id') + @mock.patch('gn2.base.trait.requests.get') + @mock.patch('gn2.base.trait.g') + @mock.patch('gn2.base.trait.get_resource_id') def test_retrieve_trait_info_with_empty_chr_field(self, resource_id_mock, g_mock, diff --git a/gn2/tests/unit/utility/test_authentication_tools.py b/gn2/tests/unit/utility/test_authentication_tools.py index 3b16ca94..90945b0f 100644 --- a/gn2/tests/unit/utility/test_authentication_tools.py +++ b/gn2/tests/unit/utility/test_authentication_tools.py @@ -38,10 +38,10 @@ def mock_add_resource(resource_ob, update=False): class TestCheckResourceAvailability(unittest.TestCase): """Test methods related to checking the resource availability""" - @mock.patch('utility.authentication_tools.add_new_resource') - @mock.patch('utility.authentication_tools.Redis') - @mock.patch('utility.authentication_tools.g', TestUserSession()) - @mock.patch('utility.authentication_tools.get_resource_id') + @mock.patch('gn2.utility.authentication_tools.add_new_resource') + @mock.patch('gn2.utility.authentication_tools.Redis') + @mock.patch('gn2.utility.authentication_tools.g', TestUserSession()) + @mock.patch('gn2.utility.authentication_tools.get_resource_id') def test_check_resource_availability_default_mask( self, resource_id_mock, @@ -56,11 +56,11 @@ class TestCheckResourceAvailability(unittest.TestCase): add_new_resource_mock.return_value = {"default_mask": 2} self.assertEqual(check_resource_availability(test_dataset, user_id), 2) - @mock.patch('utility.authentication_tools.requests.get') - @mock.patch('utility.authentication_tools.add_new_resource') - @mock.patch('utility.authentication_tools.Redis') - @mock.patch('utility.authentication_tools.g', TestUserSession()) - @mock.patch('utility.authentication_tools.get_resource_id') + @mock.patch('gn2.utility.authentication_tools.requests.get') + @mock.patch('gn2.utility.authentication_tools.add_new_resource') + @mock.patch('gn2.utility.authentication_tools.Redis') + @mock.patch('gn2.utility.authentication_tools.g', TestUserSession()) + @mock.patch('gn2.utility.authentication_tools.get_resource_id') def test_check_resource_availability_non_default_mask( self, resource_id_mock, @@ -77,13 +77,13 @@ class TestCheckResourceAvailability(unittest.TestCase): self.assertEqual(check_resource_availability(test_dataset, user_id), ['foo']) - @mock.patch('utility.authentication_tools.webqtlConfig.SUPER_PRIVILEGES', + @mock.patch('gn2.utility.authentication_tools.webqtlConfig.SUPER_PRIVILEGES', "SUPERUSER") - @mock.patch('utility.authentication_tools.requests.get') - @mock.patch('utility.authentication_tools.add_new_resource') - @mock.patch('utility.authentication_tools.Redis') - @mock.patch('utility.authentication_tools.g', TestUserSession()) - @mock.patch('utility.authentication_tools.get_resource_id') + @mock.patch('gn2.utility.authentication_tools.requests.get') + @mock.patch('gn2.utility.authentication_tools.add_new_resource') + @mock.patch('gn2.utility.authentication_tools.Redis') + @mock.patch('gn2.utility.authentication_tools.g', TestUserSession()) + @mock.patch('gn2.utility.authentication_tools.get_resource_id') def test_check_resource_availability_of_super_user( self, resource_id_mock, @@ -100,14 +100,14 @@ class TestCheckResourceAvailability(unittest.TestCase): self.assertEqual(check_resource_availability(test_dataset, user_id), "SUPERUSER") - @mock.patch('utility.authentication_tools.webqtlConfig.DEFAULT_PRIVILEGES', + @mock.patch('gn2.utility.authentication_tools.webqtlConfig.DEFAULT_PRIVILEGES', "John Doe") def test_check_resource_availability_string_dataset(self): """Test the resource availability if the dataset is a string""" self.assertEqual(check_resource_availability("Test", user_id), "John Doe") - @mock.patch('utility.authentication_tools.webqtlConfig.DEFAULT_PRIVILEGES', + @mock.patch('gn2.utility.authentication_tools.webqtlConfig.DEFAULT_PRIVILEGES', "John Doe") def test_check_resource_availability_temp(self): """Test the resource availability if the dataset is a string""" @@ -119,10 +119,10 @@ class TestCheckResourceAvailability(unittest.TestCase): class TestAddNewResource(unittest.TestCase): """Test cases for add_new_resource method""" - @mock.patch('utility.authentication_tools.webqtlConfig.DEFAULT_PRIVILEGES', + @mock.patch('gn2.utility.authentication_tools.webqtlConfig.DEFAULT_PRIVILEGES', "John Doe") - @mock.patch('utility.authentication_tools.add_resource', mock_add_resource) - @mock.patch('utility.authentication_tools.get_group_code') + @mock.patch('gn2.utility.authentication_tools.add_resource', mock_add_resource) + @mock.patch('gn2.utility.authentication_tools.get_group_code') def test_add_new_resource_if_publish_datatype(self, group_code_mock): """Test add_new_resource if dataset type is 'publish'""" group_code_mock.return_value = "Test" @@ -143,10 +143,10 @@ class TestAddNewResource(unittest.TestCase): self.assertEqual(add_new_resource(test_dataset), expected_value) - @mock.patch('utility.authentication_tools.webqtlConfig.DEFAULT_PRIVILEGES', + @mock.patch('gn2.utility.authentication_tools.webqtlConfig.DEFAULT_PRIVILEGES', "John Doe") - @mock.patch('utility.authentication_tools.add_resource', mock_add_resource) - @mock.patch('utility.authentication_tools.get_group_code') + @mock.patch('gn2.utility.authentication_tools.add_resource', mock_add_resource) + @mock.patch('gn2.utility.authentication_tools.get_group_code') def test_add_new_resource_if_geno_datatype(self, group_code_mock): """Test add_new_resource if dataset type is 'geno'""" group_code_mock.return_value = "Test" @@ -167,10 +167,10 @@ class TestAddNewResource(unittest.TestCase): self.assertEqual(add_new_resource(test_dataset), expected_value) - @mock.patch('utility.authentication_tools.webqtlConfig.DEFAULT_PRIVILEGES', + @mock.patch('gn2.utility.authentication_tools.webqtlConfig.DEFAULT_PRIVILEGES', "John Doe") - @mock.patch('utility.authentication_tools.add_resource', mock_add_resource) - @mock.patch('utility.authentication_tools.get_group_code') + @mock.patch('gn2.utility.authentication_tools.add_resource', mock_add_resource) + @mock.patch('gn2.utility.authentication_tools.get_group_code') def test_add_new_resource_if_other_datatype(self, group_code_mock): """Test add_new_resource if dataset type is not 'geno' or 'publish'""" group_code_mock.return_value = "Test" diff --git a/gn2/tests/unit/utility/test_hmac.py b/gn2/tests/unit/utility/test_hmac.py index 2b428588..f148ea5b 100644 --- a/gn2/tests/unit/utility/test_hmac.py +++ b/gn2/tests/unit/utility/test_hmac.py @@ -11,12 +11,12 @@ from gn2.utility.hmac import hmac_creation class TestHmacUtil(unittest.TestCase): """Test Utility method for hmac creation""" - @mock.patch("utility.hmac.app.config", {'SECRET_HMAC_CODE': "secret"}) + @mock.patch("gn2.utility.hmac.app.config", {'SECRET_HMAC_CODE': "secret"}) def test_hmac_creation(self): """Test hmac creation with a utf-8 string""" self.assertEqual(hmac_creation("ファイ"), "7410466338cfe109e946") - @mock.patch("utility.hmac.app.config", + @mock.patch("gn2.utility.hmac.app.config", {'SECRET_HMAC_CODE': ('\x08\xdf\xfa\x93N\x80' '\xd9\\H@\\\x9f`\x98d^' '\xb4a;\xc6OM\x946a\xbc' @@ -29,21 +29,21 @@ class TestHmacUtil(unittest.TestCase): hmac_creation(uuid_), "af4fcf5eace9e7c864ce") - @mock.patch("utility.hmac.app.config", {'SECRET_HMAC_CODE': "secret"}) + @mock.patch("gn2.utility.hmac.app.config", {'SECRET_HMAC_CODE': "secret"}) def test_data_hmac(self): """Test data_hmac fn with a utf-8 string""" self.assertEqual(data_hmac("ファイ"), "ファイ:7410466338cfe109e946") - @mock.patch("utility.hmac.app.config", {'SECRET_HMAC_CODE': "secret"}) - @mock.patch("utility.hmac.url_for") + @mock.patch("gn2.utility.hmac.app.config", {'SECRET_HMAC_CODE': "secret"}) + @mock.patch("gn2.utility.hmac.url_for") def test_url_for_hmac_with_plain_url(self, mock_url): """Test url_for_hmac without params""" mock_url.return_value = "https://mock_url.com/ファイ/" self.assertEqual(url_for_hmac("ファイ"), "https://mock_url.com/ファイ/?hm=05bc39e659b1948f41e7") - @mock.patch("utility.hmac.app.config", {'SECRET_HMAC_CODE': "secret"}) - @mock.patch("utility.hmac.url_for") + @mock.patch("gn2.utility.hmac.app.config", {'SECRET_HMAC_CODE': "secret"}) + @mock.patch("gn2.utility.hmac.url_for") def test_url_for_hmac_with_param_in_url(self, mock_url): """Test url_for_hmac with params""" mock_url.return_value = "https://mock_url.com/?ファイ=1" diff --git a/gn2/tests/unit/wqflask/api/test_correlation.py b/gn2/tests/unit/wqflask/api/test_correlation.py index 8835375d..2a1907af 100644 --- a/gn2/tests/unit/wqflask/api/test_correlation.py +++ b/gn2/tests/unit/wqflask/api/test_correlation.py @@ -39,7 +39,7 @@ class TestCorrelations(unittest.TestCase): self.assertEqual(corr_params_results, expected_results) - @mock.patch("wqflask.api.correlation.database_connection") + @mock.patch("gn2.wqflask.api.correlation.database_connection") def test_convert_to_mouse_gene_id(self, mock_db): conn = mock.MagicMock() mock_db.return_value.__enter__.return_value = conn @@ -59,8 +59,8 @@ class TestCorrelations(unittest.TestCase): convert_to_mouse_gene_id(species="human", gene_id="H1"), "MG-2" ) - @mock.patch("wqflask.api.correlation.database_connection") - @mock.patch("wqflask.api.correlation.convert_to_mouse_gene_id") + @mock.patch("gn2.wqflask.api.correlation.database_connection") + @mock.patch("gn2.wqflask.api.correlation.convert_to_mouse_gene_id") def test_do_literature_correlation_for_all_traits( self, mock_convert_to_mouse_geneid, mock_db ): @@ -88,7 +88,7 @@ class TestCorrelations(unittest.TestCase): } self.assertEqual(results, expected_results) - @mock.patch("wqflask.api.correlation.corr_result_helpers.normalize_values") + @mock.patch("gn2.wqflask.api.correlation.corr_result_helpers.normalize_values") def test_get_sample_r_and_p_values(self, mock_normalize): group = AttributeSetter( @@ -146,7 +146,7 @@ class TestCorrelations(unittest.TestCase): self.assertAlmostEqual(val, results_spearmanr[i], 4) self.assertEqual(results_num_overlap, None) - @mock.patch("wqflask.api.correlation.do_literature_correlation_for_all_traits") + @mock.patch("gn2.wqflask.api.correlation.do_literature_correlation_for_all_traits") def test_calculate_results(self, literature_correlation): literature_correlation.return_value = { diff --git a/gn2/tests/unit/wqflask/api/test_gen_menu.py b/gn2/tests/unit/wqflask/api/test_gen_menu.py index a6081e99..2416b3f6 100644 --- a/gn2/tests/unit/wqflask/api/test_gen_menu.py +++ b/gn2/tests/unit/wqflask/api/test_gen_menu.py @@ -258,7 +258,7 @@ class TestGenMenu(unittest.TestCase): "ORDER BY -ProbeSetFreeze.OrderList DESC, " "ProbeSetFreeze.CreateTime DESC") - @mock.patch('wqflask.api.gen_menu.build_datasets') + @mock.patch('gn2.wqflask.api.gen_menu.build_datasets') def test_build_types(self, datasets_mock): """Test that correct tissue metadata is returned""" db_mock = mock.MagicMock() @@ -286,9 +286,9 @@ class TestGenMenu(unittest.TestCase): "ORDER BY Tissue.Name" ) - @mock.patch('wqflask.api.gen_menu.build_types') - @mock.patch('wqflask.api.gen_menu.genotypes_exist') - @mock.patch('wqflask.api.gen_menu.phenotypes_exist') + @mock.patch('gn2.wqflask.api.gen_menu.build_types') + @mock.patch('gn2.wqflask.api.gen_menu.genotypes_exist') + @mock.patch('gn2.wqflask.api.gen_menu.phenotypes_exist') def test_get_types_with_existing_genotype_and_phenotypes( self, phenotypes_exist_mock, @@ -310,9 +310,9 @@ class TestGenMenu(unittest.TestCase): mock.MagicMock()), expected_result) - @mock.patch('wqflask.api.gen_menu.build_types') - @mock.patch('wqflask.api.gen_menu.genotypes_exist') - @mock.patch('wqflask.api.gen_menu.phenotypes_exist') + @mock.patch('gn2.wqflask.api.gen_menu.build_types') + @mock.patch('gn2.wqflask.api.gen_menu.genotypes_exist') + @mock.patch('gn2.wqflask.api.gen_menu.phenotypes_exist') def test_get_types_with_buildtype_and_non_existent_genotype_and_phenotypes( self, phenotypes_exist_mock, @@ -329,9 +329,9 @@ class TestGenMenu(unittest.TestCase): self.assertEqual(get_types(self.test_group, mock.MagicMock()), {'mouse': {}, 'human': {}}) - @mock.patch('wqflask.api.gen_menu.build_types') - @mock.patch('wqflask.api.gen_menu.genotypes_exist') - @mock.patch('wqflask.api.gen_menu.phenotypes_exist') + @mock.patch('gn2.wqflask.api.gen_menu.build_types') + @mock.patch('gn2.wqflask.api.gen_menu.genotypes_exist') + @mock.patch('gn2.wqflask.api.gen_menu.phenotypes_exist') def test_get_types_with_non_existent_genotype_phenotypes_and_buildtype( self, phenotypes_exist_mock, @@ -357,7 +357,7 @@ class TestGenMenu(unittest.TestCase): self.assertEqual(get_types(self.test_group, mock.MagicMock()), expected_result) - @mock.patch('wqflask.api.gen_menu.build_datasets') + @mock.patch('gn2.wqflask.api.gen_menu.build_datasets') def test_get_datasets_with_existent_datasets(self, build_datasets_mock): """Test correct dataset is returned with existent build_datasets""" @@ -379,7 +379,7 @@ class TestGenMenu(unittest.TestCase): self.assertEqual(get_datasets(self.test_type, mock.MagicMock()), expected_result) - @mock.patch('wqflask.api.gen_menu.build_datasets') + @mock.patch('gn2.wqflask.api.gen_menu.build_datasets') def test_get_datasets_with_non_existent_datasets(self, build_datasets_mock): """Test correct dataset is returned with non-existent build_datasets""" @@ -393,10 +393,10 @@ class TestGenMenu(unittest.TestCase): self.assertEqual(get_datasets(self.test_type, mock.MagicMock()), expected_result) - @mock.patch('wqflask.api.gen_menu.get_datasets') - @mock.patch('wqflask.api.gen_menu.get_types') - @mock.patch('wqflask.api.gen_menu.get_groups') - @mock.patch('wqflask.api.gen_menu.get_all_species') + @mock.patch('gn2.wqflask.api.gen_menu.get_datasets') + @mock.patch('gn2.wqflask.api.gen_menu.get_types') + @mock.patch('gn2.wqflask.api.gen_menu.get_groups') + @mock.patch('gn2.wqflask.api.gen_menu.get_all_species') def test_gen_dropdown_json(self, species_mock, groups_mock, diff --git a/gn2/tests/unit/wqflask/api/test_mapping.py b/gn2/tests/unit/wqflask/api/test_mapping.py index 1553cbf6..226e2a9b 100644 --- a/gn2/tests/unit/wqflask/api/test_mapping.py +++ b/gn2/tests/unit/wqflask/api/test_mapping.py @@ -63,12 +63,12 @@ class TestMapping(unittest.TestCase): self.assertEqual(results_2, expected_results) - @mock.patch("wqflask.api.mapping.rqtl_mapping.run_rqtl") - @mock.patch("wqflask.api.mapping.gemma_mapping.run_gemma") - @mock.patch("wqflask.api.mapping.initialize_parameters") - @mock.patch("wqflask.api.mapping.retrieve_sample_data") - @mock.patch("wqflask.api.mapping.create_trait") - @mock.patch("wqflask.api.mapping.data_set.create_dataset") + @mock.patch("gn2.wqflask.api.mapping.rqtl_mapping.run_rqtl") + @mock.patch("gn2.wqflask.api.mapping.gemma_mapping.run_gemma") + @mock.patch("gn2.wqflask.api.mapping.initialize_parameters") + @mock.patch("gn2.wqflask.api.mapping.retrieve_sample_data") + @mock.patch("gn2.wqflask.api.mapping.create_trait") + @mock.patch("gn2.wqflask.api.mapping.data_set.create_dataset") def test_do_mapping_for_api(self, mock_create_dataset, mock_trait, mock_retrieve_sample, mock_param, run_gemma, run_rqtl_geno): start_vars = { "db": "Temp", diff --git a/gn2/tests/unit/wqflask/api/test_markdown_routes.py b/gn2/tests/unit/wqflask/api/test_markdown_routes.py index f0f93bc1..ecf64a81 100644 --- a/gn2/tests/unit/wqflask/api/test_markdown_routes.py +++ b/gn2/tests/unit/wqflask/api/test_markdown_routes.py @@ -26,7 +26,7 @@ This is another sub-heading""" class TestMarkdownRoutesFunctions(unittest.TestCase): """Test cases for functions in markdown""" - @mock.patch('wqflask.api.markdown.requests.get') + @mock.patch('gn2.wqflask.api.markdown.requests.get') def test_render_markdown_when_fetching_locally(self, requests_mock): requests_mock.return_value = MockRequests404() markdown_content = render_markdown("general/glossary/glossary.md") @@ -38,7 +38,7 @@ class TestMarkdownRoutesFunctions(unittest.TestCase): self.assertRegex(markdown_content, "Content for general/glossary/glossary.md not available.") - @mock.patch('wqflask.api.markdown.requests.get') + @mock.patch('gn2.wqflask.api.markdown.requests.get') def test_render_markdown_when_fetching_remotely(self, requests_mock): requests_mock.return_value = MockRequests200() markdown_content = render_markdown("general/glossary/glossary.md") diff --git a/gn2/tests/unit/wqflask/correlation/test_correlation_functions.py b/gn2/tests/unit/wqflask/correlation/test_correlation_functions.py index c0f57141..f76ef57e 100644 --- a/gn2/tests/unit/wqflask/correlation/test_correlation_functions.py +++ b/gn2/tests/unit/wqflask/correlation/test_correlation_functions.py @@ -11,7 +11,7 @@ def test_tissue_corr_computation(mocker): """Test for cal_zero_order_corr_for_tiss""" primary_values = [9.288, 9.313, 8.988, 9.660, 8.21] target_values = [9.586, 8.498, 9.362, 8.820, 8.786] - _m = mocker.patch(("wqflask.correlation.correlation_functions." + _m = mocker.patch(("gn2.wqflask.correlation.correlation_functions." "compute_corr_coeff_p_value"), return_value=(0.51, 0.7)) results = cal_zero_order_corr_for_tiss(primary_values, target_values) diff --git a/gn2/tests/unit/wqflask/marker_regression/test_gemma_mapping.py b/gn2/tests/unit/wqflask/marker_regression/test_gemma_mapping.py index 26f0c50a..b4d80ad7 100644 --- a/gn2/tests/unit/wqflask/marker_regression/test_gemma_mapping.py +++ b/gn2/tests/unit/wqflask/marker_regression/test_gemma_mapping.py @@ -22,7 +22,7 @@ class MockGroup(AttributeSetter): class TestGemmaMapping(unittest.TestCase): - @mock.patch("wqflask.marker_regression.gemma_mapping.parse_loco_output") + @mock.patch("gn2.wqflask.marker_regression.gemma_mapping.parse_loco_output") def test_run_gemma_firstrun_set_false(self, mock_parse_loco): """add tests for gemma function where first run is set to false""" dataset = AttributeSetter( @@ -38,17 +38,17 @@ class TestGemmaMapping(unittest.TestCase): expected_results = ([], "file1") self.assertEqual(expected_results, result) - @mock.patch("wqflask.marker_regression.gemma_mapping.webqtlConfig.GENERATED_IMAGE_DIR", "/home/user/img") - @mock.patch("wqflask.marker_regression.gemma_mapping.GEMMAOPTS", "-debug") - @mock.patch("wqflask.marker_regression.gemma_mapping.GEMMA_WRAPPER_COMMAND", "ghc") - @mock.patch("wqflask.marker_regression.gemma_mapping.TEMPDIR", + @mock.patch("gn2.wqflask.marker_regression.gemma_mapping.webqtlConfig.GENERATED_IMAGE_DIR", "/home/user/img") + @mock.patch("gn2.wqflask.marker_regression.gemma_mapping.GEMMAOPTS", "-debug") + @mock.patch("gn2.wqflask.marker_regression.gemma_mapping.GEMMA_WRAPPER_COMMAND", "ghc") + @mock.patch("gn2.wqflask.marker_regression.gemma_mapping.TEMPDIR", os.path.join(os.path.dirname(__file__), "user/data")) - @mock.patch("wqflask.marker_regression.gemma_mapping.parse_loco_output") - @mock.patch("wqflask.marker_regression.gemma_mapping.flat_files") - @mock.patch("wqflask.marker_regression.gemma_mapping.gen_covariates_file") - @mock.patch("wqflask.marker_regression.run_mapping.random.choice") - @mock.patch("wqflask.marker_regression.gemma_mapping.os") - @mock.patch("wqflask.marker_regression.gemma_mapping.gen_pheno_txt_file") + @mock.patch("gn2.wqflask.marker_regression.gemma_mapping.parse_loco_output") + @mock.patch("gn2.wqflask.marker_regression.gemma_mapping.flat_files") + @mock.patch("gn2.wqflask.marker_regression.gemma_mapping.gen_covariates_file") + @mock.patch("gn2.wqflask.marker_regression.run_mapping.random.choice") + @mock.patch("gn2.wqflask.marker_regression.gemma_mapping.os") + @mock.patch("gn2.wqflask.marker_regression.gemma_mapping.gen_pheno_txt_file") def test_run_gemma_firstrun_set_true(self, mock_gen_pheno_txt, mock_os, mock_choice, mock_gen_covar, mock_flat_files, mock_parse_loco): """add tests for run_gemma where first run is set to true""" this_chromosomes = {} @@ -78,7 +78,7 @@ class TestGemmaMapping(unittest.TestCase): ('/home/user/imgfile_output.assoc.txt')) self.assertEqual(results, ([], "GP1_GWA_RRRRRR")) - @mock.patch("wqflask.marker_regression.gemma_mapping.TEMPDIR", "/home/user/data") + @mock.patch("gn2.wqflask.marker_regression.gemma_mapping.TEMPDIR", "/home/user/data") def test_gen_pheno_txt_file(self): """add tests for generating pheno txt file""" with mock.patch("builtins.open", mock.mock_open())as mock_open: @@ -95,9 +95,9 @@ class TestGemmaMapping(unittest.TestCase): filehandler.write.assert_has_calls(write_calls) - @mock.patch("wqflask.marker_regression.gemma_mapping.flat_files") - @mock.patch("wqflask.marker_regression.gemma_mapping.create_trait") - @mock.patch("wqflask.marker_regression.gemma_mapping.create_dataset") + @mock.patch("gn2.wqflask.marker_regression.gemma_mapping.flat_files") + @mock.patch("gn2.wqflask.marker_regression.gemma_mapping.create_trait") + @mock.patch("gn2.wqflask.marker_regression.gemma_mapping.create_dataset") def test_gen_covariates_file(self, create_dataset, create_trait, flat_files): """add tests for generating covariates files""" covariates = "X1:X2,Y1:Y2,M1:M3,V1:V2" @@ -140,9 +140,9 @@ class TestGemmaMapping(unittest.TestCase): filehandler.write.assert_has_calls([mock.call( '-9\t'), mock.call('-9\t'), mock.call('-9\t'), mock.call('-9\t'), mock.call('\n')]) - @mock.patch("wqflask.marker_regression.gemma_mapping.TEMPDIR", "/home/tmp") - @mock.patch("wqflask.marker_regression.gemma_mapping.os") - @mock.patch("wqflask.marker_regression.gemma_mapping.json") + @mock.patch("gn2.wqflask.marker_regression.gemma_mapping.TEMPDIR", "/home/tmp") + @mock.patch("gn2.wqflask.marker_regression.gemma_mapping.os") + @mock.patch("gn2.wqflask.marker_regression.gemma_mapping.json") def test_parse_loco_outputfile_found(self, mock_json, mock_os): """add tests for parse loco output file found""" mock_json.load.return_value = { @@ -174,8 +174,8 @@ X\tM5\t12\tQ\tE\tMMB\tR\t21.1\tW\t0.65\t0.6""" {'name': 'M5', 'chr': 'X', 'Mb': 1.2e-05, 'p_value': 0.6, 'additive': -10.55, 'lod_score': 0.22184874961635637}] self.assertEqual(expected_results, results) - @mock.patch("wqflask.marker_regression.gemma_mapping.TEMPDIR", "/home/tmp") - @mock.patch("wqflask.marker_regression.gemma_mapping.os") + @mock.patch("gn2.wqflask.marker_regression.gemma_mapping.TEMPDIR", "/home/tmp") + @mock.patch("gn2.wqflask.marker_regression.gemma_mapping.os") def test_parse_loco_outputfile_not_found(self, mock_os): """add tests for parse loco output where output file not found""" diff --git a/gn2/tests/unit/wqflask/marker_regression/test_plink_mapping.py b/gn2/tests/unit/wqflask/marker_regression/test_plink_mapping.py index 4c13b907..7542e15a 100644 --- a/gn2/tests/unit/wqflask/marker_regression/test_plink_mapping.py +++ b/gn2/tests/unit/wqflask/marker_regression/test_plink_mapping.py @@ -27,7 +27,7 @@ class TestPlinkMapping(unittest.TestCase): self.assertEqual([], build_line_list()) self.assertEqual(["this", "is", "an,", "irregular", "line"], results) - @mock.patch("wqflask.marker_regression.plink_mapping.flat_files") + @mock.patch("gn2.wqflask.marker_regression.plink_mapping.flat_files") def test_get_samples_from_ped_file(self, mock_flat_files): """test for getting samples from ped file""" dataset = AttributeSetter({"group": AttributeSetter({"name": "n_1"})}) @@ -42,8 +42,8 @@ Expected_2\there self.assertEqual( ["Expected_1", "Expected_2", "Expected_3"], results) - @mock.patch("wqflask.marker_regression.plink_mapping.TMPDIR", "/home/user/data/") - @mock.patch("wqflask.marker_regression.plink_mapping.get_samples_from_ped_file") + @mock.patch("gn2.wqflask.marker_regression.plink_mapping.TMPDIR", "/home/user/data/") + @mock.patch("gn2.wqflask.marker_regression.plink_mapping.get_samples_from_ped_file") def test_gen_pheno_txt_file_plink(self, mock_samples): """test for getting gen_pheno txt file""" mock_samples.return_value = ["Expected_1", "Expected_2", "Expected_3"] @@ -64,8 +64,8 @@ Expected_2\there filehandler.close.assert_called_once() - @mock.patch("wqflask.marker_regression.plink_mapping.TMPDIR", "/home/user/data/") - @mock.patch("wqflask.marker_regression.plink_mapping.build_line_list") + @mock.patch("gn2.wqflask.marker_regression.plink_mapping.TMPDIR", "/home/user/data/") + @mock.patch("gn2.wqflask.marker_regression.plink_mapping.build_line_list") def test_parse_plink_output(self, mock_line_list): """test for parsing plink output""" chromosomes = [0, 34, 110, 89, 123, 23, 2] diff --git a/gn2/tests/unit/wqflask/marker_regression/test_qtlreaper_mapping.py b/gn2/tests/unit/wqflask/marker_regression/test_qtlreaper_mapping.py index 2268f4cb..c2753141 100644 --- a/gn2/tests/unit/wqflask/marker_regression/test_qtlreaper_mapping.py +++ b/gn2/tests/unit/wqflask/marker_regression/test_qtlreaper_mapping.py @@ -7,7 +7,7 @@ from gn2.wqflask.marker_regression.qtlreaper_mapping import gen_pheno_txt_file class TestQtlReaperMapping(unittest.TestCase): - @mock.patch("wqflask.marker_regression.qtlreaper_mapping.TEMPDIR", "/home/user/data") + @mock.patch("gn2.wqflask.marker_regression.qtlreaper_mapping.TEMPDIR", "/home/user/data") def test_gen_pheno_txt_file(self): vals = ["V1", "x", "V4", "V3", "x"] samples = ["S1", "S2", "S3", "S4", "S5"] diff --git a/gn2/tests/unit/wqflask/marker_regression/test_rqtl_mapping.py b/gn2/tests/unit/wqflask/marker_regression/test_rqtl_mapping.py index 5cfce28c..9f646fb0 100644 --- a/gn2/tests/unit/wqflask/marker_regression/test_rqtl_mapping.py +++ b/gn2/tests/unit/wqflask/marker_regression/test_rqtl_mapping.py @@ -15,9 +15,9 @@ class MockDataset: class TestRqtlMapping(unittest.TestCase): """Tests for functions in rqtl_mapping.py""" - @mock.patch("wqflask.marker_regression.rqtl_mapping.requests.post") - @mock.patch("wqflask.marker_regression.rqtl_mapping.locate") - @mock.patch("wqflask.marker_regression.rqtl_mapping.write_phenotype_file") + @mock.patch("gn2.wqflask.marker_regression.rqtl_mapping.requests.post") + @mock.patch("gn2.wqflask.marker_regression.rqtl_mapping.locate") + @mock.patch("gn2.wqflask.marker_regression.rqtl_mapping.write_phenotype_file") def test_run_rqtl_with_perm(self, mock_write_pheno_file, mock_locate, mock_post): """Test for run_rqtl with permutations > 0""" dataset_group = MockGroup("GP1", "file_geno") diff --git a/gn2/tests/unit/wqflask/marker_regression/test_run_mapping.py b/gn2/tests/unit/wqflask/marker_regression/test_run_mapping.py index dd67ce49..817bf2b9 100644 --- a/gn2/tests/unit/wqflask/marker_regression/test_run_mapping.py +++ b/gn2/tests/unit/wqflask/marker_regression/test_run_mapping.py @@ -61,7 +61,7 @@ class TestRunMapping(unittest.TestCase): result_2 = get_genofile_samplelist(self.dataset) self.assertEqual(result_2, []) - @mock.patch("wqflask.marker_regression.run_mapping.data_set") + @mock.patch("gn2.wqflask.marker_regression.run_mapping.data_set") def test_if_geno_db_exists(self, mock_data_set): mock_data_set.create_dataset.side_effect = [ AttributeSetter({}), Exception()] @@ -178,7 +178,7 @@ class TestRunMapping(unittest.TestCase): with mock.patch("builtins.open", mock.mock_open()) as mock_open: - with mock.patch("wqflask.marker_regression.run_mapping.datetime.datetime", new=datetime_mock): + with mock.patch("gn2.wqflask.marker_regression.run_mapping.datetime.datetime", new=datetime_mock): export_mapping_results(dataset=self.dataset, trait=self.trait, markers=markers, results_path="~/results", mapping_method="gemma", mapping_scale="physic", score_type="-logP", transform="qnorm", @@ -215,7 +215,7 @@ class TestRunMapping(unittest.TestCase): filehandler = mock_open() filehandler.write.assert_has_calls(write_calls) - @mock.patch("wqflask.marker_regression.run_mapping.random.choice") + @mock.patch("gn2.wqflask.marker_regression.run_mapping.random.choice") def test_write_input_for_browser(self, mock_choice): """test for writing input for browser""" mock_choice.side_effect = ["F", "i", "l", "e", "s", "x"] diff --git a/gn2/tests/unit/wqflask/show_trait/test_export_trait_data.py b/gn2/tests/unit/wqflask/show_trait/test_export_trait_data.py index a933d0bf..1ecf394b 100644 --- a/gn2/tests/unit/wqflask/show_trait/test_export_trait_data.py +++ b/gn2/tests/unit/wqflask/show_trait/test_export_trait_data.py @@ -16,9 +16,9 @@ class AttributesSetter: class TestExportTraits(unittest.TestCase): """Test methods for exporting traits and metadata""" - @mock.patch("wqflask.show_trait.export_trait_data.datetime") - @mock.patch("wqflask.show_trait.export_trait_data.create_trait") - @mock.patch("wqflask.show_trait.export_trait_data.data_set") + @mock.patch("gn2.wqflask.show_trait.export_trait_data.datetime") + @mock.patch("gn2.wqflask.show_trait.export_trait_data.create_trait") + @mock.patch("gn2.wqflask.show_trait.export_trait_data.data_set") def test_get_export_metadata(self, data_mock, trait_mock, date_mock): """test for exporting metadata with dataset.type=Publish""" mock_dataset = AttributesSetter({"type": "Publish", diff --git a/gn2/tests/unit/wqflask/snp_browser/test_snp_browser.py b/gn2/tests/unit/wqflask/snp_browser/test_snp_browser.py index c33f46ef..bf0421c0 100644 --- a/gn2/tests/unit/wqflask/snp_browser/test_snp_browser.py +++ b/gn2/tests/unit/wqflask/snp_browser/test_snp_browser.py @@ -102,7 +102,7 @@ class TestSnpBrowser(unittest.TestCase): self.assertEqual(expected_results, results_with_snp) self.assertEqual(expected_results_with_indel, results_with_indel) - @mock.patch("wqflask.snp_browser.snp_browser.database_connection") + @mock.patch("gn2.wqflask.snp_browser.snp_browser.database_connection") def test_get_gene_id(self, mock_db): db_query_value = ( "SELECT geneId FROM GeneList WHERE " "SpeciesId = %s AND geneSymbol = %s" @@ -122,7 +122,7 @@ class TestSnpBrowser(unittest.TestCase): ) self.assertEqual(results, "517d729f-aa13-4413-a885-40a3f7ff768a") - @mock.patch("wqflask.snp_browser.snp_browser.database_connection") + @mock.patch("gn2.wqflask.snp_browser.snp_browser.database_connection") def test_gene_id_name_dict(self, mock_db): no_gene_names = [] conn = mock.MagicMock() @@ -164,7 +164,7 @@ class TestSnpBrowser(unittest.TestCase): self.assertEqual(results_found, expected_found) self.assertEqual(no_results, {}) - @mock.patch("wqflask.snp_browser.snp_browser.database_connection") + @mock.patch("gn2.wqflask.snp_browser.snp_browser.database_connection") def test_check_if_in_gene(self, mock_db): conn = mock.MagicMock() mock_db.return_value.__enter__.return_value = conn @@ -196,7 +196,7 @@ class TestSnpBrowser(unittest.TestCase): ) self.assertEqual(gene_not_found, "") - @mock.patch("wqflask.snp_browser.snp_browser.database_connection") + @mock.patch("gn2.wqflask.snp_browser.snp_browser.database_connection") def test_get_browser_sample_lists(self, mock_db): conn = mock.MagicMock() mock_db.return_value.__enter__.return_value = conn diff --git a/gn2/tests/unit/wqflask/test_collect.py b/gn2/tests/unit/wqflask/test_collect.py index 41d6bf74..6c1bafa5 100644 --- a/gn2/tests/unit/wqflask/test_collect.py +++ b/gn2/tests/unit/wqflask/test_collect.py @@ -42,7 +42,7 @@ class TestCollect(unittest.TestCase): def tearDown(self): self.app_context.pop() - @mock.patch("wqflask.collect.g", MockFlaskG()) + @mock.patch("gn2.wqflask.collect.g", MockFlaskG()) def test_process_traits_with_bytestring(self): """ Test that the correct traits are returned when the user is logged @@ -58,7 +58,7 @@ class TestCollect(unittest.TestCase): '1452447_at:HC_M2_0606_P', '1452452_at:HC_M2_0606_P'])) - @mock.patch("wqflask.collect.g", MockFlaskG()) + @mock.patch("gn2.wqflask.collect.g", MockFlaskG()) def test_process_traits_with_normal_string(self): """ Test that the correct traits are returned when the user is logged diff --git a/gn2/tests/unit/wqflask/test_resource_manager.py b/gn2/tests/unit/wqflask/test_resource_manager.py index f4335425..a4b3a0ee 100644 --- a/gn2/tests/unit/wqflask/test_resource_manager.py +++ b/gn2/tests/unit/wqflask/test_resource_manager.py @@ -58,7 +58,7 @@ class TestGetUserMembership(unittest.TestCase): class TestCheckUserAccessRole(unittest.TestCase): """Test cases for `get_highest_user_access_role`""" - @mock.patch("wqflask.resource_manager.requests.get") + @mock.patch("gn2.wqflask.resource_manager.requests.get") def test_edit_access(self, requests_mock): """Test that the right access roles are set""" response = mock.PropertyMock(return_value=json.dumps( @@ -76,7 +76,7 @@ class TestCheckUserAccessRole(unittest.TestCase): "metadata": DataRole.EDIT, "admin": AdminRole.EDIT_ACCESS}) - @mock.patch("wqflask.resource_manager.requests.get") + @mock.patch("gn2.wqflask.resource_manager.requests.get") def test_no_access(self, requests_mock): response = mock.PropertyMock(return_value=json.dumps( { diff --git a/gn2/tests/wqflask/show_trait/test_show_trait.py b/gn2/tests/wqflask/show_trait/test_show_trait.py index 97618d31..51b0c82c 100644 --- a/gn2/tests/wqflask/show_trait/test_show_trait.py +++ b/gn2/tests/wqflask/show_trait/test_show_trait.py @@ -39,10 +39,10 @@ def test_check_if_attr_exists(trait, id_type, expected): def test_get_ncbi_summary_request(mocker): trait = TraitObject({"geneid": "id"}) - mocker.patch("wqflask.show_trait.show_trait.check_if_attr_exists", + mocker.patch("gn2.wqflask.show_trait.show_trait.check_if_attr_exists", return_value=True) mock_get = mocker.patch( - "wqflask.show_trait.show_trait.requests.get", + "gn2.wqflask.show_trait.show_trait.requests.get", return_value=TraitObject({"content": """{ "result":{ "id":{ @@ -143,7 +143,7 @@ class TestTraits(unittest.TestCase): self.assertEqual(results, "this is a descriptionN/A") self.assertEqual(results_no_unit, "value") - @mock.patch("wqflask.show_trait.show_trait.database_connection") + @mock.patch("gn2.wqflask.show_trait.show_trait.database_connection") def test_get_nearest_marker(self, mock_db): """test for getting nearest marker with non-empty db""" conn = mock.MagicMock() @@ -170,7 +170,7 @@ class TestTraits(unittest.TestCase): self.assertEqual(results_with_item_db, "Geno1") - @mock.patch("wqflask.show_trait.show_trait.database_connection") + @mock.patch("gn2.wqflask.show_trait.show_trait.database_connection") def test_get_nearest_marker_empty_db(self, mock_db): """test for getting nearest marker with empty db""" conn = mock.MagicMock() @@ -187,7 +187,7 @@ class TestTraits(unittest.TestCase): cursor.execute.assert_called_once() self.assertEqual(results_empty_db, "") - @mock.patch("wqflask.show_trait.show_trait.get_scales_from_genofile") + @mock.patch("gn2.wqflask.show_trait.show_trait.get_scales_from_genofile") def test_get_genotype_scales_with_genofile_is_list(self, mock_get_scales): """test for getting genotype scales with genofile as list """ # where genofile is instance of list @@ -211,7 +211,7 @@ class TestTraits(unittest.TestCase): mock_get_scales.assert_has_calls(multiple_calls) self.assertEqual(results, expected_results) - @mock.patch("wqflask.show_trait.show_trait.get_scales_from_genofile") + @mock.patch("gn2.wqflask.show_trait.show_trait.get_scales_from_genofile") def test_genotype_scales_with_genofile_other(self, mock_get_scales): """test for getting genotype scales with genofile as a string""" file_location = "~/another_file_location" @@ -220,7 +220,7 @@ class TestTraits(unittest.TestCase): self.assertEqual(get_genotype_scales(file_location), expected_results) mock_get_scales.assert_called_once_with(file_location) - @mock.patch("wqflask.show_trait.show_trait.locate_ignore_error") + @mock.patch("gn2.wqflask.show_trait.show_trait.locate_ignore_error") def test_get_scales_from_genofile_found(self, mock_ignore_location): """"add test for get scales from genofile where file is found""" mock_ignore_location.return_value = True @@ -245,7 +245,7 @@ class TestTraits(unittest.TestCase): result2 = get_scales_from_genofile(file_location) self.assertEqual([['morgan', 'cM']], result2) - @mock.patch("wqflask.show_trait.show_trait.locate_ignore_error") + @mock.patch("gn2.wqflask.show_trait.show_trait.locate_ignore_error") def test_get_scales_from_genofile_not_found(self, mock_location_ignore): mock_location_ignore.return_value = False |