File size: 2,894 Bytes
23d337e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
"""
Pytest configuration + shared fixtures.

Provides:
  - test_settings:  Settings instance with all optional providers disabled,
                    in-memory DB, temp dirs.
  - test_container: fully wired ServiceContainer for integration tests.
  - sample_image_bytes: a synthetic JPEG with no faces (for negative tests).
  - sample_face_image_bytes: a synthetic JPEG with a face-like shape.
  - sample_image_b64: base64-encoded sample_image_bytes.
"""

from __future__ import annotations

import base64
import io
import sys
from pathlib import Path

import cv2
import numpy as np
import pytest

# Add project root to path
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

from config.settings import Settings, DATA_DIR
from api.container import build_container


@pytest.fixture
def test_settings(tmp_path) -> Settings:
    """Settings with all optional providers disabled + temp DB."""
    return Settings(
        environment="test",
        enable_dnn=False,
        enable_mtcnn=False,
        enable_retinaface=False,
        enable_face_recognition=False,
        enable_deepface=False,
        enable_insightface=False,
        enable_beautifulsoup_scraper=False,
        enable_selenium_scraper=False,
        enable_bing_scraper=False,
        enable_duckduckgo_scraper=False,
        enable_google_lens=False,
        enable_serpapi=False,
        enable_yandex=False,
        enable_tineye=False,
        enable_visual_features=False,
        enable_xmp=False,
        enable_manipulation_analyzer=False,
        db_path=":memory:",
        cache_enabled=False,
        rate_limit_per_minute=10000,
    )


@pytest.fixture
def test_container(test_settings):
    """Fully wired container for integration tests."""
    return build_container(test_settings)


@pytest.fixture
def sample_image_bytes() -> bytes:
    """A 200x200 black image with a white square — no faces."""
    img = np.zeros((200, 200, 3), dtype=np.uint8)
    cv2.rectangle(img, (50, 50), (150, 150), (255, 255, 255), -1)
    ok, buf = cv2.imencode(".jpg", img)
    assert ok
    return buf.tobytes()


@pytest.fixture
def sample_face_image_bytes() -> bytes:
    """A 300x300 image with a face-like shape (circle for head, dots for eyes)."""
    img = np.zeros((300, 300, 3), dtype=np.uint8)
    # Head
    cv2.circle(img, (150, 150), 80, (200, 200, 200), -1)
    # Eyes
    cv2.circle(img, (125, 130), 8, (50, 50, 50), -1)
    cv2.circle(img, (175, 130), 8, (50, 50, 50), -1)
    # Mouth
    cv2.ellipse(img, (150, 180), (30, 10), 0, 0, 180, (50, 50, 50), 2)
    ok, buf = cv2.imencode(".jpg", img)
    assert ok
    return buf.tobytes()


@pytest.fixture
def sample_image_b64(sample_image_bytes) -> str:
    return base64.b64encode(sample_image_bytes).decode()


@pytest.fixture
def sample_face_b64(sample_face_image_bytes) -> str:
    return base64.b64encode(sample_face_image_bytes).decode()