-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconftest.py
60 lines (48 loc) · 1.66 KB
/
conftest.py
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
import pytest
import uuid
from unittest.mock import patch
from fastapi.testclient import TestClient
from typing import Iterator
from app import app
from submodules.model.business_objects import (
organization as organization_bo,
user as user_bo,
project as project_bo,
general,
)
from submodules.model.models import (
Organization,
User,
Project as RefineryProject,
)
@pytest.fixture(scope="session", autouse=True)
def database_session() -> Iterator[None]:
session_token = general.get_ctx_token()
yield
general.remove_and_refresh_session(session_token)
@pytest.fixture(scope="session")
def org() -> Iterator[Organization]:
org_item = organization_bo.create(name="test_org", with_commit=True)
yield org_item
organization_bo.delete(org_item.id, with_commit=True)
@pytest.fixture(scope="session")
def user(org: Organization) -> Iterator[User]:
user_item = user_bo.create(user_id=uuid.uuid4(), with_commit=True)
user_bo.update_organization(user_id=user_item.id, organization_id=org.id)
yield user_item
@pytest.fixture(scope="session")
def refinery_project(org: Organization, user: User) -> Iterator[RefineryProject]:
project_item = project_bo.create(
organization_id=org.id,
name="test_project",
description="test_description",
created_by=user.id,
with_commit=True,
)
yield project_item
project_bo.delete(project_item.id, with_commit=True)
@pytest.fixture
def client(user: User) -> Iterator[TestClient]:
with patch("controller.auth.manager.DEV_USER_ID", str(user.id)):
with TestClient(app, base_url="http://localhost:7051") as client:
yield client