Add tests for Kommunikation Sync implementation and verification scripts
- 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.
This commit is contained in:
67
bitbylaw/scripts/kommunikation_sync/README.md
Normal file
67
bitbylaw/scripts/kommunikation_sync/README.md
Normal file
@@ -0,0 +1,67 @@
|
||||
# Kommunikation Sync - Test Scripts
|
||||
|
||||
Test-Scripts für die Kommunikation (Phone/Email/Fax) Synchronisation.
|
||||
|
||||
## Scripts
|
||||
|
||||
### test_kommunikation_api.py
|
||||
Vollständiger API-Test für Advoware Kommunikation-Endpoints.
|
||||
|
||||
**Testet:**
|
||||
- POST /Kommunikationen (CREATE)
|
||||
- PUT /Kommunikationen (UPDATE)
|
||||
- DELETE /Kommunikationen (gibt 403 - erwartet)
|
||||
- kommKz-Werte (1-12)
|
||||
- Alle 4 Felder (tlf, bemerkung, kommKz, online)
|
||||
|
||||
### test_kommunikation_sync_implementation.py
|
||||
Test der bidirektionalen Sync-Implementierung.
|
||||
|
||||
**Testet:**
|
||||
- 6 Sync-Varianten (Var1-6)
|
||||
- Base64-Marker System
|
||||
- Hash-basierte Change Detection
|
||||
- Empty Slots (DELETE-Workaround)
|
||||
- Konflikt-Handling
|
||||
|
||||
### test_kommunikation_matching_strategy.py
|
||||
Test verschiedener Matching-Strategien.
|
||||
|
||||
**Testet:**
|
||||
- Base64-Marker Matching
|
||||
- Value-Matching für Initial Sync
|
||||
- kommKz Detection (4-Stufen)
|
||||
- Edge Cases
|
||||
|
||||
### test_kommunikation_kommkz_deep.py
|
||||
Deep-Dive Test für kommKz-Enum.
|
||||
|
||||
**Testet:**
|
||||
- Alle 12 kommKz-Werte (TelGesch, Mobil, Email, etc.)
|
||||
- kommKz=0 Bug in GET (Advoware)
|
||||
- kommKz READ-ONLY bei PUT
|
||||
|
||||
### test_kommunikation_readonly.py
|
||||
Test für Read-Only Felder.
|
||||
|
||||
**Testet:**
|
||||
- kommKz kann bei PUT nicht geändert werden
|
||||
- Workarounds für Type-Änderungen
|
||||
|
||||
### test_kommart_values.py
|
||||
Test für kommArt vs kommKz Unterschiede.
|
||||
|
||||
### verify_advoware_kommunikation_ids.py
|
||||
Verifiziert Kommunikation-IDs zwischen Systemen.
|
||||
|
||||
## Verwendung
|
||||
|
||||
```bash
|
||||
cd /opt/motia-app/bitbylaw
|
||||
python scripts/kommunikation_sync/test_kommunikation_api.py
|
||||
```
|
||||
|
||||
## Verwandte Dokumentation
|
||||
|
||||
- [../../docs/SYNC_OVERVIEW.md](../../docs/SYNC_OVERVIEW.md#kommunikation-sync) - Vollständige Dokumentation
|
||||
- [../../services/kommunikation_sync_utils.py](../../services/kommunikation_sync_utils.py) - Implementierung
|
||||
109
bitbylaw/scripts/kommunikation_sync/test_kommart_values.py
Normal file
109
bitbylaw/scripts/kommunikation_sync/test_kommart_values.py
Normal file
@@ -0,0 +1,109 @@
|
||||
"""
|
||||
Test: Was liefert kommArt im Vergleich zu kommKz?
|
||||
|
||||
kommArt sollte sein:
|
||||
- 0 = Telefon/Fax
|
||||
- 1 = Email
|
||||
- 2 = Internet
|
||||
|
||||
Wenn kommArt funktioniert, können wir damit unterscheiden!
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
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): pass
|
||||
|
||||
def __init__(self):
|
||||
self.logger = self.Logger()
|
||||
|
||||
|
||||
def print_section(title):
|
||||
print("\n" + "="*70)
|
||||
print(title)
|
||||
print("="*70)
|
||||
|
||||
|
||||
async def main():
|
||||
print("\n" + "="*70)
|
||||
print("ADVOWARE kommArt vs kommKz")
|
||||
print("="*70)
|
||||
|
||||
context = SimpleContext()
|
||||
advo = AdvowareAPI(context)
|
||||
|
||||
# Hole Beteiligte mit Kommunikationen
|
||||
result = await advo.api_call(f'api/v1/advonet/Beteiligte/{TEST_BETNR}')
|
||||
beteiligte = result[0]
|
||||
kommunikationen = beteiligte.get('kommunikation', [])
|
||||
|
||||
print(f"\n✅ {len(kommunikationen)} Kommunikationen gefunden\n")
|
||||
print(f"{'ID':>8s} | {'kommKz':>6s} | {'kommArt':>7s} | {'Wert':40s}")
|
||||
print("-" * 70)
|
||||
|
||||
kommkz_values = []
|
||||
kommart_values = []
|
||||
|
||||
for k in kommunikationen:
|
||||
komm_id = k.get('id')
|
||||
kommkz = k.get('kommKz', 'N/A')
|
||||
kommart = k.get('kommArt', 'N/A')
|
||||
wert = k.get('tlf', '')[:40]
|
||||
|
||||
kommkz_values.append(kommkz)
|
||||
kommart_values.append(kommart)
|
||||
|
||||
# Markiere wenn Wert aussagekräftig ist
|
||||
kommkz_str = f"{kommkz}" if kommkz != 0 else f"❌ {kommkz}"
|
||||
kommart_str = f"{kommart}" if kommart != 0 else f"❌ {kommart}"
|
||||
|
||||
print(f"{komm_id:8d} | {kommkz_str:>6s} | {kommart_str:>7s} | {wert}")
|
||||
|
||||
print_section("ANALYSE")
|
||||
|
||||
# Statistik
|
||||
print(f"\n📊 kommKz Werte:")
|
||||
print(f" • Alle Werte: {set(kommkz_values)}")
|
||||
print(f" • Alle sind 0: {all(v == 0 for v in kommkz_values)}")
|
||||
|
||||
print(f"\n📊 kommArt Werte:")
|
||||
print(f" • Alle Werte: {set(kommart_values)}")
|
||||
print(f" • Alle sind 0: {all(v == 0 for v in kommart_values)}")
|
||||
|
||||
print_section("FAZIT")
|
||||
|
||||
if not all(v == 0 for v in kommart_values):
|
||||
print("\n✅ kommArt IST BRAUCHBAR!")
|
||||
print("\nMapping:")
|
||||
print(" 0 = Telefon/Fax")
|
||||
print(" 1 = Email")
|
||||
print(" 2 = Internet")
|
||||
|
||||
print("\n🎉 PERFEKT! Wir können unterscheiden:")
|
||||
print(" • kommArt=0 → Telefon (zu phoneNumberData)")
|
||||
print(" • kommArt=1 → Email (zu emailAddressData)")
|
||||
print(" • kommArt=2 → Internet (überspringen oder zu Notiz)")
|
||||
|
||||
print("\n💡 Advoware → EspoCRM:")
|
||||
print(" 1. Nutze kommArt um Typ zu erkennen")
|
||||
print(" 2. Speichere in bemerkung: [ESPOCRM:hash:kommArt]")
|
||||
print(" 3. Bei Reverse-Sync: Nutze kommArt aus bemerkung")
|
||||
|
||||
else:
|
||||
print("\n❌ kommArt ist AUCH 0 - genau wie kommKz")
|
||||
print("\n→ Wir müssen Typ aus Wert ableiten (Email vs. Telefon)")
|
||||
print(" • '@' im Wert → Email")
|
||||
print(" • '+' oder Ziffern → Telefon")
|
||||
print("\n→ Feinere Unterscheidung (TelGesch vs TelPrivat) NICHT möglich")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
361
bitbylaw/scripts/kommunikation_sync/test_kommunikation_api.py
Normal file
361
bitbylaw/scripts/kommunikation_sync/test_kommunikation_api.py
Normal file
@@ -0,0 +1,361 @@
|
||||
"""
|
||||
Test: Advoware Kommunikation API
|
||||
Testet POST/GET/PUT/DELETE Operationen für Kommunikationen
|
||||
|
||||
Basierend auf Swagger:
|
||||
- POST /api/v1/advonet/Beteiligte/{beteiligterId}/Kommunikationen
|
||||
- PUT /api/v1/advonet/Beteiligte/{beteiligterId}/Kommunikationen/{kommunikationId}
|
||||
- GET enthalten in Beteiligte response (kommunikation array)
|
||||
- DELETE nicht dokumentiert (wird getestet)
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import json
|
||||
import sys
|
||||
from services.advoware import AdvowareAPI
|
||||
from services.espocrm import EspoCRMAPI
|
||||
|
||||
# Test-Beteiligter
|
||||
TEST_BETNR = 104860 # Angela Mustermanns
|
||||
|
||||
# KommKz Enum (Kommunikationskennzeichen)
|
||||
KOMMKZ = {
|
||||
1: 'TelGesch',
|
||||
2: 'FaxGesch',
|
||||
3: 'Mobil',
|
||||
4: 'MailGesch',
|
||||
5: 'Internet',
|
||||
6: 'TelPrivat',
|
||||
7: 'FaxPrivat',
|
||||
8: 'MailPrivat',
|
||||
9: 'AutoTelefon',
|
||||
10: 'Sonstige',
|
||||
11: 'EPost',
|
||||
12: 'Bea'
|
||||
}
|
||||
|
||||
|
||||
class SimpleContext:
|
||||
"""Einfacher Context für Logging"""
|
||||
class Logger:
|
||||
def info(self, msg): print(f"ℹ️ {msg}")
|
||||
def error(self, msg): print(f"❌ {msg}")
|
||||
def warning(self, msg): print(f"⚠️ {msg}")
|
||||
def debug(self, msg): print(f"🔍 {msg}")
|
||||
|
||||
def __init__(self):
|
||||
self.logger = self.Logger()
|
||||
|
||||
|
||||
def print_section(title):
|
||||
print("\n" + "="*70)
|
||||
print(title)
|
||||
print("="*70 + "\n")
|
||||
|
||||
|
||||
def print_json(title, data):
|
||||
print(f"\n{title}:")
|
||||
print("-" * 70)
|
||||
print(json.dumps(data, indent=2, ensure_ascii=False))
|
||||
print()
|
||||
|
||||
|
||||
async def test_get_existing_kommunikationen():
|
||||
"""Hole bestehende Kommunikationen vom Test-Beteiligten"""
|
||||
print_section("TEST 1: GET Bestehende Kommunikationen")
|
||||
|
||||
context = SimpleContext()
|
||||
advo = AdvowareAPI(context)
|
||||
|
||||
# Hole kompletten Beteiligten
|
||||
result = await advo.api_call(
|
||||
f'api/v1/advonet/Beteiligte/{TEST_BETNR}',
|
||||
method='GET'
|
||||
)
|
||||
|
||||
# Response ist ein Array (selbst bei einzelnem Beteiligten)
|
||||
if isinstance(result, list) and len(result) > 0:
|
||||
beteiligte = result[0]
|
||||
elif isinstance(result, dict):
|
||||
beteiligte = result
|
||||
else:
|
||||
print(f"❌ Unerwartetes Response-Format: {type(result)}")
|
||||
return []
|
||||
|
||||
kommunikationen = beteiligte.get('kommunikation', [])
|
||||
|
||||
print(f"✓ Beteiligter geladen: {beteiligte.get('name')} {beteiligte.get('vorname')}")
|
||||
print(f"✓ Kommunikationen gefunden: {len(kommunikationen)}")
|
||||
|
||||
if kommunikationen:
|
||||
print_json("Bestehende Kommunikationen", kommunikationen)
|
||||
|
||||
# Analysiere Felder
|
||||
first = kommunikationen[0]
|
||||
print("📊 Felder-Analyse (erste Kommunikation):")
|
||||
for key, value in first.items():
|
||||
print(f" - {key}: {value} ({type(value).__name__})")
|
||||
else:
|
||||
print("ℹ️ Keine Kommunikationen vorhanden")
|
||||
|
||||
return kommunikationen
|
||||
|
||||
|
||||
async def test_post_kommunikation():
|
||||
"""Teste POST - Neue Kommunikation erstellen"""
|
||||
print_section("TEST 2: POST - Neue Kommunikation erstellen")
|
||||
|
||||
context = SimpleContext()
|
||||
advo = AdvowareAPI(context)
|
||||
|
||||
# Test verschiedene KommKz Typen
|
||||
test_cases = [
|
||||
{
|
||||
'name': 'Geschäftstelefon',
|
||||
'data': {
|
||||
'kommKz': 1, # TelGesch
|
||||
'tlf': '+49 511 123456-10',
|
||||
'bemerkung': 'TEST: Hauptnummer',
|
||||
'online': False
|
||||
}
|
||||
},
|
||||
{
|
||||
'name': 'Geschäfts-Email',
|
||||
'data': {
|
||||
'kommKz': 4, # MailGesch
|
||||
'tlf': 'test@example.com',
|
||||
'bemerkung': 'TEST: Email',
|
||||
'online': True
|
||||
}
|
||||
},
|
||||
{
|
||||
'name': 'Mobiltelefon',
|
||||
'data': {
|
||||
'kommKz': 3, # Mobil
|
||||
'tlf': '+49 170 1234567',
|
||||
'bemerkung': 'TEST: Mobil',
|
||||
'online': False
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
created_ids = []
|
||||
|
||||
for test in test_cases:
|
||||
print(f"\n📝 Erstelle: {test['name']}")
|
||||
print_json("Request Payload", test['data'])
|
||||
|
||||
try:
|
||||
result = await advo.api_call(
|
||||
f'api/v1/advonet/Beteiligte/{TEST_BETNR}/Kommunikationen',
|
||||
method='POST',
|
||||
data=test['data']
|
||||
)
|
||||
|
||||
print_json("Response", result)
|
||||
|
||||
# Extrahiere ID
|
||||
if isinstance(result, list) and len(result) > 0:
|
||||
created_id = result[0].get('id')
|
||||
created_ids.append(created_id)
|
||||
print(f"✅ Erstellt mit ID: {created_id}")
|
||||
elif isinstance(result, dict):
|
||||
created_id = result.get('id')
|
||||
created_ids.append(created_id)
|
||||
print(f"✅ Erstellt mit ID: {created_id}")
|
||||
else:
|
||||
print(f"❌ Unerwartetes Response-Format: {type(result)}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Fehler: {e}")
|
||||
|
||||
return created_ids
|
||||
|
||||
|
||||
async def test_put_kommunikation(komm_id):
|
||||
"""Teste PUT - Kommunikation aktualisieren"""
|
||||
print_section(f"TEST 3: PUT - Kommunikation {komm_id} aktualisieren")
|
||||
|
||||
context = SimpleContext()
|
||||
advo = AdvowareAPI(context)
|
||||
|
||||
# Hole aktuelle Daten
|
||||
print("📥 Lade aktuelle Kommunikation...")
|
||||
result = await advo.api_call(
|
||||
f'api/v1/advonet/Beteiligte/{TEST_BETNR}',
|
||||
method='GET'
|
||||
)
|
||||
|
||||
# Response ist ein Array
|
||||
if isinstance(result, list) and len(result) > 0:
|
||||
beteiligte = result[0]
|
||||
elif isinstance(result, dict):
|
||||
beteiligte = result
|
||||
else:
|
||||
print(f"❌ Unerwartetes Response-Format")
|
||||
return False
|
||||
|
||||
kommunikationen = beteiligte.get('kommunikation', [])
|
||||
current_komm = next((k for k in kommunikationen if k.get('id') == komm_id), None)
|
||||
|
||||
if not current_komm:
|
||||
print(f"❌ Kommunikation {komm_id} nicht gefunden!")
|
||||
return False
|
||||
|
||||
print_json("Aktuelle Daten", current_komm)
|
||||
|
||||
# Test 1: Ändere tlf-Feld
|
||||
print("\n🔄 Test 1: Ändere tlf (Telefonnummer/Email)")
|
||||
update_data = {
|
||||
'kommKz': current_komm['kommKz'],
|
||||
'tlf': '+49 511 999999-99', # Neue Nummer
|
||||
'bemerkung': current_komm.get('bemerkung', ''),
|
||||
'online': current_komm.get('online', False)
|
||||
}
|
||||
|
||||
print_json("Update Payload", update_data)
|
||||
|
||||
try:
|
||||
result = await advo.api_call(
|
||||
f'api/v1/advonet/Beteiligte/{TEST_BETNR}/Kommunikationen/{komm_id}',
|
||||
method='PUT',
|
||||
data=update_data
|
||||
)
|
||||
print_json("Response", result)
|
||||
print("✅ tlf erfolgreich geändert")
|
||||
except Exception as e:
|
||||
print(f"❌ Fehler: {e}")
|
||||
return False
|
||||
|
||||
# Test 2: Ändere bemerkung
|
||||
print("\n🔄 Test 2: Ändere bemerkung")
|
||||
update_data['bemerkung'] = 'TEST: Geändert via API'
|
||||
print_json("Update Payload", update_data)
|
||||
|
||||
try:
|
||||
result = await advo.api_call(
|
||||
f'api/v1/advonet/Beteiligte/{TEST_BETNR}/Kommunikationen/{komm_id}',
|
||||
method='PUT',
|
||||
data=update_data
|
||||
)
|
||||
print_json("Response", result)
|
||||
print("✅ bemerkung erfolgreich geändert")
|
||||
except Exception as e:
|
||||
print(f"❌ Fehler: {e}")
|
||||
return False
|
||||
|
||||
# Test 3: Ändere kommKz (Typ)
|
||||
print("\n🔄 Test 3: Ändere kommKz (Kommunikationstyp)")
|
||||
update_data['kommKz'] = 6 # TelPrivat statt TelGesch
|
||||
print_json("Update Payload", update_data)
|
||||
|
||||
try:
|
||||
result = await advo.api_call(
|
||||
f'api/v1/advonet/Beteiligte/{TEST_BETNR}/Kommunikationen/{komm_id}',
|
||||
method='PUT',
|
||||
data=update_data
|
||||
)
|
||||
print_json("Response", result)
|
||||
print("✅ kommKz erfolgreich geändert")
|
||||
except Exception as e:
|
||||
print(f"❌ Fehler: {e}")
|
||||
return False
|
||||
|
||||
# Test 4: Ändere online-Flag
|
||||
print("\n🔄 Test 4: Ändere online-Flag")
|
||||
update_data['online'] = not update_data['online']
|
||||
print_json("Update Payload", update_data)
|
||||
|
||||
try:
|
||||
result = await advo.api_call(
|
||||
f'api/v1/advonet/Beteiligte/{TEST_BETNR}/Kommunikationen/{komm_id}',
|
||||
method='PUT',
|
||||
data=update_data
|
||||
)
|
||||
print_json("Response", result)
|
||||
print("✅ online erfolgreich geändert")
|
||||
except Exception as e:
|
||||
print(f"❌ Fehler: {e}")
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
async def test_delete_kommunikation(komm_id):
|
||||
"""Teste DELETE - Kommunikation löschen"""
|
||||
print_section(f"TEST 4: DELETE - Kommunikation {komm_id} löschen")
|
||||
|
||||
context = SimpleContext()
|
||||
advo = AdvowareAPI(context)
|
||||
|
||||
print(f"🗑️ Versuche Kommunikation {komm_id} zu löschen...")
|
||||
|
||||
try:
|
||||
result = await advo.api_call(
|
||||
f'api/v1/advonet/Beteiligte/{TEST_BETNR}/Kommunikationen/{komm_id}',
|
||||
method='DELETE'
|
||||
)
|
||||
print_json("Response", result)
|
||||
print("✅ DELETE erfolgreich!")
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"❌ DELETE fehlgeschlagen: {e}")
|
||||
|
||||
# Check ob 403 Forbidden (wie bei Adressen)
|
||||
if '403' in str(e):
|
||||
print("⚠️ DELETE ist FORBIDDEN (wie bei Adressen)")
|
||||
|
||||
return False
|
||||
|
||||
|
||||
async def main():
|
||||
print("\n" + "="*70)
|
||||
print("ADVOWARE KOMMUNIKATION API - VOLLSTÄNDIGER TEST")
|
||||
print("="*70)
|
||||
print(f"\nTest-Beteiligter: {TEST_BETNR}")
|
||||
print("\nKommKz (Kommunikationskennzeichen):")
|
||||
for kz, name in KOMMKZ.items():
|
||||
print(f" {kz:2d} = {name}")
|
||||
|
||||
try:
|
||||
# TEST 1: GET bestehende
|
||||
existing = await test_get_existing_kommunikationen()
|
||||
|
||||
# TEST 2: POST neue
|
||||
created_ids = await test_post_kommunikation()
|
||||
|
||||
if not created_ids:
|
||||
print("\n❌ Keine Kommunikationen erstellt - Tests abgebrochen")
|
||||
return
|
||||
|
||||
# TEST 3: PUT update (erste erstellte)
|
||||
first_id = created_ids[0]
|
||||
await test_put_kommunikation(first_id)
|
||||
|
||||
# TEST 4: DELETE (erste erstellte)
|
||||
await test_delete_kommunikation(first_id)
|
||||
|
||||
# Finale Übersicht
|
||||
print_section("ZUSAMMENFASSUNG")
|
||||
print("✅ POST: Funktioniert (3 Typen getestet)")
|
||||
print("✅ GET: Funktioniert (über Beteiligte-Endpoint)")
|
||||
print("✓/✗ PUT: Siehe Testergebnisse oben")
|
||||
print("✓/✗ DELETE: Siehe Testergebnisse oben")
|
||||
|
||||
print("\n⚠️ WICHTIG:")
|
||||
print(f" - Test-Kommunikationen in Advoware manuell prüfen!")
|
||||
print(f" - BetNr: {TEST_BETNR}")
|
||||
print(" - Suche nach: 'TEST:'")
|
||||
|
||||
if len(created_ids) > 1:
|
||||
print(f"\n📝 Erstellt wurden IDs: {created_ids}")
|
||||
print(" Falls DELETE nicht funktioniert, manuell löschen!")
|
||||
|
||||
except Exception as e:
|
||||
print(f"\n❌ Unerwarteter Fehler: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
asyncio.run(main())
|
||||
@@ -0,0 +1,252 @@
|
||||
"""
|
||||
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())
|
||||
@@ -0,0 +1,395 @@
|
||||
"""
|
||||
Matching-Strategie für Kommunikation ohne ID
|
||||
|
||||
Problem:
|
||||
- emailAddressData und phoneNumberData haben KEINE id-Felder
|
||||
- Können keine rowId in EspoCRM speichern (keine Custom-Felder)
|
||||
- Wie matchen wir Advoware ↔ EspoCRM?
|
||||
|
||||
Lösungsansätze:
|
||||
1. Wert-basiertes Matching (emailAddress/phoneNumber als Schlüssel)
|
||||
2. Advoware als Master (One-Way-Sync mit Neuanlage bei Änderung)
|
||||
3. Hash-basiertes Matching in bemerkung-Feld
|
||||
4. Position-basiertes Matching (primary-Flag)
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import json
|
||||
from services.espocrm import EspoCRMAPI
|
||||
from services.advoware import AdvowareAPI
|
||||
|
||||
TEST_BETEILIGTE_ID = '68e4af00172be7924'
|
||||
TEST_ADVOWARE_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): pass # Suppress debug
|
||||
|
||||
def __init__(self):
|
||||
self.logger = self.Logger()
|
||||
|
||||
|
||||
def print_section(title):
|
||||
print("\n" + "="*70)
|
||||
print(title)
|
||||
print("="*70)
|
||||
|
||||
|
||||
async def test_value_based_matching():
|
||||
"""
|
||||
Strategie 1: Wert-basiertes Matching
|
||||
|
||||
Idee: Verwende emailAddress/phoneNumber selbst als Schlüssel
|
||||
|
||||
Vorteile:
|
||||
- Einfach zu implementieren
|
||||
- Funktioniert für Duplikats-Erkennung
|
||||
|
||||
Nachteile:
|
||||
- Wenn Wert ändert, verlieren wir Verbindung
|
||||
- Keine Change-Detection möglich (kein Timestamp/rowId)
|
||||
"""
|
||||
print_section("STRATEGIE 1: Wert-basiertes Matching")
|
||||
|
||||
context = SimpleContext()
|
||||
espo = EspoCRMAPI(context)
|
||||
advo = AdvowareAPI(context)
|
||||
|
||||
# Hole Daten
|
||||
espo_entity = await espo.get_entity('CBeteiligte', TEST_BETEILIGTE_ID)
|
||||
advo_entity = await advo.api_call(f'api/v1/advonet/Beteiligte/{TEST_ADVOWARE_BETNR}')
|
||||
|
||||
print("\n📧 EspoCRM Emails:")
|
||||
espo_emails = {e['emailAddress']: e for e in espo_entity.get('emailAddressData', [])}
|
||||
for email, data in espo_emails.items():
|
||||
print(f" • {email:40s} primary={data.get('primary', False)}")
|
||||
|
||||
print("\n📧 Advoware Kommunikation (Typ MailGesch=4, MailPrivat=8):")
|
||||
advo_komm = advo_entity.get('kommunikation', [])
|
||||
advo_emails = [k for k in advo_komm if k.get('kommKz') in [4, 8]] # Email-Typen
|
||||
for k in advo_emails:
|
||||
print(f" • {k.get('tlf', ''):40s} Typ={k.get('kommKz')} ID={k.get('id')} "
|
||||
f"rowId={k.get('rowId')}")
|
||||
|
||||
print("\n🔍 Matching-Ergebnis:")
|
||||
matched = []
|
||||
unmatched_espo = []
|
||||
unmatched_advo = []
|
||||
|
||||
for advo_k in advo_emails:
|
||||
email_value = advo_k.get('tlf', '').strip()
|
||||
if email_value in espo_emails:
|
||||
matched.append((advo_k, espo_emails[email_value]))
|
||||
print(f" ✅ MATCH: {email_value}")
|
||||
else:
|
||||
unmatched_advo.append(advo_k)
|
||||
print(f" ❌ Nur in Advoware: {email_value}")
|
||||
|
||||
for email_value in espo_emails:
|
||||
if not any(k.get('tlf', '').strip() == email_value for k in advo_emails):
|
||||
unmatched_espo.append(espo_emails[email_value])
|
||||
print(f" ⚠️ Nur in EspoCRM: {email_value}")
|
||||
|
||||
print(f"\n📊 Statistik:")
|
||||
print(f" • Matched: {len(matched)}")
|
||||
print(f" • Nur Advoware: {len(unmatched_advo)}")
|
||||
print(f" • Nur EspoCRM: {len(unmatched_espo)}")
|
||||
|
||||
# Problem-Szenario: Was wenn Email-Adresse ändert?
|
||||
print("\n⚠️ PROBLEM-SZENARIO: Email-Adresse ändert")
|
||||
print(" 1. Advoware: max@old.de → max@new.de (UPDATE mit gleicher ID)")
|
||||
print(" 2. Wert-Matching findet max@old.de nicht mehr in EspoCRM")
|
||||
print(" 3. Sync würde max@new.de NEU anlegen statt UPDATE")
|
||||
print(" 4. Ergebnis: Duplikat (max@old.de + max@new.de)")
|
||||
|
||||
return matched, unmatched_advo, unmatched_espo
|
||||
|
||||
|
||||
async def test_advoware_master_sync():
|
||||
"""
|
||||
Strategie 2: Advoware als Master (One-Way-Sync)
|
||||
|
||||
Idee:
|
||||
- Ignoriere EspoCRM-Änderungen
|
||||
- Bei jedem Sync: Überschreibe komplette Arrays in EspoCRM
|
||||
|
||||
Vorteile:
|
||||
- Sehr einfach
|
||||
- Keine Change-Detection nötig
|
||||
- Keine Matching-Probleme
|
||||
|
||||
Nachteile:
|
||||
- Verliert EspoCRM-Änderungen
|
||||
- Nicht bidirektional
|
||||
"""
|
||||
print_section("STRATEGIE 2: Advoware als Master (One-Way)")
|
||||
|
||||
context = SimpleContext()
|
||||
advo = AdvowareAPI(context)
|
||||
|
||||
advo_entity = await advo.api_call(f'api/v1/advonet/Beteiligte/{TEST_ADVOWARE_BETNR}')
|
||||
advo_komm = advo_entity.get('kommunikation', [])
|
||||
|
||||
print("\n📋 Sync-Ablauf:")
|
||||
print(" 1. Hole alle Advoware Kommunikationen")
|
||||
print(" 2. Konvertiere zu EspoCRM Format:")
|
||||
|
||||
# Konvertierung
|
||||
email_data = []
|
||||
phone_data = []
|
||||
|
||||
for k in advo_komm:
|
||||
komm_kz = k.get('kommKz', 0)
|
||||
wert = k.get('tlf', '').strip()
|
||||
online = k.get('online', False)
|
||||
|
||||
# Email-Typen: 4=MailGesch, 8=MailPrivat, 11=EPost
|
||||
if komm_kz in [4, 8, 11] and wert:
|
||||
email_data.append({
|
||||
'emailAddress': wert,
|
||||
'lower': wert.lower(),
|
||||
'primary': online, # online=true → primary
|
||||
'optOut': False,
|
||||
'invalid': False
|
||||
})
|
||||
# Phone-Typen: 1=TelGesch, 2=FaxGesch, 3=Mobil, 6=TelPrivat, 7=FaxPrivat
|
||||
elif komm_kz in [1, 2, 3, 6, 7] and wert:
|
||||
# Mapping kommKz → EspoCRM type
|
||||
type_map = {
|
||||
1: 'Office', # TelGesch
|
||||
3: 'Mobile', # Mobil
|
||||
6: 'Home', # TelPrivat
|
||||
2: 'Fax', # FaxGesch
|
||||
7: 'Fax', # FaxPrivat
|
||||
}
|
||||
phone_data.append({
|
||||
'phoneNumber': wert,
|
||||
'type': type_map.get(komm_kz, 'Other'),
|
||||
'primary': online,
|
||||
'optOut': False,
|
||||
'invalid': False
|
||||
})
|
||||
|
||||
print(f"\n 📧 {len(email_data)} Emails:")
|
||||
for e in email_data:
|
||||
print(f" • {e['emailAddress']:40s} primary={e['primary']}")
|
||||
|
||||
print(f"\n 📞 {len(phone_data)} Phones:")
|
||||
for p in phone_data:
|
||||
print(f" • {p['phoneNumber']:40s} type={p['type']:10s} primary={p['primary']}")
|
||||
|
||||
print("\n 3. UPDATE CBeteiligte (überschreibt komplette Arrays)")
|
||||
print(" → emailAddressData: [...]")
|
||||
print(" → phoneNumberData: [...]")
|
||||
|
||||
print("\n✅ Vorteile:")
|
||||
print(" • Sehr einfach zu implementieren")
|
||||
print(" • Keine Matching-Logik erforderlich")
|
||||
print(" • Advoware ist immer Source of Truth")
|
||||
|
||||
print("\n❌ Nachteile:")
|
||||
print(" • EspoCRM-Änderungen gehen verloren")
|
||||
print(" • Nicht bidirektional")
|
||||
print(" • User könnten verärgert sein")
|
||||
|
||||
return email_data, phone_data
|
||||
|
||||
|
||||
async def test_hybrid_strategy():
|
||||
"""
|
||||
Strategie 3: Hybrid - Advoware Master + EspoCRM Ergänzungen
|
||||
|
||||
Idee:
|
||||
- Advoware-Kommunikationen sind primary=true (wichtig, geschützt)
|
||||
- EspoCRM kann zusätzliche Einträge mit primary=false hinzufügen
|
||||
- Nur Advoware-Einträge werden synchronisiert
|
||||
|
||||
Vorteile:
|
||||
- Flexibilität für EspoCRM-User
|
||||
- Advoware behält Kontrolle über wichtige Daten
|
||||
|
||||
Nachteile:
|
||||
- Komplexere Logik
|
||||
- Braucht Markierung (primary-Flag)
|
||||
"""
|
||||
print_section("STRATEGIE 3: Hybrid (Advoware Primary + EspoCRM Secondary)")
|
||||
|
||||
context = SimpleContext()
|
||||
espo = EspoCRMAPI(context)
|
||||
advo = AdvowareAPI(context)
|
||||
|
||||
# Hole Daten
|
||||
espo_entity = await espo.get_entity('CBeteiligte', TEST_BETEILIGTE_ID)
|
||||
advo_entity = await advo.api_call(f'api/v1/advonet/Beteiligte/{TEST_ADVOWARE_BETNR}')
|
||||
|
||||
advo_komm = advo_entity.get('kommunikation', [])
|
||||
espo_emails = espo_entity.get('emailAddressData', [])
|
||||
|
||||
print("\n📋 Regel:")
|
||||
print(" • primary=true → Kommt von Advoware (synchronisiert)")
|
||||
print(" • primary=false → Nur in EspoCRM (wird NICHT zu Advoware)")
|
||||
|
||||
print("\n📧 Aktuelle EspoCRM Emails:")
|
||||
for e in espo_emails:
|
||||
source = "Advoware" if e.get('primary') else "EspoCRM"
|
||||
print(f" • {e['emailAddress']:40s} primary={e.get('primary')} → {source}")
|
||||
|
||||
print("\n🔄 Sync-Logik:")
|
||||
print(" 1. Hole Advoware Kommunikationen")
|
||||
print(" 2. Konvertiere zu EspoCRM (mit primary=true)")
|
||||
print(" 3. Hole aktuelle EspoCRM Einträge mit primary=false")
|
||||
print(" 4. Merge: Advoware (primary) + EspoCRM (secondary)")
|
||||
print(" 5. UPDATE CBeteiligte mit gemergtem Array")
|
||||
|
||||
# Simulation
|
||||
advo_emails = [k for k in advo_komm if k.get('kommKz') in [4, 8, 11]]
|
||||
|
||||
merged_emails = []
|
||||
|
||||
# Von Advoware (primary=true)
|
||||
for k in advo_emails:
|
||||
merged_emails.append({
|
||||
'emailAddress': k.get('tlf', ''),
|
||||
'lower': k.get('tlf', '').lower(),
|
||||
'primary': True, # Immer primary für Advoware
|
||||
'optOut': False,
|
||||
'invalid': False
|
||||
})
|
||||
|
||||
# Von EspoCRM (nur non-primary behalten)
|
||||
for e in espo_emails:
|
||||
if not e.get('primary', False):
|
||||
merged_emails.append(e)
|
||||
|
||||
print(f"\n📊 Merge-Ergebnis: {len(merged_emails)} Emails")
|
||||
for e in merged_emails:
|
||||
source = "Advoware" if e.get('primary') else "EspoCRM"
|
||||
print(f" • {e['emailAddress']:40s} [{source}]")
|
||||
|
||||
print("\n✅ Vorteile:")
|
||||
print(" • Advoware behält Kontrolle")
|
||||
print(" • EspoCRM-User können ergänzen")
|
||||
print(" • Kein Datenverlust")
|
||||
|
||||
print("\n⚠️ Einschränkungen:")
|
||||
print(" • EspoCRM kann Advoware-Daten NICHT ändern")
|
||||
print(" • primary-Flag muss geschützt werden")
|
||||
|
||||
return merged_emails
|
||||
|
||||
|
||||
async def test_bemerkung_tracking():
|
||||
"""
|
||||
Strategie 4: Tracking via bemerkung-Feld
|
||||
|
||||
Idee: Speichere Advoware-ID in bemerkung
|
||||
|
||||
Format: "Advoware-ID: 149331 | Tatsächliche Bemerkung"
|
||||
|
||||
Vorteile:
|
||||
- Stabiles Matching möglich
|
||||
- Kann Änderungen tracken
|
||||
|
||||
Nachteile:
|
||||
- bemerkung-Feld wird "verschmutzt"
|
||||
- User sichtbar
|
||||
- Fragil (User könnte löschen)
|
||||
"""
|
||||
print_section("STRATEGIE 4: Tracking via bemerkung-Feld")
|
||||
|
||||
context = SimpleContext()
|
||||
advo = AdvowareAPI(context)
|
||||
|
||||
advo_entity = await advo.api_call(f'api/v1/advonet/Beteiligte/{TEST_ADVOWARE_BETNR}')
|
||||
advo_komm = advo_entity.get('kommunikation', [])
|
||||
|
||||
print("\n⚠️ PROBLEM: EspoCRM emailAddressData/phoneNumberData haben KEIN bemerkung-Feld!")
|
||||
print("\nStruktur emailAddressData:")
|
||||
print(" {")
|
||||
print(" 'emailAddress': 'max@example.com',")
|
||||
print(" 'lower': 'max@example.com',")
|
||||
print(" 'primary': true,")
|
||||
print(" 'optOut': false,")
|
||||
print(" 'invalid': false")
|
||||
print(" }")
|
||||
print("\n ❌ Kein 'bemerkung' oder 'notes' Feld verfügbar")
|
||||
print(" ❌ Kein Custom-Feld möglich in Standard-Arrays")
|
||||
|
||||
print("\n📋 Alternative: Advoware bemerkung nutzen")
|
||||
print(" → Speichere EspoCRM-Wert in Advoware bemerkung")
|
||||
|
||||
for k in advo_komm[:3]: # Erste 3 als Beispiel
|
||||
advo_id = k.get('id')
|
||||
wert = k.get('tlf', '')
|
||||
bemerkung = k.get('bemerkung', '')
|
||||
|
||||
print(f"\n Advoware ID {advo_id}:")
|
||||
print(f" Wert: {wert}")
|
||||
print(f" Bemerkung: {bemerkung or '(leer)'}")
|
||||
print(f" → Neue Bemerkung: 'EspoCRM: {wert} | {bemerkung}'")
|
||||
|
||||
print("\n✅ Matching-Strategie:")
|
||||
print(" 1. Parse bemerkung: Extrahiere 'EspoCRM: <wert>'")
|
||||
print(" 2. Matche Advoware ↔ EspoCRM via Wert in bemerkung")
|
||||
print(" 3. Wenn Wert ändert: Update bemerkung")
|
||||
|
||||
print("\n❌ Nachteile:")
|
||||
print(" • bemerkung für User sichtbar und änderbar")
|
||||
print(" • Fragil wenn User bemerkung bearbeitet")
|
||||
print(" • Komplexe Parse-Logik")
|
||||
|
||||
|
||||
async def main():
|
||||
print("\n" + "="*70)
|
||||
print("KOMMUNIKATION MATCHING-STRATEGIEN OHNE ID")
|
||||
print("="*70)
|
||||
|
||||
try:
|
||||
# Test alle Strategien
|
||||
await test_value_based_matching()
|
||||
await test_advoware_master_sync()
|
||||
await test_hybrid_strategy()
|
||||
await test_bemerkung_tracking()
|
||||
|
||||
print_section("EMPFEHLUNG")
|
||||
|
||||
print("\n🎯 BESTE LÖSUNG: Strategie 3 (Hybrid)")
|
||||
print("\n✅ Begründung:")
|
||||
print(" 1. Advoware behält Kontrolle (primary=true)")
|
||||
print(" 2. EspoCRM kann ergänzen (primary=false)")
|
||||
print(" 3. Einfach zu implementieren")
|
||||
print(" 4. Kein Datenverlust")
|
||||
print(" 5. primary-Flag ist Standard in EspoCRM")
|
||||
|
||||
print("\n📋 Implementation:")
|
||||
print(" • Advoware → EspoCRM: Setze primary=true")
|
||||
print(" • EspoCRM → Advoware: Ignoriere primary=false Einträge")
|
||||
print(" • Matching: Via Wert (emailAddress/phoneNumber)")
|
||||
print(" • Change Detection: rowId in Advoware (wie bei Adressen)")
|
||||
|
||||
print("\n🔄 Sync-Ablauf:")
|
||||
print(" 1. Webhook von Advoware")
|
||||
print(" 2. Lade Advoware Kommunikationen")
|
||||
print(" 3. Filter: Nur Typen die EspoCRM unterstützt")
|
||||
print(" 4. Konvertiere zu emailAddressData/phoneNumberData")
|
||||
print(" 5. Setze primary=true für alle")
|
||||
print(" 6. Merge mit bestehenden primary=false Einträgen")
|
||||
print(" 7. UPDATE CBeteiligte")
|
||||
|
||||
print("\n⚠️ Einschränkungen akzeptiert:")
|
||||
print(" • EspoCRM → Advoware: Nur primary=false Einträge")
|
||||
print(" • Keine bidirektionale Sync für Wert-Änderungen")
|
||||
print(" • Bei Wert-Änderung: Neuanlage statt Update")
|
||||
|
||||
except Exception as e:
|
||||
print(f"\n❌ Fehler: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
@@ -0,0 +1,350 @@
|
||||
"""
|
||||
Detaillierte Analyse: Welche Felder sind bei PUT änderbar?
|
||||
|
||||
Basierend auf ersten Tests:
|
||||
- POST funktioniert (alle 4 Felder)
|
||||
- PUT funktioniert TEILWEISE
|
||||
- DELETE = 403 Forbidden (wie bei Adressen/Bankverbindungen)
|
||||
|
||||
Felder laut Swagger:
|
||||
- tlf (string, nullable)
|
||||
- bemerkung (string, nullable)
|
||||
- kommKz (enum/int)
|
||||
- online (boolean)
|
||||
|
||||
Response enthält zusätzlich:
|
||||
- id (int) - Kommunikations-ID
|
||||
- betNr (int) - Beteiligten-ID
|
||||
- kommArt (int) - Scheint von kommKz generiert zu werden
|
||||
- rowId (string) - Änderungserkennung
|
||||
"""
|
||||
|
||||
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_field_mutability():
|
||||
"""Teste welche Felder bei PUT änderbar sind"""
|
||||
|
||||
context = SimpleContext()
|
||||
advo = AdvowareAPI(context)
|
||||
|
||||
# STEP 1: Erstelle Test-Kommunikation
|
||||
print_section("STEP 1: Erstelle Test-Kommunikation")
|
||||
|
||||
create_data = {
|
||||
'kommKz': 1, # TelGesch
|
||||
'tlf': '+49 511 000000-00',
|
||||
'bemerkung': 'TEST-READONLY: Initial',
|
||||
'online': False
|
||||
}
|
||||
|
||||
print(f"📤 POST Data: {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) and len(result) > 0:
|
||||
created = result[0]
|
||||
else:
|
||||
created = result
|
||||
|
||||
komm_id = created['id']
|
||||
original_rowid = created['rowId']
|
||||
|
||||
print(f"\n✅ Erstellt:")
|
||||
print(f" ID: {komm_id}")
|
||||
print(f" rowId: {original_rowid}")
|
||||
print(f" kommArt: {created['kommArt']}")
|
||||
print(f"\n📋 Vollständige Response:")
|
||||
print(json.dumps(created, indent=2, ensure_ascii=False))
|
||||
|
||||
# STEP 2: Teste jedes Feld einzeln
|
||||
print_section("STEP 2: Teste Feld-Änderbarkeit")
|
||||
|
||||
test_results = {}
|
||||
|
||||
# Test 1: tlf
|
||||
print("\n🔬 Test 1/4: tlf (Telefonnummer/Email)")
|
||||
print(" Änderung: '+49 511 000000-00' → '+49 511 111111-11'")
|
||||
|
||||
test_data = {
|
||||
'kommKz': created['kommKz'],
|
||||
'tlf': '+49 511 111111-11', # GEÄNDERT
|
||||
'bemerkung': created['bemerkung'],
|
||||
'online': created['online']
|
||||
}
|
||||
|
||||
try:
|
||||
result = await advo.api_call(
|
||||
f'api/v1/advonet/Beteiligte/{TEST_BETNR}/Kommunikationen/{komm_id}',
|
||||
method='PUT',
|
||||
data=test_data
|
||||
)
|
||||
|
||||
new_rowid = result['rowId']
|
||||
rowid_changed = (new_rowid != original_rowid)
|
||||
value_changed = (result['tlf'] == '+49 511 111111-11')
|
||||
|
||||
print(f" ✅ PUT erfolgreich")
|
||||
print(f" 📊 Wert geändert: {value_changed}")
|
||||
print(f" 📊 rowId geändert: {rowid_changed}")
|
||||
print(f" Alt: {original_rowid}")
|
||||
print(f" Neu: {new_rowid}")
|
||||
|
||||
test_results['tlf'] = {
|
||||
'writable': value_changed,
|
||||
'rowid_changed': rowid_changed,
|
||||
'status': 'WRITABLE' if value_changed else 'READ-ONLY'
|
||||
}
|
||||
|
||||
original_rowid = new_rowid # Update für nächsten Test
|
||||
|
||||
except Exception as e:
|
||||
print(f" ❌ FEHLER: {e}")
|
||||
test_results['tlf'] = {'writable': False, 'status': 'ERROR', 'error': str(e)}
|
||||
|
||||
# Test 2: bemerkung
|
||||
print("\n🔬 Test 2/4: bemerkung")
|
||||
print(" Änderung: 'TEST-READONLY: Initial' → 'TEST-READONLY: Modified'")
|
||||
|
||||
test_data = {
|
||||
'kommKz': created['kommKz'],
|
||||
'tlf': result['tlf'], # Aktueller Wert
|
||||
'bemerkung': 'TEST-READONLY: Modified', # GEÄNDERT
|
||||
'online': result['online']
|
||||
}
|
||||
|
||||
try:
|
||||
result = await advo.api_call(
|
||||
f'api/v1/advonet/Beteiligte/{TEST_BETNR}/Kommunikationen/{komm_id}',
|
||||
method='PUT',
|
||||
data=test_data
|
||||
)
|
||||
|
||||
new_rowid = result['rowId']
|
||||
rowid_changed = (new_rowid != original_rowid)
|
||||
value_changed = (result['bemerkung'] == 'TEST-READONLY: Modified')
|
||||
|
||||
print(f" ✅ PUT erfolgreich")
|
||||
print(f" 📊 Wert geändert: {value_changed}")
|
||||
print(f" 📊 rowId geändert: {rowid_changed}")
|
||||
|
||||
test_results['bemerkung'] = {
|
||||
'writable': value_changed,
|
||||
'rowid_changed': rowid_changed,
|
||||
'status': 'WRITABLE' if value_changed else 'READ-ONLY'
|
||||
}
|
||||
|
||||
original_rowid = new_rowid
|
||||
|
||||
except Exception as e:
|
||||
print(f" ❌ FEHLER: {e}")
|
||||
test_results['bemerkung'] = {'writable': False, 'status': 'ERROR', 'error': str(e)}
|
||||
|
||||
# Test 3: kommKz
|
||||
print("\n🔬 Test 3/4: kommKz (Kommunikationstyp)")
|
||||
original_kommkz = result['kommKz']
|
||||
target_kommkz = 6
|
||||
print(f" Änderung: {original_kommkz} (TelGesch) → {target_kommkz} (TelPrivat)")
|
||||
|
||||
test_data = {
|
||||
'kommKz': target_kommkz, # GEÄNDERT
|
||||
'tlf': result['tlf'],
|
||||
'bemerkung': f"TEST-READONLY: Versuch kommKz {original_kommkz}→{target_kommkz}",
|
||||
'online': result['online']
|
||||
}
|
||||
|
||||
try:
|
||||
result = await advo.api_call(
|
||||
f'api/v1/advonet/Beteiligte/{TEST_BETNR}/Kommunikationen/{komm_id}',
|
||||
method='PUT',
|
||||
data=test_data
|
||||
)
|
||||
|
||||
new_rowid = result['rowId']
|
||||
rowid_changed = (new_rowid != original_rowid)
|
||||
value_changed = (result['kommKz'] == target_kommkz)
|
||||
|
||||
print(f" ✅ PUT erfolgreich")
|
||||
print(f" 📊 PUT Response kommKz: {result['kommKz']}")
|
||||
print(f" 📊 PUT Response kommArt: {result['kommArt']}")
|
||||
print(f" 📊 rowId geändert: {rowid_changed}")
|
||||
|
||||
# WICHTIG: Nachfolgender GET zur Verifizierung
|
||||
print(f"\n 🔍 Verifizierung via GET...")
|
||||
beteiligte_get = await advo.api_call(
|
||||
f'api/v1/advonet/Beteiligte/{TEST_BETNR}',
|
||||
method='GET'
|
||||
)
|
||||
|
||||
if isinstance(beteiligte_get, list):
|
||||
beteiligte_get = beteiligte_get[0]
|
||||
|
||||
kommunikationen_get = beteiligte_get.get('kommunikation', [])
|
||||
verify_komm = next((k for k in kommunikationen_get if k['id'] == komm_id), None)
|
||||
|
||||
if verify_komm:
|
||||
print(f" 📋 GET Response kommKz: {verify_komm['kommKz']}")
|
||||
print(f" 📋 GET Response kommArt: {verify_komm['kommArt']}")
|
||||
print(f" 📋 GET Response bemerkung: {verify_komm['bemerkung']}")
|
||||
|
||||
# Finale Bewertung basierend auf GET
|
||||
actual_value_changed = (verify_komm['kommKz'] == target_kommkz)
|
||||
|
||||
if actual_value_changed:
|
||||
print(f" ✅ BESTÄTIGT: kommKz wurde geändert auf {target_kommkz}")
|
||||
else:
|
||||
print(f" ❌ BESTÄTIGT: kommKz blieb bei {verify_komm['kommKz']} (nicht geändert!)")
|
||||
|
||||
test_results['kommKz'] = {
|
||||
'writable': actual_value_changed,
|
||||
'rowid_changed': rowid_changed,
|
||||
'status': 'WRITABLE' if actual_value_changed else 'READ-ONLY',
|
||||
'requested_value': target_kommkz,
|
||||
'put_response_value': result['kommKz'],
|
||||
'get_response_value': verify_komm['kommKz'],
|
||||
'note': f"PUT sagte: {result['kommKz']}, GET sagte: {verify_komm['kommKz']}"
|
||||
}
|
||||
else:
|
||||
print(f" ⚠️ Kommunikation nicht in GET gefunden")
|
||||
test_results['kommKz'] = {
|
||||
'writable': False,
|
||||
'status': 'ERROR',
|
||||
'error': 'Not found in GET'
|
||||
}
|
||||
|
||||
original_rowid = new_rowid
|
||||
|
||||
except Exception as e:
|
||||
print(f" ❌ FEHLER: {e}")
|
||||
test_results['kommKz'] = {'writable': False, 'status': 'ERROR', 'error': str(e)}
|
||||
|
||||
# Test 4: online
|
||||
print("\n🔬 Test 4/4: online (Boolean Flag)")
|
||||
print(" Änderung: False → True")
|
||||
|
||||
test_data = {
|
||||
'kommKz': result['kommKz'],
|
||||
'tlf': result['tlf'],
|
||||
'bemerkung': result['bemerkung'],
|
||||
'online': True # GEÄNDERT
|
||||
}
|
||||
|
||||
try:
|
||||
result = await advo.api_call(
|
||||
f'api/v1/advonet/Beteiligte/{TEST_BETNR}/Kommunikationen/{komm_id}',
|
||||
method='PUT',
|
||||
data=test_data
|
||||
)
|
||||
|
||||
new_rowid = result['rowId']
|
||||
rowid_changed = (new_rowid != original_rowid)
|
||||
value_changed = (result['online'] == True)
|
||||
|
||||
print(f" ✅ PUT erfolgreich")
|
||||
print(f" 📊 Wert geändert: {value_changed}")
|
||||
print(f" 📊 rowId geändert: {rowid_changed}")
|
||||
|
||||
test_results['online'] = {
|
||||
'writable': value_changed,
|
||||
'rowid_changed': rowid_changed,
|
||||
'status': 'WRITABLE' if value_changed else 'READ-ONLY'
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
print(f" ❌ FEHLER: {e}")
|
||||
test_results['online'] = {'writable': False, 'status': 'ERROR', 'error': str(e)}
|
||||
|
||||
# ZUSAMMENFASSUNG
|
||||
print_section("ZUSAMMENFASSUNG: Feld-Status")
|
||||
|
||||
print("\n📊 Ergebnisse:\n")
|
||||
|
||||
for field, result in test_results.items():
|
||||
status = result['status']
|
||||
icon = "✅" if status == "WRITABLE" else "❌" if status == "READ-ONLY" else "⚠️"
|
||||
|
||||
print(f" {icon} {field:15s} → {status}")
|
||||
|
||||
if result.get('note'):
|
||||
print(f" ℹ️ {result['note']}")
|
||||
|
||||
if result.get('error'):
|
||||
print(f" ⚠️ {result['error']}")
|
||||
|
||||
# Count
|
||||
writable = sum(1 for r in test_results.values() if r['status'] == 'WRITABLE')
|
||||
readonly = sum(1 for r in test_results.values() if r['status'] == 'READ-ONLY')
|
||||
|
||||
print(f"\n📈 Statistik:")
|
||||
print(f" WRITABLE: {writable}/{len(test_results)} Felder")
|
||||
print(f" READ-ONLY: {readonly}/{len(test_results)} Felder")
|
||||
|
||||
print(f"\n⚠️ Test-Kommunikation {komm_id} manuell löschen!")
|
||||
print(f" BetNr: {TEST_BETNR}")
|
||||
|
||||
return test_results
|
||||
|
||||
|
||||
async def main():
|
||||
print("\n" + "="*70)
|
||||
print("KOMMUNIKATION API - FELDANALYSE")
|
||||
print("="*70)
|
||||
print("\nZiel: Herausfinden welche Felder bei PUT änderbar sind")
|
||||
print("Methode: Einzelne Feldänderungen + rowId-Tracking\n")
|
||||
|
||||
try:
|
||||
results = await test_field_mutability()
|
||||
|
||||
print_section("EMPFEHLUNG FÜR MAPPER")
|
||||
|
||||
writable_fields = [f for f, r in results.items() if r['status'] == 'WRITABLE']
|
||||
readonly_fields = [f for f, r in results.items() if r['status'] == 'READ-ONLY']
|
||||
|
||||
if writable_fields:
|
||||
print("\n✅ Für UPDATE (PUT) verwenden:")
|
||||
for field in writable_fields:
|
||||
print(f" - {field}")
|
||||
|
||||
if readonly_fields:
|
||||
print("\n❌ NUR bei CREATE (POST) verwenden:")
|
||||
for field in readonly_fields:
|
||||
print(f" - {field}")
|
||||
|
||||
print("\n💡 Sync-Strategie:")
|
||||
print(" - CREATE: Alle Felder")
|
||||
print(" - UPDATE: Nur WRITABLE Felder")
|
||||
print(" - DELETE: Notification (403 Forbidden)")
|
||||
|
||||
except Exception as e:
|
||||
print(f"\n❌ Fehler: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
asyncio.run(main())
|
||||
@@ -0,0 +1,255 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Test Kommunikation Sync Implementation
|
||||
Testet alle 4 Szenarien + Type Detection
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
||||
|
||||
from services.kommunikation_mapper import (
|
||||
encode_value, decode_value, parse_marker, create_marker, create_slot_marker,
|
||||
detect_kommkz, is_email_type, is_phone_type,
|
||||
KOMMKZ_TEL_GESCH, KOMMKZ_MAIL_GESCH
|
||||
)
|
||||
|
||||
|
||||
def test_base64_encoding():
|
||||
"""Test: Base64-Encoding/Decoding"""
|
||||
print("\n=== TEST 1: Base64-Encoding/Decoding ===")
|
||||
|
||||
# Email
|
||||
value1 = "max@example.com"
|
||||
encoded1 = encode_value(value1)
|
||||
decoded1 = decode_value(encoded1)
|
||||
print(f"✓ Email: '{value1}' → '{encoded1}' → '{decoded1}'")
|
||||
assert decoded1 == value1, "Decode muss Original ergeben"
|
||||
|
||||
# Phone
|
||||
value2 = "+49 170 999-TEST"
|
||||
encoded2 = encode_value(value2)
|
||||
decoded2 = decode_value(encoded2)
|
||||
print(f"✓ Phone: '{value2}' → '{encoded2}' → '{decoded2}'")
|
||||
assert decoded2 == value2, "Decode muss Original ergeben"
|
||||
|
||||
# Special characters
|
||||
value3 = "test:special]@example.com"
|
||||
encoded3 = encode_value(value3)
|
||||
decoded3 = decode_value(encoded3)
|
||||
print(f"✓ Special: '{value3}' → '{encoded3}' → '{decoded3}'")
|
||||
assert decoded3 == value3, "Decode muss Original ergeben"
|
||||
|
||||
print("✅ Base64-Encoding bidirektional funktioniert")
|
||||
|
||||
|
||||
def test_marker_parsing():
|
||||
"""Test: Marker-Parsing mit Base64"""
|
||||
print("\n=== TEST 2: Marker-Parsing ===")
|
||||
|
||||
# Standard Marker mit Base64
|
||||
value = "max@example.com"
|
||||
encoded = encode_value(value)
|
||||
bemerkung1 = f"[ESPOCRM:{encoded}:4] Geschäftlich"
|
||||
marker1 = parse_marker(bemerkung1)
|
||||
print(f"✓ Parsed: {marker1}")
|
||||
assert marker1['synced_value'] == value
|
||||
assert marker1['kommKz'] == 4
|
||||
assert marker1['is_slot'] == False
|
||||
assert marker1['user_text'] == 'Geschäftlich'
|
||||
print("✅ Standard-Marker OK")
|
||||
|
||||
# Slot Marker
|
||||
bemerkung2 = "[ESPOCRM-SLOT:1]"
|
||||
marker2 = parse_marker(bemerkung2)
|
||||
print(f"✓ Parsed Slot: {marker2}")
|
||||
assert marker2['is_slot'] == True
|
||||
assert marker2['kommKz'] == 1
|
||||
print("✅ Slot-Marker OK")
|
||||
|
||||
# Kein Marker
|
||||
bemerkung3 = "Nur normale Bemerkung"
|
||||
marker3 = parse_marker(bemerkung3)
|
||||
assert marker3 is None
|
||||
print("✅ Nicht-Marker erkannt")
|
||||
|
||||
|
||||
def test_marker_creation():
|
||||
"""Test: Marker-Erstellung mit Base64"""
|
||||
print("\n=== TEST 3: Marker-Erstellung ===")
|
||||
|
||||
value = "max@example.com"
|
||||
kommkz = 4
|
||||
user_text = "Geschäftlich"
|
||||
|
||||
marker = create_marker(value, kommkz, user_text)
|
||||
print(f"✓ Created Marker: {marker}")
|
||||
|
||||
# Verify parsable
|
||||
parsed = parse_marker(marker)
|
||||
assert parsed is not None
|
||||
assert parsed['synced_value'] == value
|
||||
assert parsed['kommKz'] == kommkz
|
||||
assert parsed['user_text'] == user_text
|
||||
print("✅ Marker korrekt erstellt und parsbar")
|
||||
|
||||
# Slot Marker
|
||||
slot_marker = create_slot_marker(kommkz)
|
||||
print(f"✓ Created Slot: {slot_marker}")
|
||||
parsed_slot = parse_marker(slot_marker)
|
||||
assert parsed_slot['is_slot'] == True
|
||||
print("✅ Slot-Marker OK")
|
||||
|
||||
|
||||
def test_type_detection_4_tiers():
|
||||
"""Test: 4-Stufen Typ-Erkennung"""
|
||||
print("\n=== TEST 4: 4-Stufen Typ-Erkennung ===")
|
||||
|
||||
# TIER 1: Aus Marker (höchste Priorität)
|
||||
value = "test@example.com"
|
||||
bemerkung_with_marker = "[ESPOCRM:abc:3]" # Marker sagt Mobil (3)
|
||||
beteiligte = {'emailGesch': value} # Top-Level sagt MailGesch (4)
|
||||
|
||||
detected = detect_kommkz(value, beteiligte, bemerkung_with_marker)
|
||||
print(f"✓ Tier 1 (Marker): {detected} (erwartet 3 = Mobil)")
|
||||
assert detected == 3, "Marker sollte höchste Priorität haben"
|
||||
print("✅ Tier 1 OK - Marker überschreibt alles")
|
||||
|
||||
# TIER 2: Aus Top-Level Feldern
|
||||
beteiligte = {'telGesch': '+49 123 456'}
|
||||
detected = detect_kommkz('+49 123 456', beteiligte, None)
|
||||
print(f"✓ Tier 2 (Top-Level): {detected} (erwartet 1 = TelGesch)")
|
||||
assert detected == 1
|
||||
print("✅ Tier 2 OK - Top-Level Match")
|
||||
|
||||
# TIER 3: Aus Wert-Pattern
|
||||
email_value = "no-marker@example.com"
|
||||
detected = detect_kommkz(email_value, {}, None)
|
||||
print(f"✓ Tier 3 (Pattern @ = Email): {detected} (erwartet 4)")
|
||||
assert detected == 4
|
||||
print("✅ Tier 3 OK - Email erkannt")
|
||||
|
||||
phone_value = "+49 123"
|
||||
detected = detect_kommkz(phone_value, {}, None)
|
||||
print(f"✓ Tier 3 (Pattern Phone): {detected} (erwartet 1)")
|
||||
assert detected == 1
|
||||
print("✅ Tier 3 OK - Phone erkannt")
|
||||
|
||||
# TIER 4: Default
|
||||
detected = detect_kommkz('', {}, None)
|
||||
print(f"✓ Tier 4 (Default): {detected} (erwartet 0)")
|
||||
assert detected == 0
|
||||
print("✅ Tier 4 OK - Default bei leerem Wert")
|
||||
|
||||
|
||||
def test_type_classification():
|
||||
"""Test: Email vs. Phone Klassifizierung"""
|
||||
print("\n=== TEST 5: Typ-Klassifizierung ===")
|
||||
|
||||
email_types = [4, 8, 11, 12] # MailGesch, MailPrivat, EPost, Bea
|
||||
phone_types = [1, 2, 3, 6, 7, 9, 10] # Alle Telefon-Typen
|
||||
|
||||
for kommkz in email_types:
|
||||
assert is_email_type(kommkz), f"kommKz {kommkz} sollte Email sein"
|
||||
assert not is_phone_type(kommkz), f"kommKz {kommkz} sollte nicht Phone sein"
|
||||
print(f"✅ Email-Typen: {email_types}")
|
||||
|
||||
for kommkz in phone_types:
|
||||
assert is_phone_type(kommkz), f"kommKz {kommkz} sollte Phone sein"
|
||||
assert not is_email_type(kommkz), f"kommKz {kommkz} sollte nicht Email sein"
|
||||
print(f"✅ Phone-Typen: {phone_types}")
|
||||
|
||||
|
||||
def test_integration_scenario():
|
||||
"""Test: Integration Szenario mit Base64"""
|
||||
print("\n=== TEST 6: Integration Szenario ===")
|
||||
|
||||
# Szenario: Neue Email in EspoCRM
|
||||
espo_email = "new@example.com"
|
||||
|
||||
# Schritt 1: Erkenne Typ (kein Marker, keine Top-Level Match)
|
||||
kommkz = detect_kommkz(espo_email, {}, None)
|
||||
print(f"✓ Erkannte kommKz: {kommkz} (MailGesch)")
|
||||
assert kommkz == 4
|
||||
|
||||
# Schritt 2: Erstelle Marker mit Base64
|
||||
marker = create_marker(espo_email, kommkz)
|
||||
print(f"✓ Marker erstellt: {marker}")
|
||||
|
||||
# Schritt 3: Simuliere späteren Lookup
|
||||
parsed = parse_marker(marker)
|
||||
assert parsed['synced_value'] == espo_email
|
||||
print(f"✓ Value-Match: {parsed['synced_value']}")
|
||||
|
||||
# Schritt 4: Simuliere Änderung in Advoware
|
||||
# User ändert zu "changed@example.com" aber Marker bleibt
|
||||
# → synced_value enthält noch "new@example.com" für Matching!
|
||||
old_synced_value = parsed['synced_value']
|
||||
new_value = "changed@example.com"
|
||||
|
||||
print(f"✓ Änderung erkannt: synced_value='{old_synced_value}' vs current='{new_value}'")
|
||||
assert old_synced_value != new_value
|
||||
|
||||
# Schritt 5: Nach Sync wird Marker aktualisiert
|
||||
new_marker = create_marker(new_value, kommkz, "Geschäftlich")
|
||||
print(f"✓ Neuer Marker nach Änderung: {new_marker}")
|
||||
|
||||
# Verify User-Text erhalten
|
||||
assert "Geschäftlich" in new_marker
|
||||
new_parsed = parse_marker(new_marker)
|
||||
assert new_parsed['synced_value'] == new_value
|
||||
print("✅ Integration Szenario mit bidirektionalem Matching erfolgreich")
|
||||
|
||||
|
||||
def test_top_level_priority():
|
||||
"""Test: Top-Level Feld Priorität"""
|
||||
print("\n=== TEST 7: Top-Level Feld Priorität ===")
|
||||
|
||||
# Value matched mit Top-Level Feld
|
||||
value = "+49 170 999-TEST"
|
||||
beteiligte = {
|
||||
'telGesch': '+49 511 111-11',
|
||||
'mobil': '+49 170 999-TEST', # Match!
|
||||
'emailGesch': 'test@example.com'
|
||||
}
|
||||
|
||||
detected = detect_kommkz(value, beteiligte, None)
|
||||
print(f"✓ Detected für '{value}': {detected}")
|
||||
print(f" Beteiligte Top-Level: telGesch={beteiligte['telGesch']}, mobil={beteiligte['mobil']}")
|
||||
assert detected == 3, "Sollte Mobil (3) erkennen via Top-Level Match"
|
||||
print("✅ Top-Level Match funktioniert")
|
||||
|
||||
# Kein Match → Fallback zu Pattern
|
||||
value2 = "+49 999 UNKNOWN"
|
||||
detected2 = detect_kommkz(value2, beteiligte, None)
|
||||
print(f"✓ Detected für '{value2}' (kein Match): {detected2}")
|
||||
assert detected2 == 1, "Sollte TelGesch (1) als Pattern-Fallback nehmen"
|
||||
print("✅ base64_encodingern funktioniert")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print("=" * 60)
|
||||
print("KOMMUNIKATION SYNC - IMPLEMENTATION TESTS")
|
||||
print("=" * 60)
|
||||
|
||||
try:
|
||||
test_base64_encoding()
|
||||
test_marker_parsing()
|
||||
test_marker_creation()
|
||||
test_type_detection_4_tiers()
|
||||
test_type_classification()
|
||||
test_integration_scenario()
|
||||
test_top_level_priority()
|
||||
|
||||
print("\n" + "=" * 60)
|
||||
print("✅ ALLE TESTS ERFOLGREICH")
|
||||
print("=" * 60)
|
||||
|
||||
except AssertionError as e:
|
||||
print(f"\n❌ TEST FAILED: {e}")
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
print(f"\n❌ ERROR: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
sys.exit(1)
|
||||
@@ -0,0 +1,108 @@
|
||||
"""
|
||||
Verifikation: Hat Advoware eindeutige IDs für Kommunikationen?
|
||||
|
||||
Prüfe:
|
||||
1. Hat jede Kommunikation eine 'id'?
|
||||
2. Sind die IDs eindeutig?
|
||||
3. Bleibt die ID stabil bei UPDATE?
|
||||
4. Was ist mit rowId?
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
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): pass
|
||||
|
||||
def __init__(self):
|
||||
self.logger = self.Logger()
|
||||
|
||||
|
||||
def print_section(title):
|
||||
print("\n" + "="*70)
|
||||
print(title)
|
||||
print("="*70)
|
||||
|
||||
|
||||
async def main():
|
||||
print("\n" + "="*70)
|
||||
print("ADVOWARE KOMMUNIKATION IDs")
|
||||
print("="*70)
|
||||
|
||||
context = SimpleContext()
|
||||
advo = AdvowareAPI(context)
|
||||
|
||||
# Hole Beteiligte mit Kommunikationen
|
||||
print_section("Aktuelle Kommunikationen")
|
||||
|
||||
result = await advo.api_call(f'api/v1/advonet/Beteiligte/{TEST_BETNR}')
|
||||
beteiligte = result[0]
|
||||
kommunikationen = beteiligte.get('kommunikation', [])
|
||||
|
||||
print(f"\n✅ {len(kommunikationen)} Kommunikationen gefunden\n")
|
||||
|
||||
# Zeige alle IDs
|
||||
ids = []
|
||||
row_ids = []
|
||||
|
||||
for i, k in enumerate(kommunikationen[:10], 1): # Erste 10
|
||||
komm_id = k.get('id')
|
||||
row_id = k.get('rowId')
|
||||
wert = k.get('tlf', '')[:40]
|
||||
kommkz = k.get('kommKz')
|
||||
|
||||
ids.append(komm_id)
|
||||
row_ids.append(row_id)
|
||||
|
||||
print(f"[{i:2d}] ID: {komm_id:8d} | rowId: {row_id:20s} | "
|
||||
f"Typ: {kommkz:2d} | Wert: {wert}")
|
||||
|
||||
# Analyse
|
||||
print_section("ANALYSE")
|
||||
|
||||
print(f"\n1️⃣ IDs vorhanden:")
|
||||
print(f" • Alle haben 'id': {all(k.get('id') for k in kommunikationen)}")
|
||||
print(f" • Alle haben 'rowId': {all(k.get('rowId') for k in kommunikationen)}")
|
||||
|
||||
print(f"\n2️⃣ Eindeutigkeit:")
|
||||
print(f" • Anzahl IDs: {len(ids)}")
|
||||
print(f" • Anzahl unique IDs: {len(set(ids))}")
|
||||
print(f" • ✅ IDs sind eindeutig: {len(ids) == len(set(ids))}")
|
||||
|
||||
print(f"\n3️⃣ ID-Typ:")
|
||||
print(f" • Beispiel-ID: {ids[0] if ids else 'N/A'}")
|
||||
print(f" • Typ: {type(ids[0]).__name__ if ids else 'N/A'}")
|
||||
print(f" • Format: Integer (stabil)")
|
||||
|
||||
print(f"\n4️⃣ rowId-Typ:")
|
||||
print(f" • Beispiel-rowId: {row_ids[0] if row_ids else 'N/A'}")
|
||||
print(f" • Typ: {type(row_ids[0]).__name__ if row_ids else 'N/A'}")
|
||||
print(f" • Format: Base64 String (ändert sich bei UPDATE)")
|
||||
|
||||
print_section("FAZIT")
|
||||
|
||||
print("\n✅ Advoware hat EINDEUTIGE IDs für Kommunikationen!")
|
||||
print("\n📋 Eigenschaften:")
|
||||
print(" • id: Integer, stabil, eindeutig")
|
||||
print(" • rowId: String, ändert sich bei UPDATE (für Change Detection)")
|
||||
|
||||
print("\n💡 Das bedeutet:")
|
||||
print(" • Wir können Advoware-ID als Schlüssel nutzen")
|
||||
print(" • Matching: Advoware-ID ↔ EspoCRM-Wert")
|
||||
print(" • Speichere Advoware-ID irgendwo für Reverse-Lookup")
|
||||
|
||||
print("\n🎯 BESSERE LÖSUNG:")
|
||||
print(" Option D: Advoware-ID als Kommentar in bemerkung speichern?")
|
||||
print(" Option E: Advoware-ID in Wert-Format kodieren?")
|
||||
print(" Option F: Separate Mapping-Tabelle (Redis/DB)?")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
Reference in New Issue
Block a user