Repository Public
1# =============================================================================2# SP BOUCHER | INFRASTRUCTURE & AUTOMATION3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# Project : MacLustr Identity7# File : sdk/python/tests/conftest.py8# Description : Shared fixtures.9# Module : sdk10# Repository : https://git.spboucher.ai/maclustr-identity11# Project Website : https://identity.spboucher.ai12# Created : 2026-12-0113# Last Modified : 2026-12-0114#15# Author : Simon-Pierre Boucher16# Position : Professor of Finance17# Institution : Université du Québec en Outaouais (UQO)18# Organization : SP Boucher19# Website : https://spboucher.ai20# Git : https://git.spboucher.ai21#22# Preferred Contact: admin@spboucher.ai23# Technical Contact: dev@spboucher.ai24# Security/Admin : admin@spboucher.ai25#26# Copyright (c) 202627# Simon-Pierre Boucher28# All rights reserved where applicable. This file is governed by the29# applicable project license, copyright notices and relevant law.30# Existing third-party rights and notices remain unaffected.31#32# License : None specified (no license file in this repository)33#34# Do not embed credentials, private keys, access tokens,35# certificates or confidential personal information.36#37# =============================================================================38# END OF SP BOUCHER SOURCE HEADER39# =============================================================================4041"""Shared fixtures. Integration fixtures provision sandbox applications on the LOCAL backend through its CLI."""42from __future__ import annotations4344import os45import re46import subprocess47import sys48import time49from pathlib import Path5051import httpx52import pytest5354REPO = Path(__file__).resolve().parents[3]55sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "examples"))565758@pytest.fixture(scope="session")59def backend() -> dict:60 base_url = os.environ.get("MLID_BASE_URL", "http://localhost:8870")61 if not re.fullmatch(r"http://(localhost|127\.0\.0\.1)(:\d+)?", base_url):62 pytest.exit("Integration tests only run against a local backend.")63 try:64 httpx.get(base_url + "/health", timeout=3).raise_for_status()65 except httpx.HTTPError:66 pytest.skip(f"no backend at {base_url}")67 key_a, key_b = os.environ.get("MLID_SECRET_KEY"), os.environ.get("MLID_SECRET_KEY_B")68 if not key_a or not key_b:69 python = REPO / ".venv" / "bin" / "python"70 if not python.exists():71 pytest.skip("backend virtualenv not found; set MLID_SECRET_KEY and MLID_SECRET_KEY_B")72 env = {**os.environ, "DATABASE_URL": os.environ.get("DATABASE_URL", "postgres://127.0.0.1/maclustr_identity_sdk"),73 "MLID_DATA_DIR": os.environ.get("MLID_DATA_DIR", "/tmp/mlid-sdk/data"),74 "MLID_MASTER_KEY_FILE": os.environ.get("MLID_MASTER_KEY_FILE", "/tmp/mlid-sdk/master.key")}7576 def cli(*args: str) -> str:77 return subprocess.run([str(python), "-m", "services.mlid.cli", *args], cwd=REPO, env=env, check=True, capture_output=True, text=True).stdout.strip()7879 run = format(int(time.time() * 1000), "x")80 keys = []81 for suffix in ("a", "b"):82 slug = f"sdk-py-{suffix}-{run}"83 cli("app-create", slug, f"Python SDK integration {suffix.upper()}")84 keys.append(cli("key-create", slug).splitlines()[-1])85 key_a, key_b = keys86 return {"base_url": base_url, "key_a": key_a, "key_b": key_b}87