From 05628e484fb238cea6ac3267be959b2bb0702c61 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Thu, 27 Oct 2022 12:20:35 +0300 Subject: Refactor: Pass user id to `check_resource_availability` * Pass the user_id for the current user to the `check_resource_availability` function as an argument, rather than using the global `g.user_session.user_id` value. --- wqflask/tests/unit/utility/test_authentication_tools.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'wqflask/tests') diff --git a/wqflask/tests/unit/utility/test_authentication_tools.py b/wqflask/tests/unit/utility/test_authentication_tools.py index 024ab43f..fb8de292 100644 --- a/wqflask/tests/unit/utility/test_authentication_tools.py +++ b/wqflask/tests/unit/utility/test_authentication_tools.py @@ -21,6 +21,8 @@ class TestUser: """Mockes user id. Used in Flask.g.user_session.user_id""" return b"Jane" +user_id = b"Jane" + class TestUserSession: """Mock user session""" @@ -52,7 +54,7 @@ class TestCheckResourceAvailability(unittest.TestCase): test_dataset = mock.MagicMock() type(test_dataset).type = mock.PropertyMock(return_value="Test") add_new_resource_mock.return_value = {"default_mask": 2} - self.assertEqual(check_resource_availability(test_dataset), 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') @@ -72,7 +74,7 @@ class TestCheckResourceAvailability(unittest.TestCase): requests_mock.return_value = TestResponse() test_dataset = mock.MagicMock() type(test_dataset).type = mock.PropertyMock(return_value="Test") - self.assertEqual(check_resource_availability(test_dataset), + self.assertEqual(check_resource_availability(test_dataset, user_id), ['foo']) @mock.patch('utility.authentication_tools.webqtlConfig.SUPER_PRIVILEGES', @@ -95,14 +97,14 @@ class TestCheckResourceAvailability(unittest.TestCase): requests_mock.return_value = TestResponse() test_dataset = mock.MagicMock() type(test_dataset).type = mock.PropertyMock(return_value="Test") - self.assertEqual(check_resource_availability(test_dataset), + self.assertEqual(check_resource_availability(test_dataset, user_id), "SUPERUSER") @mock.patch('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"), + self.assertEqual(check_resource_availability("Test", user_id), "John Doe") @mock.patch('utility.authentication_tools.webqtlConfig.DEFAULT_PRIVILEGES', @@ -111,7 +113,7 @@ class TestCheckResourceAvailability(unittest.TestCase): """Test the resource availability if the dataset is a string""" test_dataset = mock.MagicMock() type(test_dataset).type = mock.PropertyMock(return_value="Temp") - self.assertEqual(check_resource_availability(test_dataset), + self.assertEqual(check_resource_availability(test_dataset, user_id), "John Doe") -- cgit v1.2.3