Repository Public
1# =============================================================================2# SP BOUCHER | INFRASTRUCTURE & AUTOMATION3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# Project : MacLustr Identity7# File : tests/conftest.py8# Module : tests9# Repository : https://git.spboucher.ai/maclustr-identity10# Project Website : https://identity.spboucher.ai11# Created : 2026-12-0112# Last Modified : 2026-12-0113#14# Author : Simon-Pierre Boucher15# Position : Professor of Finance16# Institution : Université du Québec en Outaouais (UQO)17# Organization : SP Boucher18# Website : https://spboucher.ai19# Git : https://git.spboucher.ai20#21# Preferred Contact: admin@spboucher.ai22# Technical Contact: dev@spboucher.ai23# Security/Admin : admin@spboucher.ai24#25# Copyright (c) 202626# Simon-Pierre Boucher27# All rights reserved where applicable. This file is governed by the28# applicable project license, copyright notices and relevant law.29# Existing third-party rights and notices remain unaffected.30#31# License : None specified (no license file in this repository)32#33# Do not embed credentials, private keys, access tokens,34# certificates or confidential personal information.35#36# =============================================================================37# END OF SP BOUCHER SOURCE HEADER38# =============================================================================3940import os41import sys42import tempfile43from pathlib import Path4445ROOT = Path(__file__).resolve().parents[1]46sys.path.insert(0, str(ROOT))47_tmp = tempfile.mkdtemp(prefix="mlid-test-")48os.environ.update({"MLID_ENV": "development", "DATABASE_URL": os.environ.get("MLID_TEST_DATABASE_URL", "postgres://127.0.0.1/maclustr_identity_test"),49 "MLID_DATA_DIR": _tmp + "/data", "MLID_MASTER_KEY_FILE": _tmp + "/master.key", "MLID_ALLOW_PRIVATE_WEBHOOKS": "1",50 "MLID_ORIGIN": "http://localhost:8860", "MLID_WEB_DIR": _tmp + "/web"})5152import pytest # noqa: E40253from fastapi.testclient import TestClient # noqa: E40254from services.mlid import db, registry, scheduler # noqa: E40255from services.mlid.app import app # noqa: E40256from services.mlid.internal_app import app as internal_app # noqa: E4025758FX = ROOT / "tests" / "fixtures"596061@pytest.fixture(scope="session", autouse=True)62def _schema():63 with db.tx() as c:64 c.execute("drop schema public cascade; create schema public")65 db.migrate()66 yield67 db.close()686970@pytest.fixture(scope="session")71def client():72 with TestClient(app) as c:73 yield c747576@pytest.fixture(scope="session")77def internal():78 return TestClient(internal_app)798081class AppCtx:82 def __init__(self, slug):83 self.app = registry.create_app(slug.title(), slug)84 self.id = self.app["id"]85 _, self.test_key = registry.create_key(self.id, livemode=False)86 _, self.live_key = registry.create_key(self.id, livemode=True)8788 def h(self, live=False):89 return {"Authorization": "Bearer " + (self.live_key if live else self.test_key)}909192@pytest.fixture(scope="session")93def app_a():94 return AppCtx("app-a")959697@pytest.fixture(scope="session")98def app_b():99 return AppCtx("app-b")100101102@pytest.fixture(scope="session")103def worker_token():104 return scheduler.register_worker("test-worker", [])[1]105106107@pytest.fixture()108def gates_open():109 db.q("update compliance_gate set status='open'")110 yield111 db.q("update compliance_gate set status='closed'")112