From c1d775162c2a657f9e8001914cc216cd70460371 Mon Sep 17 00:00:00 2001 From: zsloan Date: Thu, 18 Feb 2021 21:36:28 +0000 Subject: Patched utility.authentication_tools.g as TestUserSession because otherwise the str.encode failed on the mock.Mock() object, and this also seems consistent with the way it's done in a later method --- wqflask/tests/unit/utility/test_authentication_tools.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wqflask/tests/unit/utility/test_authentication_tools.py b/wqflask/tests/unit/utility/test_authentication_tools.py index 5c391be5..6d817f5e 100644 --- a/wqflask/tests/unit/utility/test_authentication_tools.py +++ b/wqflask/tests/unit/utility/test_authentication_tools.py @@ -5,7 +5,6 @@ from unittest import mock from utility.authentication_tools import check_resource_availability from utility.authentication_tools import add_new_resource - class TestResponse: """Mock Test Response after a request""" @property @@ -38,7 +37,7 @@ 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', mock.Mock()) + @mock.patch('utility.authentication_tools.g', TestUserSession()) @mock.patch('utility.authentication_tools.get_resource_id') def test_check_resource_availability_default_mask( self, @@ -46,6 +45,7 @@ class TestCheckResourceAvailability(unittest.TestCase): redis_mock, add_new_resource_mock): """Test the resource availability with default mask""" + resource_id_mock.return_value = 1 redis_mock.smembers.return_value = [] test_dataset = mock.MagicMock() @@ -64,7 +64,7 @@ class TestCheckResourceAvailability(unittest.TestCase): redis_mock, add_new_resource_mock, requests_mock): - """Test the resource availability with default mask""" + """Test the resource availability with non-default mask""" resource_id_mock.return_value = 1 redis_mock.smembers.return_value = [] add_new_resource_mock.return_value = {"default_mask": 2} -- cgit v1.2.3 From e55861d6ced9a5c746a8e28c9a9c067e3927275a Mon Sep 17 00:00:00 2001 From: zsloan Date: Thu, 18 Feb 2021 21:47:39 +0000 Subject: Fixed test_run_mapping.py to make export_mapping_results test work correctly --- wqflask/tests/unit/wqflask/marker_regression/test_run_mapping.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/wqflask/tests/unit/wqflask/marker_regression/test_run_mapping.py b/wqflask/tests/unit/wqflask/marker_regression/test_run_mapping.py index 4129cc0c..a29d8cfb 100644 --- a/wqflask/tests/unit/wqflask/marker_regression/test_run_mapping.py +++ b/wqflask/tests/unit/wqflask/marker_regression/test_run_mapping.py @@ -180,14 +180,19 @@ class TestRunMapping(unittest.TestCase): with mock.patch("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_scale="physic", score_type="-log(p)") + results_path="~/results", mapping_scale="physic", score_type="-log(p)", + transform="qnorm", covariates="Dataset1:Trait1,Dataset2:Trait2", n_samples="100") write_calls = [ mock.call('Time/Date: 09/01/19 / 10:12:12\n'), mock.call('Population: Human GP1_\n'), mock.call( 'Data Set: dataser_1\n'), + mock.call('N Samples: 100\n'), mock.call('Transform - Quantile Normalized\n'), mock.call('Gene Symbol: IGFI\n'), mock.call( 'Location: X1 @ 123313 Mb\n'), + mock.call('Cofactors (dataset - trait):\n'), + mock.call('Trait1 - Dataset1\n'), + mock.call('Trait2 - Dataset2\n'), mock.call('\n'), mock.call('Name,Chr,'), mock.call('Mb,-log(p)'), mock.call('Cm,-log(p)'), mock.call(',Additive'), mock.call(',Dominance'), -- cgit v1.2.3 From cb039b3e7e8a3a260edc80b0de79fc27af795cf0 Mon Sep 17 00:00:00 2001 From: zsloan Date: Thu, 18 Feb 2021 21:58:58 +0000 Subject: Fixed TestCheckResourceAvailability to make it work after realizing that Redis.smembers apparently returns values as bytes --- wqflask/tests/unit/utility/test_authentication_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wqflask/tests/unit/utility/test_authentication_tools.py b/wqflask/tests/unit/utility/test_authentication_tools.py index 6d817f5e..fff5fd8f 100644 --- a/wqflask/tests/unit/utility/test_authentication_tools.py +++ b/wqflask/tests/unit/utility/test_authentication_tools.py @@ -89,7 +89,7 @@ class TestCheckResourceAvailability(unittest.TestCase): requests_mock): """Test the resource availability if the user is the super user""" resource_id_mock.return_value = 1 - redis_mock.smembers.return_value = ["Jane"] + redis_mock.smembers.return_value = [b"Jane"] add_new_resource_mock.return_value = {"default_mask": 2} requests_mock.return_value = TestResponse() test_dataset = mock.MagicMock() -- cgit v1.2.3 From 4817d78b22b899b9beb3fd3a99a10d6cbcee22d6 Mon Sep 17 00:00:00 2001 From: zsloan Date: Thu, 18 Feb 2021 22:05:43 +0000 Subject: Fixed test_gen_menu to reflect updated query --- wqflask/tests/unit/wqflask/api/test_gen_menu.py | 7 ++++--- wqflask/wqflask/api/gen_menu.py | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/wqflask/tests/unit/wqflask/api/test_gen_menu.py b/wqflask/tests/unit/wqflask/api/test_gen_menu.py index cc666f0c..57eb1650 100644 --- a/wqflask/tests/unit/wqflask/api/test_gen_menu.py +++ b/wqflask/tests/unit/wqflask/api/test_gen_menu.py @@ -244,10 +244,11 @@ class TestGenMenu(unittest.TestCase): "ProbeFreeze, InbredSet, Tissue, Species WHERE " + "Species.Name = 'Mouse' AND Species.Id = " + "InbredSet.SpeciesId AND InbredSet.Name = 'HLC' AND " + - "ProbeSetFreeze.ProbeFreezeId = ProbeFreeze.Id and " + + "ProbeSetFreeze.ProbeFreezeId = ProbeFreeze.Id AND " + "Tissue.Name = 'mRNA' AND ProbeFreeze.TissueId = " + - "Tissue.Id and ProbeFreeze.InbredSetId = InbredSet.Id " + - "ORDER BY ProbeSetFreeze.OrderList DESC") + "Tissue.Id AND ProbeFreeze.InbredSetId = InbredSet.Id AND " + + "ProbeSetFreeze.public > 0 " + + "ORDER BY -ProbeSetFreeze.OrderList DESC, ProbeSetFreeze.CreateTime DESC") @mock.patch('wqflask.api.gen_menu.build_datasets') @mock.patch('wqflask.api.gen_menu.g') diff --git a/wqflask/wqflask/api/gen_menu.py b/wqflask/wqflask/api/gen_menu.py index 4ce19fdb..18afc5ad 100644 --- a/wqflask/wqflask/api/gen_menu.py +++ b/wqflask/wqflask/api/gen_menu.py @@ -207,7 +207,7 @@ def build_datasets(species, group, type_name): "InbredSet.SpeciesId AND InbredSet.Name = '{1}' " "AND ProbeSetFreeze.ProbeFreezeId = ProbeFreeze.Id " "AND Tissue.Name = '{2}' AND ProbeFreeze.TissueId = " - "Tissue.Id and ProbeFreeze.InbredSetId = InbredSet.Id " + "Tissue.Id AND ProbeFreeze.InbredSetId = InbredSet.Id " "AND ProbeSetFreeze.public > 0 " "ORDER BY -ProbeSetFreeze.OrderList DESC, ProbeSetFreeze.CreateTime DESC").format(species, group, type_name)).fetchall() -- cgit v1.2.3