|
37 | 37 | )
|
38 | 38 | from port_ocean.core.integrations.mixins.live_events import LiveEventsMixin
|
39 | 39 | from port_ocean.core.models import Entity
|
40 |
| -from port_ocean.exceptions.webhook_processor import RetryableError |
| 40 | +from port_ocean.exceptions.webhook_processor import ( |
| 41 | + RetryableError, |
| 42 | + WebhookEventNotSupportedError, |
| 43 | +) |
41 | 44 | from port_ocean.core.handlers.queue import LocalQueue
|
42 | 45 |
|
43 | 46 |
|
@@ -354,7 +357,9 @@ async def test_extractMatchingProcessors_noMatch(
|
354 | 357 | test_path = "/test"
|
355 | 358 | processor_manager.register_processor(test_path, MockProcessorFalse)
|
356 | 359 |
|
357 |
| - with pytest.raises(ValueError, match="No matching processors found"): |
| 360 | + with pytest.raises( |
| 361 | + WebhookEventNotSupportedError, match="No matching processors found" |
| 362 | + ): |
358 | 363 | async with event_context(
|
359 | 364 | EventType.HTTP_REQUEST, trigger_type="request"
|
360 | 365 | ) as event:
|
@@ -409,6 +414,82 @@ async def test_extractMatchingProcessors_onlyOneMatches(
|
409 | 414 | assert processor.event.payload == webhook_event.payload
|
410 | 415 |
|
411 | 416 |
|
| 417 | +@pytest.mark.asyncio |
| 418 | +async def test_extractMatchingProcessors_noProcessorsRegistered( |
| 419 | + processor_manager: LiveEventsProcessorManager, |
| 420 | + webhook_event: WebhookEvent, |
| 421 | + mock_port_app_config: PortAppConfig, |
| 422 | +) -> None: |
| 423 | + """Test that WebhookEventNotSupportedError is raised for unknown events without any registered processors""" |
| 424 | + test_path = "/unknown_path" |
| 425 | + # No processors registered for this path |
| 426 | + |
| 427 | + # Manually add the path to _processors_classes to simulate a path with no processors |
| 428 | + processor_manager._processors_classes[test_path] = [] |
| 429 | + |
| 430 | + with pytest.raises( |
| 431 | + WebhookEventNotSupportedError, match="No matching processors found" |
| 432 | + ): |
| 433 | + async with event_context( |
| 434 | + EventType.HTTP_REQUEST, trigger_type="request" |
| 435 | + ) as event: |
| 436 | + event.port_app_config = mock_port_app_config |
| 437 | + await processor_manager._extract_matching_processors( |
| 438 | + webhook_event, test_path |
| 439 | + ) |
| 440 | + |
| 441 | + |
| 442 | +@pytest.mark.asyncio |
| 443 | +async def test_extractMatchingProcessors_processorsAvailableButKindsNotConfigured( |
| 444 | + processor_manager: LiveEventsProcessorManager, |
| 445 | + webhook_event: WebhookEvent, |
| 446 | +) -> None: |
| 447 | + """Test that processors available but kinds not configured returns empty list""" |
| 448 | + test_path = "/test" |
| 449 | + |
| 450 | + from port_ocean.core.handlers.port_app_config.models import ( |
| 451 | + PortAppConfig, |
| 452 | + ResourceConfig, |
| 453 | + ) |
| 454 | + |
| 455 | + # Create a mock processor that will match the event but return a kind not in the port app config |
| 456 | + class MockProcessorWithUnmappedKind(AbstractWebhookProcessor): |
| 457 | + async def authenticate( |
| 458 | + self, payload: Dict[str, Any], headers: Dict[str, str] |
| 459 | + ) -> bool: |
| 460 | + return True |
| 461 | + |
| 462 | + async def validate_payload(self, payload: Dict[str, Any]) -> bool: |
| 463 | + return True |
| 464 | + |
| 465 | + async def handle_event( |
| 466 | + self, payload: EventPayload, resource: ResourceConfig |
| 467 | + ) -> WebhookEventRawResults: |
| 468 | + return WebhookEventRawResults( |
| 469 | + updated_raw_results=[], deleted_raw_results=[] |
| 470 | + ) |
| 471 | + |
| 472 | + async def should_process_event(self, event: WebhookEvent) -> bool: |
| 473 | + return True # This processor will match |
| 474 | + |
| 475 | + async def get_matching_kinds(self, event: WebhookEvent) -> list[str]: |
| 476 | + return ["unmapped_kind"] # This kind is not in the mock_port_app_config |
| 477 | + |
| 478 | + processor_manager.register_processor(test_path, MockProcessorWithUnmappedKind) |
| 479 | + |
| 480 | + empty_port_app_config = PortAppConfig( |
| 481 | + resources=[], |
| 482 | + ) |
| 483 | + |
| 484 | + async with event_context(EventType.HTTP_REQUEST, trigger_type="request") as event: |
| 485 | + event.port_app_config = empty_port_app_config |
| 486 | + processors = await processor_manager._extract_matching_processors( |
| 487 | + webhook_event, test_path |
| 488 | + ) |
| 489 | + |
| 490 | + assert len(processors) == 0 |
| 491 | + |
| 492 | + |
412 | 493 | def test_registerProcessor_registrationWorks(
|
413 | 494 | processor_manager: LiveEventsProcessorManager,
|
414 | 495 | ) -> None:
|
@@ -853,7 +934,10 @@ async def patched_extract_matching_processors(
|
853 | 934 | except asyncio.TimeoutError:
|
854 | 935 | pytest.fail("Event processing timed out")
|
855 | 936 |
|
856 |
| - assert isinstance(test_state["exception_thrown"], ValueError) is True |
| 937 | + assert ( |
| 938 | + isinstance(test_state["exception_thrown"], WebhookEventNotSupportedError) |
| 939 | + is True |
| 940 | + ) |
857 | 941 |
|
858 | 942 | mock_upsert.assert_not_called()
|
859 | 943 | mock_delete.assert_not_called()
|
|
0 commit comments