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
66
67
68
69
70
71
72
|
from collections.abc import Callable, Generator
from typing import TYPE_CHECKING
import pytest
from generalresearch.managers.thl.profiling.question import (
QuestionManager,
)
from generalresearch.managers.thl.profiling.schema import (
UpkSchemaManager,
)
from generalresearch.managers.thl.profiling.uqa import UQAManager
from generalresearch.managers.thl.profiling.user_upk import (
UserUpkManager,
)
if TYPE_CHECKING:
from generalresearch.models.thl.user import User
from generalresearch.pg_helper import PostgresConfig
from generalresearch.redis_helper import RedisConfig
@pytest.fixture(scope="session")
def upk_schema_manager(thl_web_rw: PostgresConfig) -> UpkSchemaManager:
return UpkSchemaManager(pg_config=thl_web_rw)
@pytest.fixture(scope="session")
def user_upk_manager(
thl_web_rw: PostgresConfig, thl_redis_config: RedisConfig
) -> UserUpkManager:
return UserUpkManager(pg_config=thl_web_rw, redis_config=thl_redis_config)
@pytest.fixture(scope="session")
def question_manager(
thl_web_rw: PostgresConfig,
) -> QuestionManager:
return QuestionManager(pg_config=thl_web_rw)
@pytest.fixture(scope="session")
def uqa_manager(
thl_web_rw: PostgresConfig, thl_redis_config: RedisConfig
) -> UQAManager:
return UQAManager(redis_config=thl_redis_config, pg_config=thl_web_rw)
@pytest.fixture(scope="function")
def uqa_manager_clear_cache_factory(
uqa_manager: UQAManager,
) -> Callable[..., Generator[None]]:
def _inner(user: User) -> Generator[None]:
# On successive py-test/jenkins runs, the cache may contain
# the previous run's info (keyed under the same user_id)
uqa_manager.clear_cache(user)
yield
uqa_manager.clear_cache(user)
return _inner
@pytest.fixture(scope="function")
def uqa_manager_clear_cache(
uqa_manager_clear_cache_factory: Callable[..., None], user: User
):
uqa_manager_clear_cache_factory(user=user)
|