aboutsummaryrefslogtreecommitdiff
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.py78
1 files changed, 49 insertions, 29 deletions
diff --git a/tests/unit/auth/fixtures/resource_fixtures.py b/tests/unit/auth/fixtures/resource_fixtures.py
index 7f3c383..e06f64e 100644
--- a/tests/unit/auth/fixtures/resource_fixtures.py
+++ b/tests/unit/auth/fixtures/resource_fixtures.py
@@ -1,45 +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
+
+
+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)
+
+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))
+
+TEST_RESOURCES_PUBLIC = (SYSTEM_RESOURCE, TEST_RESOURCES[0], TEST_RESOURCES[4])
-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]
+def fxtr_resources(conn_after_auth_migrations):
"""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)
-
+ conn = conn_after_auth_migrations
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)
+ ((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, 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))
+ ((str(res.resource_id),) for res in TEST_RESOURCES))