about summary refs log tree commit diff
path: root/wqflask/tests
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2022-10-27 12:20:35 +0300
committerFrederick Muriuki Muriithi2022-10-28 15:57:56 +0300
commit05628e484fb238cea6ac3267be959b2bb0702c61 (patch)
tree9fb701bc4cb8878d5a3f63d49e5f6520cb14783f /wqflask/tests
parent560eb051e127fe4b8b93104200fe55512a72038f (diff)
downloadgenenetwork2-05628e484fb238cea6ac3267be959b2bb0702c61.tar.gz
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.
Diffstat (limited to 'wqflask/tests')
-rw-r--r--wqflask/tests/unit/utility/test_authentication_tools.py12
1 files changed, 7 insertions, 5 deletions
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")