- Implemented comprehensive tests for the Kommunikation Sync functionality, covering base64 encoding, marker parsing, creation, type detection, and integration scenarios. - Added a verification script to check for unique IDs in Advoware communications, ensuring stability and integrity of the IDs. - Created utility scripts for code validation, notification testing, and PUT response detail analysis to enhance development and testing processes. - Updated README with details on new tools and their usage.
253 lines
8.1 KiB
Python
253 lines
8.1 KiB
Python
"""
|
|
Tiefenanalyse: kommKz Feld-Verhalten
|
|
|
|
Beobachtung:
|
|
- PUT Response zeigt kommKz: 1
|
|
- Nachfolgender GET zeigt kommKz: 0 (!)
|
|
- 0 ist kein gültiger kommKz-Wert (1-12)
|
|
|
|
Test: Prüfe ob kommKz überhaupt korrekt gespeichert/gelesen wird
|
|
"""
|
|
|
|
import asyncio
|
|
import json
|
|
from services.advoware import AdvowareAPI
|
|
|
|
TEST_BETNR = 104860
|
|
|
|
|
|
class SimpleContext:
|
|
class Logger:
|
|
def info(self, msg): print(f"[INFO] {msg}")
|
|
def error(self, msg): print(f"[ERROR] {msg}")
|
|
def warning(self, msg): print(f"[WARN] {msg}")
|
|
def debug(self, msg): print(f"[DEBUG] {msg}")
|
|
|
|
def __init__(self):
|
|
self.logger = self.Logger()
|
|
|
|
|
|
def print_section(title):
|
|
print("\n" + "="*70)
|
|
print(title)
|
|
print("="*70)
|
|
|
|
|
|
async def test_kommkz_behavior():
|
|
"""Teste kommKz Verhalten in Detail"""
|
|
|
|
context = SimpleContext()
|
|
advo = AdvowareAPI(context)
|
|
|
|
# SCHRITT 1: Erstelle mit kommKz=3 (Mobil)
|
|
print_section("SCHRITT 1: CREATE mit kommKz=3 (Mobil)")
|
|
|
|
create_data = {
|
|
'kommKz': 3, # Mobil
|
|
'tlf': '+49 170 999-TEST',
|
|
'bemerkung': 'TEST-DEEP: Initial kommKz=3',
|
|
'online': False
|
|
}
|
|
|
|
print(f"📤 CREATE Request:")
|
|
print(json.dumps(create_data, indent=2))
|
|
|
|
result = await advo.api_call(
|
|
f'api/v1/advonet/Beteiligte/{TEST_BETNR}/Kommunikationen',
|
|
method='POST',
|
|
data=create_data
|
|
)
|
|
|
|
if isinstance(result, list):
|
|
created = result[0]
|
|
else:
|
|
created = result
|
|
|
|
komm_id = created['id']
|
|
|
|
print(f"\n✅ POST Response:")
|
|
print(f" id: {created['id']}")
|
|
print(f" kommKz: {created['kommKz']}")
|
|
print(f" kommArt: {created['kommArt']}")
|
|
print(f" tlf: {created['tlf']}")
|
|
print(f" bemerkung: {created['bemerkung']}")
|
|
|
|
# SCHRITT 2: Sofortiger GET nach CREATE
|
|
print_section("SCHRITT 2: GET direkt nach CREATE")
|
|
|
|
beteiligte = await advo.api_call(
|
|
f'api/v1/advonet/Beteiligte/{TEST_BETNR}',
|
|
method='GET'
|
|
)
|
|
|
|
if isinstance(beteiligte, list):
|
|
beteiligte = beteiligte[0]
|
|
|
|
kommunikationen = beteiligte.get('kommunikation', [])
|
|
get_komm = next((k for k in kommunikationen if k['id'] == komm_id), None)
|
|
|
|
if get_komm:
|
|
print(f"📥 GET Response:")
|
|
print(f" id: {get_komm['id']}")
|
|
print(f" kommKz: {get_komm['kommKz']}")
|
|
print(f" kommArt: {get_komm['kommArt']}")
|
|
print(f" tlf: {get_komm['tlf']}")
|
|
print(f" bemerkung: {get_komm['bemerkung']}")
|
|
|
|
if get_komm['kommKz'] != 3:
|
|
print(f"\n⚠️ WARNUNG: kommKz nach CREATE stimmt nicht!")
|
|
print(f" Erwartet: 3")
|
|
print(f" Tatsächlich: {get_komm['kommKz']}")
|
|
|
|
# SCHRITT 3: PUT mit gleichem kommKz (keine Änderung)
|
|
print_section("SCHRITT 3: PUT mit gleichem kommKz=3")
|
|
|
|
update_data = {
|
|
'kommKz': 3, # GLEICH wie original
|
|
'tlf': '+49 170 999-TEST',
|
|
'bemerkung': 'TEST-DEEP: PUT mit gleichem kommKz=3',
|
|
'online': False
|
|
}
|
|
|
|
print(f"📤 PUT Request (keine kommKz-Änderung):")
|
|
print(json.dumps(update_data, indent=2))
|
|
|
|
result = await advo.api_call(
|
|
f'api/v1/advonet/Beteiligte/{TEST_BETNR}/Kommunikationen/{komm_id}',
|
|
method='PUT',
|
|
data=update_data
|
|
)
|
|
|
|
print(f"\n✅ PUT Response:")
|
|
print(f" kommKz: {result['kommKz']}")
|
|
print(f" kommArt: {result['kommArt']}")
|
|
print(f" bemerkung: {result['bemerkung']}")
|
|
|
|
# GET nach PUT
|
|
print(f"\n🔍 GET nach PUT:")
|
|
beteiligte = await advo.api_call(
|
|
f'api/v1/advonet/Beteiligte/{TEST_BETNR}',
|
|
method='GET'
|
|
)
|
|
|
|
if isinstance(beteiligte, list):
|
|
beteiligte = beteiligte[0]
|
|
|
|
kommunikationen = beteiligte.get('kommunikation', [])
|
|
get_komm = next((k for k in kommunikationen if k['id'] == komm_id), None)
|
|
|
|
if get_komm:
|
|
print(f" kommKz: {get_komm['kommKz']}")
|
|
print(f" kommArt: {get_komm['kommArt']}")
|
|
print(f" bemerkung: {get_komm['bemerkung']}")
|
|
|
|
# SCHRITT 4: PUT mit ANDEREM kommKz
|
|
print_section("SCHRITT 4: PUT mit kommKz=7 (FaxPrivat)")
|
|
|
|
update_data = {
|
|
'kommKz': 7, # ÄNDERN: Mobil → FaxPrivat
|
|
'tlf': '+49 170 999-TEST',
|
|
'bemerkung': 'TEST-DEEP: Versuch kommKz 3→7',
|
|
'online': False
|
|
}
|
|
|
|
print(f"📤 PUT Request (kommKz-Änderung 3→7):")
|
|
print(json.dumps(update_data, indent=2))
|
|
|
|
result = await advo.api_call(
|
|
f'api/v1/advonet/Beteiligte/{TEST_BETNR}/Kommunikationen/{komm_id}',
|
|
method='PUT',
|
|
data=update_data
|
|
)
|
|
|
|
print(f"\n✅ PUT Response:")
|
|
print(f" kommKz: {result['kommKz']}")
|
|
print(f" kommArt: {result['kommArt']}")
|
|
print(f" bemerkung: {result['bemerkung']}")
|
|
|
|
# GET nach PUT mit Änderungsversuch
|
|
print(f"\n🔍 GET nach PUT (mit Änderungsversuch):")
|
|
beteiligte = await advo.api_call(
|
|
f'api/v1/advonet/Beteiligte/{TEST_BETNR}',
|
|
method='GET'
|
|
)
|
|
|
|
if isinstance(beteiligte, list):
|
|
beteiligte = beteiligte[0]
|
|
|
|
kommunikationen = beteiligte.get('kommunikation', [])
|
|
get_komm = next((k for k in kommunikationen if k['id'] == komm_id), None)
|
|
|
|
if get_komm:
|
|
print(f" kommKz: {get_komm['kommKz']}")
|
|
print(f" kommArt: {get_komm['kommArt']}")
|
|
print(f" bemerkung: {get_komm['bemerkung']}")
|
|
|
|
print(f"\n📊 Zusammenfassung für ID {komm_id}:")
|
|
print(f" CREATE Request: kommKz=3")
|
|
print(f" CREATE Response: kommKz={created['kommKz']}")
|
|
print(f" GET nach CREATE: kommKz={kommunikationen[0].get('kommKz', 'N/A') if kommunikationen else 'N/A'}")
|
|
print(f" PUT Request (change): kommKz=7")
|
|
print(f" PUT Response: kommKz={result['kommKz']}")
|
|
print(f" GET nach PUT: kommKz={get_komm['kommKz']}")
|
|
|
|
if get_komm['kommKz'] == 7:
|
|
print(f"\n✅ kommKz wurde geändert auf 7!")
|
|
elif get_komm['kommKz'] == 3:
|
|
print(f"\n❌ kommKz blieb bei 3 (READ-ONLY bestätigt)")
|
|
elif get_komm['kommKz'] == 0:
|
|
print(f"\n⚠️ kommKz ist 0 (ungültiger Wert - möglicherweise Bug in API)")
|
|
else:
|
|
print(f"\n⚠️ kommKz hat unerwarteten Wert: {get_komm['kommKz']}")
|
|
|
|
# SCHRITT 5: Vergleiche mit bestehenden Kommunikationen
|
|
print_section("SCHRITT 5: Vergleich mit bestehenden Kommunikationen")
|
|
|
|
print(f"\nAlle Kommunikationen von Beteiligten {TEST_BETNR}:")
|
|
for i, k in enumerate(kommunikationen):
|
|
print(f"\n [{i+1}] ID: {k['id']}")
|
|
print(f" kommKz: {k['kommKz']}")
|
|
print(f" kommArt: {k['kommArt']}")
|
|
print(f" tlf: {k.get('tlf', '')[:40]}")
|
|
print(f" bemerkung: {k.get('bemerkung', '')[:40] if k.get('bemerkung') else 'null'}")
|
|
print(f" online: {k.get('online')}")
|
|
|
|
# Prüfe auf Inkonsistenzen
|
|
if k['kommKz'] == 0 and k['kommArt'] != 0:
|
|
print(f" ⚠️ INKONSISTENZ: kommKz=0 aber kommArt={k['kommArt']}")
|
|
|
|
print(f"\n⚠️ Test-Kommunikation {komm_id} manuell löschen!")
|
|
|
|
return komm_id
|
|
|
|
|
|
async def main():
|
|
print("\n" + "="*70)
|
|
print("TIEFENANALYSE: kommKz Feld-Verhalten")
|
|
print("="*70)
|
|
print("\nZiel: Verstehen warum GET kommKz=0 zeigt")
|
|
print("Methode: Schrittweise CREATE/PUT/GET mit detailliertem Tracking\n")
|
|
|
|
try:
|
|
komm_id = await test_kommkz_behavior()
|
|
|
|
print_section("FAZIT")
|
|
print("\n📌 Erkenntnisse:")
|
|
print(" 1. POST Response zeigt den gesendeten kommKz")
|
|
print(" 2. PUT Response zeigt oft den gesendeten kommKz")
|
|
print(" 3. GET Response zeigt den TATSÄCHLICH gespeicherten Wert")
|
|
print(" 4. kommKz=0 in GET deutet auf ein Problem hin")
|
|
print("\n💡 Empfehlung:")
|
|
print(" - Immer GET nach PUT für Verifizierung")
|
|
print(" - Nicht auf PUT Response verlassen")
|
|
print(" - kommKz ist definitiv READ-ONLY bei PUT")
|
|
|
|
except Exception as e:
|
|
print(f"\n❌ Fehler: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
asyncio.run(main())
|