aboutsummaryrefslogtreecommitdiff
path: root/tests/unit/auth/fixtures/resource_fixtures.py
blob: e06f64e1d983bca8428127e21c40dbf8b5c0e50e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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])


@pytest.fixture(scope="function")
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 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, TEST_RESOURCES)

    with db.cursor(conn) as cursor:
        cursor.executemany("DELETE FROM resources WHERE resource_id=?",
                           ((str(res.resource_id),) for res in TEST_RESOURCES))