aboutsummaryrefslogtreecommitdiff
path: root/tests/unit
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2022-12-08 08:04:14 +0300
committerFrederick Muriuki Muriithi2022-12-08 08:35:42 +0300
commitb2e4621ba69a4fbbb9bd310aae6c9dee7339a3f5 (patch)
treee7baa7066858d1a41d0c584ad918b5e121426ba5 /tests/unit
parent2be81e59ff416cb8764aaf041a3b8febae4d8875 (diff)
downloadgenenetwork3-b2e4621ba69a4fbbb9bd310aae6c9dee7339a3f5.tar.gz
auth: add test to retrieve public resources
* gn3/auth/authorisation/resources.py: new functions * resource_categories: retrieves all resource categories * public_resources: retrieves all public resources * tests/unit/auth/test_resources.py: test `public_resources` function
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/auth/test_resources.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/tests/unit/auth/test_resources.py b/tests/unit/auth/test_resources.py
index aaf22e6..6dc0e98 100644
--- a/tests/unit/auth/test_resources.py
+++ b/tests/unit/auth/test_resources.py
@@ -5,7 +5,8 @@ import pytest
from gn3.auth.authorisation.groups import Group
from gn3.auth.authorisation.resources import (
- Resource, create_resource, ResourceCategory)
+ Resource, user_resources, create_resource, ResourceCategory,
+ public_resources)
from tests.unit.auth import conftest
@@ -25,7 +26,7 @@ uuid_fn = lambda : uuid.UUID("d32611e3-07fc-4564-b56c-786c6db6de2b")
conftest.TEST_USERS,
(Resource(
group, uuid.UUID("d32611e3-07fc-4564-b56c-786c6db6de2b"),
- "test_resource", resource_category),
+ "test_resource", resource_category, False),
create_resource_failure,
create_resource_failure,
create_resource_failure,
@@ -37,3 +38,16 @@ def test_create_resource(mocker, test_app, test_users_in_group, user, expected):
with test_app.app_context() as flask_context:
flask_context.g.user = user
assert create_resource(conn, "test_resource", resource_category) == expected
+
+SORTKEY = lambda resource: resource.resource_id
+
+@pytest.mark.unit_test
+def test_public_resources(test_resources):
+ """
+ GIVEN: some resources in the database
+ WHEN: public resources are requested
+ THEN: only list the resources that are public
+ """
+ conn, _res = test_resources
+ assert sorted(public_resources(conn), key=SORTKEY) == sorted(tuple(
+ res for res in conftest.TEST_RESOURCES if res.public), key=SORTKEY)