feat: donne aux immeubles un nom d'usage
Les comptes rendus n'identifient un immeuble que par son code de gestion (« 33689020 »), illisible partout où il s'affiche. La dénomination (« Servient ») le remplace à l'écran sans toucher au code, qui reste la clé venue des PDF. La colonne s'ajoute à une table déjà installée : elle passe donc par le rattrapage de schéma, qui accepte désormais l'absence de valeur de rattrapage. Déduire un nom d'usage du code en inventerait un. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -24,11 +24,7 @@ def test_ajoute_extracted_at_a_une_base_existante(tmp_path, monkeypatch):
|
||||
importe_le = datetime(2026, 3, 1, 10, 0, tzinfo=timezone.utc)
|
||||
with engine.begin() as conn:
|
||||
conn.execute(text("ALTER TABLE documents DROP COLUMN extracted_at"))
|
||||
conn.execute(
|
||||
text(
|
||||
"INSERT INTO immeubles (code) VALUES ('IMM1');"
|
||||
)
|
||||
)
|
||||
conn.execute(text("INSERT INTO immeubles (code) VALUES ('IMM1');"))
|
||||
conn.execute(
|
||||
text(
|
||||
"INSERT INTO documents (reference, date, immeuble_id, json_data,"
|
||||
@@ -55,6 +51,37 @@ def test_ajoute_extracted_at_a_une_base_existante(tmp_path, monkeypatch):
|
||||
connection.reset_connection()
|
||||
|
||||
|
||||
def test_ajoute_denomination_a_une_base_existante(tmp_path, monkeypatch):
|
||||
"""La colonne arrive vide : deduire un nom d'usage du code l'inventerait."""
|
||||
db_path = tmp_path / "ancienne.sqlite"
|
||||
monkeypatch.setenv("PLESNA_DB_PATH", str(db_path))
|
||||
monkeypatch.setenv("PLESNA_STORAGE_PATH", str(tmp_path / "documents"))
|
||||
|
||||
connection.reset_connection()
|
||||
connection.init_db(db_path)
|
||||
engine = connection.get_engine(db_path)
|
||||
with engine.begin() as conn:
|
||||
conn.execute(text("ALTER TABLE immeubles DROP COLUMN denomination"))
|
||||
conn.execute(text("INSERT INTO immeubles (code) VALUES ('33689020')"))
|
||||
connection.reset_connection()
|
||||
|
||||
connection.init_db(db_path)
|
||||
|
||||
with connection.get_engine(db_path).begin() as conn:
|
||||
colonnes = {
|
||||
row[1] for row in conn.execute(text("PRAGMA table_info(immeubles)"))
|
||||
}
|
||||
assert "denomination" in colonnes
|
||||
|
||||
denomination, code = conn.execute(
|
||||
text("SELECT denomination, code FROM immeubles")
|
||||
).one()
|
||||
assert denomination is None
|
||||
assert code == "33689020"
|
||||
|
||||
connection.reset_connection()
|
||||
|
||||
|
||||
def test_rattrapage_idempotent(tmp_path, monkeypatch):
|
||||
"""Relancer init_db sur une base a jour ne doit rien casser."""
|
||||
db_path = tmp_path / "a_jour.sqlite"
|
||||
@@ -67,7 +94,9 @@ def test_rattrapage_idempotent(tmp_path, monkeypatch):
|
||||
connection.init_db(db_path)
|
||||
|
||||
with connection.get_engine(db_path).begin() as conn:
|
||||
colonnes = [row[1] for row in conn.execute(text("PRAGMA table_info(documents)"))]
|
||||
colonnes = [
|
||||
row[1] for row in conn.execute(text("PRAGMA table_info(documents)"))
|
||||
]
|
||||
assert colonnes.count("extracted_at") == 1
|
||||
|
||||
connection.reset_connection()
|
||||
|
||||
Reference in New Issue
Block a user