From 917ea44b71b809e2b036737f792b1cdabf689da5 Mon Sep 17 00:00:00 2001 From: GitHub Copilot Date: Mon, 1 Sep 2025 17:15:45 +0000 Subject: [PATCH] feat: Implement GetBinInfo XML command - Add GetBinInfo command to XML API endpoint - Return bin details including ID and ContentCode in XML format - Implement comprehensive error handling for missing bins and invalid requests - Add validation for required Bin ID parameter - Add 3 comprehensive test cases covering success and error scenarios - Update USER_MANUAL.md with detailed GetBinInfo documentation - Maintain backward compatibility with existing XML commands Resolves #13 --- USER_MANUAL.md | 49 +++++++++++++++++++++++++++++++++++++- src/main.py | 26 +++++++++++++++++++++ test.db | Bin 57344 -> 57344 bytes tests/test_main.py | 57 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 131 insertions(+), 1 deletion(-) diff --git a/USER_MANUAL.md b/USER_MANUAL.md index d5176c7..98da02f 100644 --- a/USER_MANUAL.md +++ b/USER_MANUAL.md @@ -56,6 +56,44 @@ Die API verfügt über eine integrierte Hintergrund-Simulationslogik, die automa - `POST /api` - XML-basierte Befehle - `CreateTaskgroup` - Neue Aufgabengruppe erstellen - `GetTaskInfo` - Aufgaben- oder Gruppeninformationen abrufen + - `GetBinInfo` - Detaillierte Informationen über einen Behälter abrufen (NEU) + +#### GetBinInfo-Befehl (NEU) +Der `GetBinInfo`-Befehl ermöglicht das Abrufen detaillierter Informationen über einen bestimmten Behälter. + +**Anfrage-Format:** +```xml + + + BIN-12345 + + +``` + +**Antwort-Format (Erfolg):** +```xml + + + BIN-12345 + 5 + + +``` + +**Antwort-Format (Fehler):** +```xml + + + Bin not found: BIN-99999 + + +``` + +**Validierungen:** +- Bin-ID ist erforderlich +- Behälter muss in der Datenbank existieren +- Gibt HTTP 400 bei fehlender Bin-ID zurück +- Gibt HTTP 404 bei nicht gefundenem Behälter zurück ## Installation und Start @@ -109,7 +147,16 @@ Die Anwendung verwendet SQLite für Entwicklung und Tests. Für Produktion kann ## Changelog -### Version 0.2.0 (Aktuell) +### Version 0.3.0 (Aktuell) +- ✅ **GetBinInfo XML-Befehl implementiert** + - Detaillierte Behälterinformationen über XML-API abrufbar + - Vollständige Fehlerbehandlung für nicht existierende Behälter + - Validierung für fehlende Bin-IDs + - Umfassende Tests für alle Szenarien +- ✅ Verbesserte XML-Fehlerbehandlung +- ✅ Erweiterte API-Dokumentation + +### Version 0.2.0 - ✅ **Hintergrund-Simulationslogik implementiert** - Automatische Verarbeitung von Aufgaben im Hintergrund - Statusaktualisierung von Tasks und TaskGroups diff --git a/src/main.py b/src/main.py index 4493bed..107898c 100644 --- a/src/main.py +++ b/src/main.py @@ -183,6 +183,32 @@ async def handle_xml_request(request: Request, db: Session = Depends(get_db)): } } } + + elif command == "GetBinInfo": + bin_info_data = autostore_data[command] + + # Handle case where GetBinInfo is empty or None + if not bin_info_data or not isinstance(bin_info_data, dict): + raise HTTPException(status_code=400, detail="Bin ID is required for GetBinInfo.") + + bin_id = bin_info_data.get("Bin") + + if not bin_id: + raise HTTPException(status_code=400, detail="Bin ID is required for GetBinInfo.") + + bin_obj = crud.get_bin(db, bin_id=bin_id) + if not bin_obj: + raise ValueError(f"Bin not found: {bin_id}") + + response_dict = { + "AutoStore": { + "GetBinInfo": { + "Bin": bin_obj.id, + "ContentCode": str(bin_obj.content_code) + } + } + } + else: # Placeholder for other commands raise HTTPException(status_code=400, detail=f"Unknown or unimplemented command: {command}") diff --git a/test.db b/test.db index e6971641a126d13358541e15c5883aa8c8fa6e6e..29f1891773e1f28a42d8fb0d7e98085a74c1a221 100644 GIT binary patch delta 37 ncmZoTz}#?vd4iOX=xPQA20kd}Wnd5vny6#MB)WQI!h-t%oh}H{ delta 37 ncmZoTz}#?vd4iOX@NNbM20kd}Wnd7TF;T~eNqG0hga!8jq0|X7 diff --git a/tests/test_main.py b/tests/test_main.py index 83d5e74..2abcbba 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -577,3 +577,60 @@ def test_get_task_info_not_found(client): assert response.status_code == 404 response_data = xmltodict.parse(response.content) assert "Taskgroup not found" in response_data["AutoStore"]["Error"]["Description"] + + +def test_get_bin_info_xml(client, db_session): + """Tests the GetBinInfo command for a specific bin.""" + # Arrange: Create a bin in the database + bin_id = "BIN-INFO-01" + bin_data = schemas.BinCreate(id=bin_id, content_code=5) + crud.create_bin(db_session, bin_data) + + # Act: Send GetBinInfo XML request + xml_request = f""" + + + {bin_id} + + + """ + headers = {"Content-Type": "application/xml"} + response = client.post("/api", content=xml_request, headers=headers) + + # Assert: Check response + assert response.status_code == 200 + response_data = xmltodict.parse(response.content) + bin_info = response_data["AutoStore"]["GetBinInfo"] + assert bin_info["Bin"] == bin_id + assert bin_info["ContentCode"] == "5" + + +def test_get_bin_info_not_found_xml(client): + """Tests that GetBinInfo returns an error for a non-existent bin.""" + xml_request = """ + + + NON-EXISTENT-BIN + + + """ + headers = {"Content-Type": "application/xml"} + response = client.post("/api", content=xml_request, headers=headers) + assert response.status_code == 404 + response_data = xmltodict.parse(response.content) + assert "Bin not found" in response_data["AutoStore"]["Error"]["Description"] + + +def test_get_bin_info_missing_bin_id_xml(client): + """Tests that GetBinInfo returns an error when Bin ID is missing.""" + xml_request = """ + + + + + """ + headers = {"Content-Type": "application/xml"} + response = client.post("/api", content=xml_request, headers=headers) + assert response.status_code == 400 + response_data = xmltodict.parse(response.content) + assert "Bin ID is required" in response_data["AutoStore"]["Error"]["Description"]