From 68434bf4464d7ac86da0aac60dc6473a08a96917 Mon Sep 17 00:00:00 2001 From: Johan Le Baut Date: Sun, 13 Feb 2022 12:12:58 +0100 Subject: [PATCH] handle axione erreur --- .gitignore | 3 ++- axione_api/api.py | 47 +++++++++++++++++++++++++++++-------- fixtures/dummy-data-2.xml | 46 ++++++++++++++++++++++++++++++++++++ fixtures/dummy-data-3.xml | 36 ++++++++++++++++++++++++++++ templates/landing_form.html | 4 ++-- templates/result.html | 14 ++++++++--- templates/style.css | 4 ++-- webapp.py | 7 +++++- 8 files changed, 142 insertions(+), 19 deletions(-) create mode 100644 fixtures/dummy-data-2.xml create mode 100644 fixtures/dummy-data-3.xml diff --git a/.gitignore b/.gitignore index 392f4f6..88d0713 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ __pycache__ -/elig-test.ini \ No newline at end of file +/elig-test.ini +.vscode \ No newline at end of file diff --git a/axione_api/api.py b/axione_api/api.py index dfae753..496a422 100644 --- a/axione_api/api.py +++ b/axione_api/api.py @@ -90,7 +90,6 @@ def query_axione(cfg, body): print(headers) print("BODY: ") print(body) - print("===================") with open("./fixtures/dummy-data-1.xml", "r") as f: dummyData = f.read() return dummyData @@ -121,17 +120,45 @@ class BatimentResult(TypedDict): referenceBatiment: str etages: list[EtageResult] +class AxioneErreur(TypedDict): + codeErreur: str + libelleErreur: str -def parse_response(resp_str) -> list[BatimentResult]: +class AxioneResult(TypedDict): + codeRetour: int + axioneErreur: AxioneErreur + batiments: list[BatimentResult] + + +def parse_response(resp_str) -> AxioneResult: root = ET.fromstring(resp_str) - parsedBatiments = [ - parse_batiment(b) - for b in root.findall( - ".//{http://structureadresseftth.axione.fr/model/commun}batiment" - ) - ] - return parsedBatiments - + codeRetourXml = root.find( + ".//{http://structureadresseftth.axione.fr/model/commun}codeRetour" + ) + codeRetour = int(codeRetourXml.text.strip()) + axioneErreur = None + parsedBatiments = [] + if codeRetour == 0: + parsedBatiments = [ + parse_batiment(b) + for b in root.findall( + ".//{http://structureadresseftth.axione.fr/model/commun}batiment" + ) + ] + else: + axioneErreur = AxioneErreur( + codeErreur = root.find( + ".//{http://structureadresseftth.axione.fr/model/commun}codeErreur" + ).text.strip(), + libelleErreur = root.find( + ".//{http://structureadresseftth.axione.fr/model/commun}libelleErreur" + ).text.strip() + ) + return AxioneResult( + codeRetour=codeRetour, + axioneErreur=axioneErreur, + batiments=parsedBatiments + ) def parse_batiment(batiment) -> BatimentResult: etatBatiment = batiment.get("etatBatiment", None) diff --git a/fixtures/dummy-data-2.xml b/fixtures/dummy-data-2.xml new file mode 100644 index 0000000..a8b8789 --- /dev/null +++ b/fixtures/dummy-data-2.xml @@ -0,0 +1,46 @@ + + + + + + + + + 0 + + BEFO + true + + + + + + + + + + + + + + + BF-ISS1-0110 + + + + + + + + + + PME + OC + + + + + + + + \ No newline at end of file diff --git a/fixtures/dummy-data-3.xml b/fixtures/dummy-data-3.xml new file mode 100644 index 0000000..f83388c --- /dev/null +++ b/fixtures/dummy-data-3.xml @@ -0,0 +1,36 @@ + + + + + + + + + 1 + I01 + Code Rivoli introuvable, manquant ou incomplet + + + + + + + + + + + + + + + + PME + OI + + + + + + + + \ No newline at end of file diff --git a/templates/landing_form.html b/templates/landing_form.html index b8df301..4f6f9cd 100644 --- a/templates/landing_form.html +++ b/templates/landing_form.html @@ -7,8 +7,8 @@ - + diff --git a/templates/result.html b/templates/result.html index 5db72a8..3d044b9 100644 --- a/templates/result.html +++ b/templates/result.html @@ -11,11 +11,12 @@ -

Aquilenet

-
+

Aquilenet

+ {% if result['codeRetour'] == 0 %} +

Test d'Éligibilité FTTH Aquilenet: Résultats

Résultat pour le PTO: {{ pto }}

- {% for batiment in result %} + {% for batiment in result['batiments'] %} @@ -58,5 +59,12 @@
{% endfor %}
+ {% else %} +
+

Erreur

+

Code d'erreur: {{ result['axioneErreur']['codeErreur'] }}

+

Description de l'erreur: {{ result['axioneErreur']['libelleErreur'] }}

+
+ {% endif %} diff --git a/templates/style.css b/templates/style.css index bcfada8..64e7c6e 100644 --- a/templates/style.css +++ b/templates/style.css @@ -93,7 +93,7 @@ form { align-self: center; margin-bottom: 2em; } - +*/ table,td { border: 2px solid #333; border-collapse: collapse; @@ -107,4 +107,4 @@ thead, tfoot { td { padding-left: 1em; padding-right: 1em; -} */ +} diff --git a/webapp.py b/webapp.py index 8641b9a..6a5be00 100644 --- a/webapp.py +++ b/webapp.py @@ -58,7 +58,12 @@ def test_address(): numeroVoie = escape(request.form['numeroVoie']) # Trimming rivoli's key codeRivoli = escape(request.form['codeRivoli'])[:-1] - result = query_axione_fantoir(cfg, codeInsee, codeRivoli, numeroVoie) + result = parse_response(query_axione_fantoir(cfg, codeInsee, codeRivoli, numeroVoie)) + if cfg.debug: + print("===================") + print("Dummy response: ") + print(result) + print("===================") return render_template("result.html", pto="", result=result)