aboutsummaryrefslogtreecommitdiff
path: root/wqflask
diff options
context:
space:
mode:
authorBonfaceKilz2021-10-13 13:05:26 +0300
committerBonfaceKilz2021-10-25 14:00:14 +0300
commit212d19c29a42bd6966965b166cdbb4dd642e5eb4 (patch)
treeb622998ada4507203aa13c15d8c738eab6feab59 /wqflask
parenteb2e43434c137a070db5943db21d3b92afdd9a91 (diff)
downloadgenenetwork2-212d19c29a42bd6966965b166cdbb4dd642e5eb4.tar.gz
Add test-cases for `get_user_membership`
Diffstat (limited to 'wqflask')
-rw-r--r--wqflask/tests/unit/wqflask/test_resource_manager.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/wqflask/tests/unit/wqflask/test_resource_manager.py b/wqflask/tests/unit/wqflask/test_resource_manager.py
new file mode 100644
index 00000000..a27f40e1
--- /dev/null
+++ b/wqflask/tests/unit/wqflask/test_resource_manager.py
@@ -0,0 +1,51 @@
+"""Test cases for wqflask/resource_manager.py"""
+import unittest
+
+from unittest import mock
+from wqflask.resource_manager import get_user_membership
+
+
+class TestGetUserMembership(unittest.TestCase):
+ """Test cases for `get_user_membership`"""
+
+ def setUp(self):
+ conn = mock.MagicMock()
+ conn.hgetall.return_value = {
+ '7fa95d07-0e2d-4bc5-b47c-448fdc1260b2': (
+ '{"name": "editors", '
+ '"admins": ["8ad942fe-490d-453e-bd37-56f252e41604", "rand"], '
+ '"members": ["8ad942fe-490d-453e-bd37-56f252e41603", '
+ '"rand"], '
+ '"changed_timestamp": "Oct 06 2021 06:39PM", '
+ '"created_timestamp": "Oct 06 2021 06:39PM"}')}
+ self.conn = conn
+
+ def test_user_is_group_member_only(self):
+ """Test that a user is only a group member"""
+ self.assertEqual(
+ get_user_membership(
+ conn=self.conn,
+ user_id="8ad942fe-490d-453e-bd37-56f252e41603",
+ group_id="7fa95d07-0e2d-4bc5-b47c-448fdc1260b2"),
+ {"member": True,
+ "admin": False})
+
+ def test_user_is_group_admin_only(self):
+ """Test that a user is a group admin only"""
+ self.assertEqual(
+ get_user_membership(
+ conn=self.conn,
+ user_id="8ad942fe-490d-453e-bd37-56f252e41604",
+ group_id="7fa95d07-0e2d-4bc5-b47c-448fdc1260b2"),
+ {"member": False,
+ "admin": True})
+
+ def test_user_is_both_group_member_and_admin(self):
+ """Test that a user is both an admin and member of a group"""
+ self.assertEqual(
+ get_user_membership(
+ conn=self.conn,
+ user_id="rand",
+ group_id="7fa95d07-0e2d-4bc5-b47c-448fdc1260b2"),
+ {"member": True,
+ "admin": True})