Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : tests/test_connectors.py10# Module : tests11# Repository : https://git.spboucher.ai/lou-ka12# Created : 2026-08-0813# Last Modified : 2026-08-0814#15# =============================================================================16# AUTHOR & PROFESSIONAL AFFILIATION17# =============================================================================18#19# Author : Simon-Pierre Boucher20# Position : Professor of Finance21# Institution : Université du Québec en Outaouais (UQO)22# Department : Département des sciences administratives23# Organization : SP Boucher24#25# Website : https://spboucher.ai26# Git : https://git.spboucher.ai27#28# =============================================================================29# OFFICIAL CONTACT DIRECTORY30# =============================================================================31#32# General : info@spboucher.ai33# Professional : contact@spboucher.ai34# Direct : simon@spboucher.ai35# Research : research@spboucher.ai36# Development : dev@spboucher.ai37# Support : support@spboucher.ai38# Security/Admin : admin@spboucher.ai39# Notifications : notifications@spboucher.ai40#41# Preferred Contact: contact@spboucher.ai42#43# =============================================================================44# COPYRIGHT & INTELLECTUAL PROPERTY45# =============================================================================46#47# Copyright (c) 202648# Simon-Pierre Boucher49#50# All rights reserved where applicable.51#52# This file is governed by the applicable project license,53# copyright notices, institutional agreements and relevant law.54#55# Unless expressly authorized by the applicable license or56# rights holder, copying, redistribution, sublicensing,57# publication and commercial exploitation are not permitted.58#59# Existing third-party rights and notices remain unaffected.60#61# =============================================================================62# CONFIDENTIALITY & SECURITY63# =============================================================================64#65# Classification : Public66# Distribution : Public repository; use is governed by the project license67# Security Contact : admin@spboucher.ai68#69# Access to this source does not independently grant permission70# to redistribute or disclose confidential materials.71#72# Do not embed credentials, private keys, access tokens,73# certificates or confidential personal information.74#75# =============================================================================76# LICENSE & MAINTENANCE77# =============================================================================78#79# License : None specified (no license file in this repository)80# Maintainer : Simon-Pierre Boucher81# Technical Contact: dev@spboucher.ai82#83# =============================================================================84# END OF SP BOUCHER SOURCE HEADER85# =============================================================================8687# -----------------------------------------------------------------------------88# Lou-Ka — tests de régression des connecteurs (rejeu des fixtures hors-ligne)89# Ré-enregistrer une fixture après un changement de site :90# .venv/bin/python run.py record <source>91# -----------------------------------------------------------------------------92import json93import re9495import pytest9697from louka.fixtures import FIXTURES_DIR, recorded_sources, replay_connector, snapshot9899SOURCES = recorded_sources()100101pytestmark = pytest.mark.skipif(102 not SOURCES, reason="aucune fixture enregistrée (run.py record <source>)")103104105@pytest.fixture(scope="module")106def parsed():107 """Rejoue chaque connecteur une seule fois par session de test."""108 cache = {}109110 def _get(source_id):111 if source_id not in cache:112 cache[source_id] = replay_connector(source_id).fetch()113 return cache[source_id]114115 return _get116117118@pytest.mark.parametrize("source_id", SOURCES)119def test_parsing_matches_snapshot(source_id, parsed):120 """Le parsing des fixtures reproduit exactement l'instantané enregistré."""121 expected = json.loads(122 (FIXTURES_DIR / source_id / "expected.json").read_text(encoding="utf-8"))123 actual = snapshot(parsed(source_id))124 assert actual["count"] == expected["count"]125 assert actual["listings"] == expected["listings"]126127128@pytest.mark.parametrize("source_id", SOURCES)129def test_listings_are_valid(source_id, parsed):130 """Contraintes de schéma : uid uniques, URLs absolues, prix plausibles."""131 listings = parsed(source_id)132 assert listings, "le connecteur ne retourne aucune annonce depuis la fixture"133134 uids = [l.uid for l in listings]135 assert len(uids) == len(set(uids)), "external_id en double"136137 for l in listings:138 assert l.source == source_id139 assert l.external_id140 assert re.match(r"^https?://", l.url), f"URL non absolue : {l.url!r}"141 assert l.price is None or 100 <= l.price <= 20000142 assert l.area_sqft is None or 80 <= l.area_sqft <= 20000143 for img in l.images:144 assert re.match(r"^https?://", img), f"image non absolue : {img!r}"145 # jamais de valeur inventée : chaîne vide ou None, pas de « N/A »146 assert (l.unit_type or "") not in ("N/A", "n/a", "?")147