""" Shared pytest fixtures for the PIC test suite. """ import os import sys import json import tempfile import shutil import pytest # Ensure api/ is on the path for all tests sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'api')) @pytest.fixture def tmp_dir(): """Temporary directory that is cleaned up after each test.""" d = tempfile.mkdtemp() yield d shutil.rmtree(d, ignore_errors=True) @pytest.fixture def tmp_config_dir(tmp_dir): """Temporary config dir with the sub-directories expected by managers.""" for sub in ('api', 'caddy', 'dns', 'dhcp', 'ntp', 'wireguard'): os.makedirs(os.path.join(tmp_dir, sub), exist_ok=True) return tmp_dir @pytest.fixture def tmp_data_dir(tmp_dir): """Temporary data dir with the sub-directories expected by managers.""" for sub in ('dns', 'mail', 'calendar', 'files', 'wireguard'): os.makedirs(os.path.join(tmp_dir, sub), exist_ok=True) return tmp_dir @pytest.fixture def flask_client(): """Flask test client with TESTING mode enabled.""" from app import app app.config['TESTING'] = True with app.test_client() as client: yield client