reprise : l'index que la fiche du site attribue, et la copie de reprise
Decide le 2026-10-20, jamais applique : une reprise au site de TechnoLibre loge Chezlepro en 41 et TechnoLibre en 43, pour coexister avec la production le temps d'un exercice. La nomenclature garde l'index de production ; charger_nomenclature rend celui de la fiche du site hebergeur (attribue.index), et tout l'adressage suit. L'index de production reste sous index_production. Site.ecarts_attribution : l'hebergeur actif attribue l'index de production, un site de reprise un index different ; P21 reserve chaque index de reprise. make reprise-preparer SITE= TENANT= : branche reprise/<site> du depot du locataire, en worktree sous DepotsSurForge/reprises/ (hors des freres), main fusionnee, fiche du site de reprise deposee. Prouve sur TechnoLibre : copie entierement en 43, production intacte. Nouveau test_index_reprise.py (9 cas) ; trois mutations attrapees. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
01d2a4bc42
commit
5f1054facb
12 changed files with 336 additions and 10 deletions
97
scripts/tests/test_index_reprise.py
Normal file
97
scripts/tests/test_index_reprise.py
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
#!/usr/bin/env python3
|
||||
"""L'index de reprise : la fiche du site attribue, tout suit, et rien ne se percute.
|
||||
|
||||
Ecosystemes FICTIFS (un site de production, un site de reprise, un locataire). Ces cas gardent :
|
||||
1. la nomenclature rend l'index que la FICHE attribue, et garde celui de production a part ;
|
||||
sans fiche, l'index de la nomenclature ;
|
||||
2. l'hebergeur actif doit attribuer l'index de production ; un site de reprise, un autre ;
|
||||
3. un index de reprise est RESERVE : un ecosysteme qui le prendrait est en collision (P21) ;
|
||||
4. preparer une reprise chez l'hebergeur actif, ou chez un site qui ne la declare pas, est refuse.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from unittest import mock
|
||||
|
||||
import yaml
|
||||
|
||||
RACINE = Path(__file__).resolve().parents[2]
|
||||
sys.path.insert(0, str(RACINE / "scripts"))
|
||||
|
||||
import contexte # noqa: E402
|
||||
import instances # noqa: E402
|
||||
import inventory_rules # noqa: E402
|
||||
import reprise # noqa: E402
|
||||
|
||||
|
||||
def ecrire(chemin: Path, donnees: dict) -> None:
|
||||
chemin.parent.mkdir(parents=True, exist_ok=True)
|
||||
chemin.write_text(yaml.safe_dump(donnees), encoding="utf-8")
|
||||
|
||||
|
||||
class Fictif(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.d = Path(tempfile.mkdtemp())
|
||||
ecrire(self.d / "SITE-Prod" / "underlay.yml", {"underlay": {"index": 37, "tenants": {"OPS-X": 23}}})
|
||||
ecrire(self.d / "SITE-Reprise" / "underlay.yml", {"underlay": {"index": 31, "tenants": {"OPS-X": 43}}})
|
||||
ecrire(self.d / "OPS-X" / "plan" / "nomenclature.yml", {"index": 23, "categories": {1: {"libelle": "Frontiere"}}})
|
||||
ecrire(self.d / "OPS-X" / "fiche-site.yml", {"site": "SITE-Prod", "attribue": {"index": 23}})
|
||||
ecrire(self.d / "OPS-X" / "parente.yml", {"parente": {"depots": {"hebergeur": {"nom": "SITE-Prod"}}}})
|
||||
self.loc = contexte.Locataire(self.d / "OPS-X")
|
||||
|
||||
def reprise_tenants(self, idx):
|
||||
ecrire(self.d / "SITE-Reprise" / "underlay.yml", {"underlay": {"index": 31, "tenants": {"OPS-X": idx}}})
|
||||
return contexte.Site(self.d / "SITE-Reprise")
|
||||
|
||||
# 1. ----------------------------------------------------------------------------------
|
||||
def test_la_fiche_attribue_l_index(self):
|
||||
copie = self.d / "copie" / "OPS-X"
|
||||
ecrire(copie / "plan" / "nomenclature.yml", {"index": 23})
|
||||
ecrire(copie / "fiche-site.yml", {"site": "SITE-Reprise", "attribue": {"index": 43}})
|
||||
n = inventory_rules.charger_nomenclature(copie / "plan" / "nomenclature.yml")
|
||||
self.assertEqual((n["index"], n["index_production"]), (43, 23))
|
||||
|
||||
def test_sans_fiche_l_index_de_la_nomenclature(self):
|
||||
(self.d / "OPS-X" / "fiche-site.yml").unlink()
|
||||
self.assertEqual(inventory_rules.charger_nomenclature(self.d / "OPS-X" / "plan" / "nomenclature.yml")["index"], 23)
|
||||
|
||||
# 2. ----------------------------------------------------------------------------------
|
||||
def test_l_hebergeur_attribue_la_production(self):
|
||||
self.assertEqual(contexte.Site(self.d / "SITE-Prod").ecarts_attribution(self.loc), [])
|
||||
ecrire(self.d / "SITE-Prod" / "underlay.yml", {"underlay": {"index": 37, "tenants": {"OPS-X": 24}}})
|
||||
self.assertTrue(contexte.Site(self.d / "SITE-Prod").ecarts_attribution(self.loc))
|
||||
|
||||
def test_la_reprise_attribue_un_autre_index(self):
|
||||
self.assertEqual(self.reprise_tenants(43).ecarts_attribution(self.loc), [])
|
||||
self.assertTrue(self.reprise_tenants(23).ecarts_attribution(self.loc))
|
||||
|
||||
# 3. ----------------------------------------------------------------------------------
|
||||
def test_l_index_de_reprise_est_reserve(self):
|
||||
ecrire(self.d / "OPS-Y" / "plan" / "nomenclature.yml", {"index": 43, "categories": {1: {}}})
|
||||
with mock.patch.object(instances, "FRERES", self.d), mock.patch.object(instances, "_actif", return_value=None):
|
||||
coll = instances.collisions(instances.decouvrir())
|
||||
self.assertIn(43, coll)
|
||||
self.assertEqual(len(coll[43]), 2)
|
||||
|
||||
def test_sans_voisin_pas_de_collision(self):
|
||||
with mock.patch.object(instances, "FRERES", self.d), mock.patch.object(instances, "_actif", return_value=None):
|
||||
self.assertEqual(instances.collisions(instances.decouvrir()), {})
|
||||
|
||||
# 4. ----------------------------------------------------------------------------------
|
||||
def test_preparer_chez_l_hebergeur_est_refuse(self):
|
||||
self.assertTrue(reprise.refus_preparation(contexte.Site(self.d / "SITE-Prod"), self.loc))
|
||||
|
||||
def test_preparer_chez_un_site_qui_ne_declare_pas(self):
|
||||
ecrire(self.d / "SITE-Reprise" / "underlay.yml", {"underlay": {"index": 31, "tenants": {}}})
|
||||
self.assertTrue(reprise.refus_preparation(contexte.Site(self.d / "SITE-Reprise"), self.loc))
|
||||
|
||||
def test_preparer_chez_le_site_de_reprise_passe(self):
|
||||
self.assertEqual(reprise.refus_preparation(self.reprise_tenants(43), self.loc), [])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Loading…
Reference in a new issue