From c3ce0e40dc2c1982d50655b5d49ab0e1da922b1a Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Fri, 15 Sep 2023 10:14:54 +0300 Subject: Add System resource, and group resource(s) to list of user resources * The system resource is public, and should be present for all users. * Each user that is a member of a group, should have their group show up in their list of resources. * Fix the SQL join: add an `ON ...` clause. --- tests/unit/auth/fixtures/group_fixtures.py | 21 +++++++++++++++++++-- tests/unit/auth/test_resources.py | 14 +++++++------- 2 files changed, 26 insertions(+), 9 deletions(-) (limited to 'tests') diff --git a/tests/unit/auth/fixtures/group_fixtures.py b/tests/unit/auth/fixtures/group_fixtures.py index 93133d2..79683c0 100644 --- a/tests/unit/auth/fixtures/group_fixtures.py +++ b/tests/unit/auth/fixtures/group_fixtures.py @@ -15,6 +15,16 @@ TEST_GROUP_02 = Group(uuid.UUID("e37d59d7-c05e-4d67-b479-81e627d8d634"), "AnotherTestGroup", {}) TEST_GROUPS = (TEST_GROUP_01, TEST_GROUP_02) +SYSTEM_CATEGORY = ResourceCategory( + uuid.UUID("aa3d787f-af6a-44fa-9b0b-c82d40e54ad2"), + "system", + "The overall system.") +SYSTEM_RESOURCE = Resource( + uuid.UUID("0248b289-b277-4eaa-8c94-88a434d14b6e"), + "GeneNetwork System", + SYSTEM_CATEGORY, + True) + GROUP_CATEGORY = ResourceCategory( uuid.UUID("1e0f70ee-add5-4358-8c6c-43de77fa4cce"), "group", @@ -24,11 +34,17 @@ GROUPS_AS_RESOURCES = tuple({ "resource_id": res_id, "resource_name": group.group_name, "category_id": str(GROUP_CATEGORY.resource_category_id), - "public": "1" + "public": "0" } for res_id, group in zip( ("38d1807d-105f-44a7-8327-7e2d973b6d8d", "89458ef6-e090-4b53-8c2c-59eaf2785f11"), TEST_GROUPS)) +GROUP_RESOURCES = tuple( + Resource(uuid.UUID(row["resource_id"]), + row["resource_name"], + GROUP_CATEGORY, + False) + for row in GROUPS_AS_RESOURCES) TEST_RESOURCES_GROUP_01 = ( Resource(uuid.UUID("26ad1668-29f5-439d-b905-84d551f85955"), @@ -60,7 +76,8 @@ TEST_RESOURCES_GROUP_02 = ( True)) TEST_RESOURCES = TEST_RESOURCES_GROUP_01 + TEST_RESOURCES_GROUP_02 -TEST_RESOURCES_PUBLIC = (TEST_RESOURCES_GROUP_01[0], TEST_RESOURCES_GROUP_02[1]) +TEST_RESOURCES_PUBLIC = ( + SYSTEM_RESOURCE, TEST_RESOURCES_GROUP_01[0], TEST_RESOURCES_GROUP_02[1]) def __gtuple__(cursor): return tuple(dict(row) for row in cursor.fetchall()) diff --git a/tests/unit/auth/test_resources.py b/tests/unit/auth/test_resources.py index ee4f312..9b4d0e7 100644 --- a/tests/unit/auth/test_resources.py +++ b/tests/unit/auth/test_resources.py @@ -77,6 +77,9 @@ def sort_key_resources(resource): """Sort-key for resources.""" return resource.resource_id +PUBLIC_RESOURCES = sorted( + conftest.TEST_RESOURCES_PUBLIC, key=sort_key_resources) + @pytest.mark.unit_test def test_public_resources(fxtr_resources): """ @@ -85,12 +88,8 @@ def test_public_resources(fxtr_resources): THEN: only list the resources that are public """ conn, _res = fxtr_resources - 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=sort_key_resources) + assert sorted( + public_resources(conn), key=sort_key_resources) == PUBLIC_RESOURCES @pytest.mark.unit_test @pytest.mark.parametrize( @@ -99,7 +98,8 @@ PUBLIC_RESOURCES = sorted( conftest.TEST_USERS, (sorted( {res.resource_id: res for res in - (conftest.TEST_RESOURCES_GROUP_01 + + ((conftest.GROUP_RESOURCES[0],) + + conftest.TEST_RESOURCES_GROUP_01 + conftest.TEST_RESOURCES_PUBLIC)}.values(), key=sort_key_resources), sorted( -- cgit v1.2.3