61 lines
1.5 KiB
Python
61 lines
1.5 KiB
Python
"""Shared pytest fixtures for the PII service tests."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
import os
|
|
|
|
# Make the service root importable from tests/
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
|
|
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
import pytest
|
|
|
|
from layers.regex_layer import RegexLayer
|
|
from pipeline import Pipeline
|
|
from pseudonymize import AESEncryptor, PseudonymMapper
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Cryptography fixtures
|
|
# ---------------------------------------------------------------------------
|
|
|
|
TEST_KEY_B64 = "dmV5bGFudC1kZXYta2V5LTMyYnl0ZXMtcGFkZGluZy0=" # 32 bytes
|
|
|
|
|
|
@pytest.fixture
|
|
def encryptor() -> AESEncryptor:
|
|
return AESEncryptor(TEST_KEY_B64)
|
|
|
|
|
|
@pytest.fixture
|
|
def redis_mock() -> MagicMock:
|
|
mock = MagicMock()
|
|
mock.set.return_value = True
|
|
mock.get.return_value = None
|
|
mock.scan_iter.return_value = iter([])
|
|
return mock
|
|
|
|
|
|
@pytest.fixture
|
|
def pseudo_mapper(redis_mock, encryptor) -> PseudonymMapper:
|
|
return PseudonymMapper(redis_mock, encryptor, ttl_seconds=3600)
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Layer fixtures
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
@pytest.fixture
|
|
def regex_layer() -> RegexLayer:
|
|
return RegexLayer()
|
|
|
|
|
|
@pytest.fixture
|
|
def pipeline_regex_only() -> Pipeline:
|
|
"""Pipeline with NER disabled for fast unit tests."""
|
|
with patch("config.NER_ENABLED", False):
|
|
p = Pipeline()
|
|
return p
|