From 16faa26e52b1f0191595e16550d553907d2f9d67 Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Thu, 17 Sep 2020 17:21:30 +0300 Subject: Fix errors in tests * wqflask/tests/utility/test_authentication_tools.py test_check_resource_availability_non_default_mask): Mock flask's global 'g' variable properly. * wqflask/tests/base/test_trait.py: Ditto. * wqflask/tests/utility/test_authentication_tools.py: Ditto. --- wqflask/tests/base/test_trait.py | 9 +++------ wqflask/tests/utility/test_authentication_tools.py | 8 ++------ 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/wqflask/tests/base/test_trait.py b/wqflask/tests/base/test_trait.py index 53b0d440..d333458a 100644 --- a/wqflask/tests/base/test_trait.py +++ b/wqflask/tests/base/test_trait.py @@ -38,9 +38,8 @@ class TestRetrieveTraitInfo(unittest.TestCase): dataset={}) @mock.patch('base.trait.requests.get') - @mock.patch('base.trait.g') + @mock.patch('base.trait.g', mock.Mock()) def test_retrieve_trait_info_with_empty_trait_info(self, - g_mock, requests_mock): """Empty trait info""" requests_mock.return_value = TestNilResponse() @@ -49,9 +48,8 @@ class TestRetrieveTraitInfo(unittest.TestCase): dataset=mock.MagicMock()) @mock.patch('base.trait.requests.get') - @mock.patch('base.trait.g') + @mock.patch('base.trait.g', mock.Mock()) def test_retrieve_trait_info_with_non_empty_trait_info(self, - g_mock, requests_mock): """Test that attributes are set""" mock_dataset = mock.MagicMock() @@ -66,9 +64,8 @@ class TestRetrieveTraitInfo(unittest.TestCase): self.assertEqual(test_trait.d, 4) @mock.patch('base.trait.requests.get') - @mock.patch('base.trait.g') + @mock.patch('base.trait.g', mock.Mock()) def test_retrieve_trait_info_utf8_parsing(self, - g_mock, requests_mock): """Test that utf-8 strings are parsed correctly""" utf_8_string = "test_string" diff --git a/wqflask/tests/utility/test_authentication_tools.py b/wqflask/tests/utility/test_authentication_tools.py index 99c74245..ef94eabc 100644 --- a/wqflask/tests/utility/test_authentication_tools.py +++ b/wqflask/tests/utility/test_authentication_tools.py @@ -38,17 +38,15 @@ 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.patch('utility.authentication_tools.g', mock.Mock()) @mock.patch('utility.authentication_tools.get_resource_id') def test_check_resource_availability_default_mask( self, resource_id_mock, - g_mock, redis_mock, add_new_resource_mock): """Test the resource availability with default mask""" resource_id_mock.return_value = 1 - g_mock.return_value = mock.Mock() redis_mock.smembers.return_value = [] test_dataset = mock.MagicMock() type(test_dataset).type = mock.PropertyMock(return_value="Test") @@ -58,18 +56,16 @@ class TestCheckResourceAvailability(unittest.TestCase): @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') + @mock.patch('utility.authentication_tools.g', TestUserSession()) @mock.patch('utility.authentication_tools.get_resource_id') def test_check_resource_availability_non_default_mask( self, resource_id_mock, - g_mock, redis_mock, add_new_resource_mock, requests_mock): """Test the resource availability with default mask""" resource_id_mock.return_value = 1 - g_mock.return_value = mock.Mock() redis_mock.smembers.return_value = [] add_new_resource_mock.return_value = {"default_mask": 2} requests_mock.return_value = TestResponse() -- cgit v1.2.3