about summary refs log tree commit diff
path: root/tests/unit/auth/fixtures/resource_fixtures.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/auth/fixtures/resource_fixtures.py')
-rw-r--r--tests/unit/auth/fixtures/resource_fixtures.py109
1 files changed, 49 insertions, 60 deletions
diff --git a/tests/unit/auth/fixtures/resource_fixtures.py b/tests/unit/auth/fixtures/resource_fixtures.py
index 37397d2..e06f64e 100644
--- a/tests/unit/auth/fixtures/resource_fixtures.py
+++ b/tests/unit/auth/fixtures/resource_fixtures.py
@@ -1,76 +1,65 @@
 """Fixtures and utilities for resource-related tests"""
+import uuid
+
 import pytest
 
 from gn_auth.auth.db import sqlite3 as db
+from gn_auth.auth.authorisation.resources import Resource, ResourceCategory
 
-from .role_fixtures import RESOURCE_EDITOR_ROLE, RESOURCE_READER_ROLE
-from .group_fixtures import (
-    TEST_RESOURCES,
-    TEST_GROUP_01,
-    TEST_GROUP_02,
-    TEST_RESOURCES_GROUP_01,
-    TEST_RESOURCES_GROUP_02)
 
-@pytest.fixture(scope="function")
-def fxtr_resources(fxtr_group):# pylint: disable=[redefined-outer-name]
-    """fixture: setup test resources in the database"""
-    conn, _group = fxtr_group
-    ownership = tuple({
-        "group_id": str(TEST_GROUP_01.group_id),
-        "resource_id": str(res.resource_id)
-    } for res in TEST_RESOURCES_GROUP_01) + tuple({
-        "group_id": str(TEST_GROUP_02.group_id),
-        "resource_id": str(res.resource_id)
-    } for res in TEST_RESOURCES_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)
 
-    with db.cursor(conn) as cursor:
-        cursor.executemany(
-            "INSERT INTO resources VALUES (?,?,?,?)",
-        ((str(res.resource_id), res.resource_name,
-          str(res.resource_category.resource_category_id),
-          1 if res.public else 0) for res in TEST_RESOURCES))
-        cursor.executemany(
-            "INSERT INTO resource_ownership(group_id, resource_id) "
-            "VALUES (:group_id, :resource_id)",
-            ownership)
+TEST_RESOURCES = (
+    Resource(uuid.UUID("26ad1668-29f5-439d-b905-84d551f85955"),
+             "ResourceG01R01",
+             ResourceCategory(uuid.UUID("48056f84-a2a6-41ac-8319-0e1e212cba2a"),
+                              "genotype", "Genotype Dataset"),
+             True),
+    Resource(uuid.UUID("2130aec0-fefd-434d-92fd-9ca342348b2d"),
+             "ResourceG01R02",
+             ResourceCategory(uuid.UUID("548d684b-d4d1-46fb-a6d3-51a56b7da1b3"),
+                              "phenotype", "Phenotype (Publish) Dataset"),
+             False),
+    Resource(uuid.UUID("e9a1184a-e8b4-49fb-b713-8d9cbeea5b83"),
+             "ResourceG01R03",
+             ResourceCategory(uuid.UUID("fad071a3-2fc8-40b8-992b-cdefe7dcac79"),
+                              "mrna", "mRNA Dataset"),
+             False),
+    Resource(uuid.UUID("14496a1c-c234-49a2-978c-8859ea274054"),
+             "ResourceG02R01",
+             ResourceCategory(uuid.UUID("48056f84-a2a6-41ac-8319-0e1e212cba2a"),
+                              "genotype", "Genotype Dataset"),
+             False),
+    Resource(uuid.UUID("04ad9e09-94ea-4390-8a02-11f92999806b"),
+             "ResourceG02R02",
+             ResourceCategory(uuid.UUID("fad071a3-2fc8-40b8-992b-cdefe7dcac79"),
+                              "mrna", "mRNA Dataset"),
+             True))
 
-    yield (conn, TEST_RESOURCES)
-
-    with db.cursor(conn) as cursor:
-        cursor.executemany(
-            "DELETE FROM resource_ownership "
-            "WHERE group_id=:group_id AND resource_id=:resource_id",
-            ownership)
-        cursor.executemany("DELETE FROM resources WHERE resource_id=?",
-                           ((str(res.resource_id),)
-         for res in TEST_RESOURCES))
+TEST_RESOURCES_PUBLIC = (SYSTEM_RESOURCE, TEST_RESOURCES[0], TEST_RESOURCES[4])
 
 
 @pytest.fixture(scope="function")
-def fxtr_resource_roles(fxtr_group, fxtr_resources, fxtr_roles):# pylint: disable=[redefined-outer-name,unused-argument]
-    """Link roles to resources."""
-    resource_roles = ({
-        "resource_id": str(TEST_RESOURCES_GROUP_01[0].resource_id),
-        "role_created_by": "ecb52977-3004-469e-9428-2a1856725c7f",
-        "role_id": str(RESOURCE_EDITOR_ROLE.role_id)
-    },{
-        "resource_id": str(TEST_RESOURCES_GROUP_01[0].resource_id),
-        "role_created_by": "ecb52977-3004-469e-9428-2a1856725c7f",
-        "role_id": str(RESOURCE_READER_ROLE.role_id)
-    })
-    conn, groups = fxtr_group
+def fxtr_resources(conn_after_auth_migrations):
+    """fixture: setup test resources in the database"""
+    conn = conn_after_auth_migrations
     with db.cursor(conn) as cursor:
         cursor.executemany(
-            "INSERT INTO resource_roles(resource_id, role_created_by, role_id) "
-            "VALUES (:resource_id, :role_created_by, :role_id)",
-            resource_roles)
+            "INSERT INTO resources VALUES (?,?,?,?)",
+            ((str(res.resource_id), res.resource_name,
+              str(res.resource_category.resource_category_id),
+              1 if res.public else 0) for res in TEST_RESOURCES))
 
-    yield conn, groups, resource_roles
+    yield (conn, TEST_RESOURCES)
 
     with db.cursor(conn) as cursor:
-        cursor.executemany(
-            ("DELETE FROM resource_roles "
-             "WHERE resource_id=:resource_id "
-             "AND role_created_by=:role_created_by "
-             "AND role_id=:role_id"),
-            resource_roles)
+        cursor.executemany("DELETE FROM resources WHERE resource_id=?",
+                           ((str(res.resource_id),) for res in TEST_RESOURCES))