feat(company-explorer-integration): Implement Company Explorer Connector and Lead Engine Sync [2f988f42]\n\nIntegrates the Company Explorer API into the Lead Engine workflow, allowing for robust company existence checks, creation, and asynchronous enrichment.\n\n- Introduced as a central client wrapper for the Company Explorer API, handling find-or-create logic, discovery, polling for website data, and analysis triggers.\n- Updated to utilize the new connector for syncing new leads with the Company Explorer.\n- Added for comprehensive unit testing of the connector logic.\n- Created as a demonstration script for the end-to-end integration.\n- Updated to document the new client integration architecture pattern.\n\nThis enhances the Lead Engine with a reliable mechanism for company data enrichment.

This commit is contained in:
2026-02-01 19:55:12 +00:00
parent da9f0d1edd
commit 8894f086c9
5 changed files with 385 additions and 220 deletions

View File

@@ -0,0 +1,98 @@
import unittest
from unittest.mock import patch, MagicMock
import os
import requests
# Den Pfad anpassen, damit das Modul gefunden wird
import sys
sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))
from check_company_existence import check_company_existence_with_company_explorer
class TestCompanyExistenceChecker(unittest.TestCase):
@patch('check_company_existence.requests.get')
def test_company_exists_exact_match(self, mock_get):
"""Testet, ob ein exakt passendes Unternehmen korrekt als 'existent' erkannt wird."""
mock_response = MagicMock()
mock_response.status_code = 200
mock_response.json.return_value = {
"total": 1,
"items": [
{"id": 123, "name": "TestCorp"}
]
}
mock_get.return_value = mock_response
result = check_company_existence_with_company_explorer("TestCorp")
self.assertTrue(result["exists"])
self.assertEqual(result["company_id"], 123)
self.assertEqual(result["company_name"], "TestCorp")
@patch('check_company_existence.requests.get')
def test_company_does_not_exist(self, mock_get):
"""Testet, ob ein nicht existentes Unternehmen korrekt als 'nicht existent' erkannt wird."""
mock_response = MagicMock()
mock_response.status_code = 200
mock_response.json.return_value = {"total": 0, "items": []}
mock_get.return_value = mock_response
result = check_company_existence_with_company_explorer("NonExistentCorp")
self.assertFalse(result["exists"])
self.assertIn("not found", result["message"])
@patch('check_company_existence.requests.get')
def test_company_partial_match_only(self, mock_get):
"""Testet den Fall, in dem die Suche Ergebnisse liefert, aber kein exakter Match dabei ist."""
mock_response = MagicMock()
mock_response.status_code = 200
mock_response.json.return_value = {
"total": 1,
"items": [
{"id": 124, "name": "TestCorp Inc"}
]
}
mock_get.return_value = mock_response
result = check_company_existence_with_company_explorer("TestCorp")
self.assertFalse(result["exists"])
self.assertIn("not found as an exact match", result["message"])
@patch('check_company_existence.requests.get')
def test_http_error_handling(self, mock_get):
"""Testet das Fehlerhandling bei einem HTTP 401 Unauthorized Error."""
# Importiere requests innerhalb des Test-Scopes, um den side_effect zu verwenden
import requests
mock_response = MagicMock()
mock_response.status_code = 401
mock_response.text = "Unauthorized"
# Die raise_for_status Methode muss eine Ausnahme auslösen
mock_response.raise_for_status.side_effect = requests.exceptions.HTTPError("401 Client Error: Unauthorized for url")
mock_get.return_value = mock_response
result = check_company_existence_with_company_explorer("AnyCompany")
self.assertFalse(result["exists"])
self.assertIn("HTTP error occurred", result["error"])
@patch('check_company_existence.requests.get')
def test_connection_error_handling(self, mock_get):
"""Testet das Fehlerhandling bei einem Connection Error."""
# Importiere requests hier, damit die Ausnahme im Patch-Kontext ist
import requests
mock_get.side_effect = requests.exceptions.ConnectionError("Connection failed")
result = check_company_existence_with_company_explorer("AnyCompany")
self.assertFalse(result["exists"])
self.assertIn("Connection error occurred", result["error"])
if __name__ == '__main__':
# Füge 'requests' zum globalen Scope hinzu, damit es im Test-HTTP-Error-Handling-Test verwendet werden kann
import requests
unittest.main(argv=['first-arg-is-ignored'], exit=False)