Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Lou·Ka9# File : tests/test_search.py10# Module : tests11# Repository : https://git.spboucher.ai/lou-ka12# Created : 2026-08-1813# Last Modified : 2026-08-1814#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 — Agrégateur de logements à louer (province de Québec)89# Auteur : Simon-Pierre Boucher — contact@spboucher.ai90# test_search.py : /api/search — la recherche unifiée liste + carte.91# Règle d'or : total == len(points), quelles que soient les contraintes.92# -----------------------------------------------------------------------------93import pytest94from fastapi.testclient import TestClient959697@pytest.fixture(scope="module")98def client():99 from louka import web100 return TestClient(web.app)101102103def _get(client, **params):104 r = client.get("/api/search", params=params)105 assert r.status_code == 200, r.text106 return r.json()107108109def test_regle_dor_total_egale_points(client):110 d = _get(client, page_size=5)111 assert d["total"] == len(d["points"])112 assert len(d["listings"]) <= 5113 # points triés comme la liste : le 1er point est la 1re annonce114 if d["listings"]:115 assert d["points"][0][0] == d["listings"][0]["uid"]116117118def test_bbox_restreint_et_conserve_egalite(client):119 tout = _get(client, page_size=1)120 zone = _get(client, bbox="-71.45,46.70,-71.10,46.92", page_size=1)121 assert zone["total"] <= tout["total"]122 assert zone["total"] == len(zone["points"])123 for _uid, lng, lat, _p, _v in zone["points"]:124 assert -71.45 <= lng <= -71.10 and 46.70 <= lat <= 46.92125126127def test_polygone_sous_ensemble_de_son_emprise(client):128 poly = "-71.24,46.80;-71.20,46.82;-71.24,46.83"129 dedans = _get(client, poly=poly, page_size=1)130 emprise = _get(client, bbox="-71.24,46.80,-71.20,46.83", page_size=1)131 assert dedans["total"] == len(dedans["points"])132 assert dedans["total"] <= emprise["total"]133134135def test_polygone_invalide(client):136 r = client.get("/api/search", params={"poly": "abc"})137 assert r.status_code == 400138 r = client.get("/api/search", params={"poly": "-71,46;-71.2,46.2"})139 assert r.status_code == 400 # 2 sommets140141142def test_tris(client):143 asc = _get(client, sort="prix", page_size=10,144 bbox="-71.45,46.70,-71.10,46.92")145 prix = [p[3] for p in asc["points"] if p[3] is not None]146 assert prix == sorted(prix)147 desc = _get(client, sort="prix_desc", page_size=10,148 bbox="-71.45,46.70,-71.10,46.92")149 prix_d = [p[3] for p in desc["points"] if p[3] is not None]150 assert prix_d == sorted(prix_d, reverse=True)151152153def test_tri_inconnu(client):154 r = client.get("/api/search", params={"sort": "alea"})155 assert r.status_code == 400156157158def test_page_ramenee_dans_les_bornes(client):159 d = _get(client, page=99999, page_size=50,160 bbox="-71.45,46.70,-71.10,46.92")161 assert d["page"] == max(1, -(-d["total"] // 50))162163164def test_include_liste_sans_points(client):165 d = _get(client, include="liste", page_size=5)166 assert d["points"] is None167 assert d["total"] > 0 or d["listings"] == []168169170def test_filtre_deal_et_verdicts(client):171 d = _get(client, deal="sous", page_size=5)172 assert d["total"] == len(d["points"])173 assert all(p[4] == "s" for p in d["points"])174