about summary refs log tree commit diff
path: root/tests/unit/auth/test_resources.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-08-23 09:12:07 +0300
committerFrederick Muriuki Muriithi2023-08-23 09:13:02 +0300
commit8d35e0413fa670ef4fc08e7262a12c43b89df6fc (patch)
treedd6bbc1f13a5a241f28f8507a659de1d3474af24 /tests/unit/auth/test_resources.py
parent277297d9a804e09137493bd9e1613df94f154dc0 (diff)
downloadgn-auth-8d35e0413fa670ef4fc08e7262a12c43b89df6fc.tar.gz
pylint: Replace `lambda ...` statements with `def ...`
Diffstat (limited to 'tests/unit/auth/test_resources.py')
-rw-r--r--tests/unit/auth/test_resources.py21
1 files changed, 11 insertions, 10 deletions
diff --git a/tests/unit/auth/test_resources.py b/tests/unit/auth/test_resources.py
index 9d2671c..7018e73 100644
--- a/tests/unit/auth/test_resources.py
+++ b/tests/unit/auth/test_resources.py
@@ -21,7 +21,6 @@ create_resource_failure = {
     "status": "error",
     "message": "Unauthorised: Could not create resource"
 }
-uuid_fn = lambda : uuid.UUID("d32611e3-07fc-4564-b56c-786c6db6de2b")
 
 @pytest.mark.unit_test
 @pytest.mark.parametrize(
@@ -33,7 +32,7 @@ uuid_fn = lambda : uuid.UUID("d32611e3-07fc-4564-b56c-786c6db6de2b")
             "test_resource", resource_category, False),))))
 def test_create_resource(mocker, fxtr_users_in_group, user, expected):
     """Test that resource creation works as expected."""
-    mocker.patch("gn_auth.auth.authorisation.resources.models.uuid4", uuid_fn)
+    mocker.patch("gn_auth.auth.authorisation.resources.models.uuid4", conftest.uuid_fn)
     mocker.patch("gn_auth.auth.authorisation.checks.require_oauth.acquire",
                  conftest.get_tokeniser(user))
     conn, _group, _users = fxtr_users_in_group
@@ -63,7 +62,7 @@ def test_create_resource(mocker, fxtr_users_in_group, user, expected):
 def test_create_resource_raises_for_unauthorised_users(
         mocker, fxtr_users_in_group, user, expected):
     """Test that resource creation works as expected."""
-    mocker.patch("gn_auth.auth.authorisation.resources.models.uuid4", uuid_fn)
+    mocker.patch("gn_auth.auth.authorisation.resources.models.uuid4", conftest.uuid_fn)
     mocker.patch("gn_auth.auth.authorisation.checks.require_oauth.acquire",
                  conftest.get_tokeniser(user))
     conn, _group, _users = fxtr_users_in_group
@@ -71,7 +70,9 @@ def test_create_resource_raises_for_unauthorised_users(
         assert create_resource(
             conn, "test_resource", resource_category, user, False) == expected
 
-SORTKEY = lambda resource: resource.resource_id
+def sort_key_resources(resource):
+    """Sort-key for resources."""
+    return resource.resource_id
 
 @pytest.mark.unit_test
 def test_public_resources(fxtr_resources):
@@ -81,12 +82,12 @@ def test_public_resources(fxtr_resources):
     THEN: only list the resources that are public
     """
     conn, _res = fxtr_resources
-    assert sorted(public_resources(conn), key=SORTKEY) == sorted(tuple(
-        res for res in conftest.TEST_RESOURCES if res.public), key=SORTKEY)
+    assert sorted(public_resources(conn), key=sort_key_resources) == sorted(tuple(
+        res for res in conftest.TEST_RESOURCES if res.public), key=sort_key_resources)
 
 PUBLIC_RESOURCES = sorted(
     {res.resource_id: res for res in conftest.TEST_RESOURCES_PUBLIC}.values(),
-    key=SORTKEY)
+    key=sort_key_resources)
 
 @pytest.mark.unit_test
 @pytest.mark.parametrize(
@@ -97,13 +98,13 @@ PUBLIC_RESOURCES = sorted(
             {res.resource_id: res for res in
              (conftest.TEST_RESOURCES_GROUP_01 +
               conftest.TEST_RESOURCES_PUBLIC)}.values(),
-            key=SORTKEY),
+            key=sort_key_resources),
          sorted(
              {res.resource_id: res for res in
               ((conftest.TEST_RESOURCES_GROUP_01[1],) +
                conftest.TEST_RESOURCES_PUBLIC)}.values()
              ,
-             key=SORTKEY),
+             key=sort_key_resources),
          PUBLIC_RESOURCES, PUBLIC_RESOURCES))))
 def test_user_resources(fxtr_group_user_roles, user, expected):
     """
@@ -114,4 +115,4 @@ def test_user_resources(fxtr_group_user_roles, user, expected):
     conn, *_others = fxtr_group_user_roles
     assert sorted(
         {res.resource_id: res for res in user_resources(conn, user)
-         }.values(), key=SORTKEY) == expected
+         }.values(), key=sort_key_resources) == expected