@@ -54,6 +54,29 @@ def test_connection_info(self) -> None:
5454 config = CloudEventsConfig (endpoint = "https://example.com/webhook" )
5555 assert "POST https://example.com/webhook" in config .get_connection_info ()
5656
57+ @patch .dict (
58+ os .environ ,
59+ {"K_CE_OVERRIDES" : '{"extensions": {"extra": "test", "num": 42}}' },
60+ )
61+ def test_k_ce_overrides_valid (self ) -> None :
62+ """Test K_CE_OVERRIDES with valid extensions."""
63+ config = CloudEventsConfig ()
64+ assert config .overrides == {"extra" : "test" , "num" : 42 }
65+
66+ @patch .dict (os .environ , {"K_CE_OVERRIDES" : '{"other": "field"}' })
67+ def test_k_ce_overrides_no_extensions (self ) -> None :
68+ """Test K_CE_OVERRIDES without extensions field."""
69+ config = CloudEventsConfig ()
70+ assert config .overrides == {}
71+
72+ @patch .dict (os .environ , {"K_CE_OVERRIDES" : "invalid-json" })
73+ def test_k_ce_overrides_invalid_json (self ) -> None :
74+ """Test K_CE_OVERRIDES with invalid JSON."""
75+ from pydantic import ValidationError
76+
77+ with pytest .raises (ValidationError ):
78+ CloudEventsConfig ()
79+
5780
5881class TestCloudEventsAdapter :
5982 """Test CloudEvents output adapter."""
@@ -286,3 +309,60 @@ async def test_health_check(self, adapter: CloudEventsAdapter) -> None:
286309 # Running with client
287310 adapter ._client = MagicMock ()
288311 assert await adapter .health_check () is True
312+
313+ @patch .dict (
314+ os .environ ,
315+ {
316+ "K_CE_OVERRIDES" : (
317+ '{"extensions": {"extra": "test-value", "priority": "high"}}'
318+ )
319+ },
320+ )
321+ def test_convert_to_cloudevent_with_overrides (
322+ self , config : CloudEventsConfig , sample_event : NotificationEvent
323+ ) -> None :
324+ """Test CloudEvent conversion with K_CE_OVERRIDES."""
325+ # Create adapter after environment variable is set
326+ adapter = CloudEventsAdapter (config )
327+ cloud_event = adapter ._convert_to_cloudevent (sample_event )
328+
329+ assert isinstance (cloud_event , CloudEvent )
330+ assert cloud_event ["extra" ] == "test-value"
331+ assert cloud_event ["priority" ] == "high"
332+
333+ @patch .dict (os .environ , {"K_CE_OVERRIDES" : '{"extensions": {"number": 123}}' })
334+ def test_convert_to_cloudevent_with_number_override (
335+ self , config : CloudEventsConfig , sample_event : NotificationEvent
336+ ) -> None :
337+ """Test CloudEvent conversion with number in K_CE_OVERRIDES."""
338+ # Create adapter after environment variable is set
339+ adapter = CloudEventsAdapter (config )
340+ cloud_event = adapter ._convert_to_cloudevent (sample_event )
341+
342+ assert cloud_event ["number" ] == "123" # Should be converted to string
343+
344+ @patch .dict (os .environ , {"K_CE_OVERRIDES" : "invalid-json" })
345+ def test_convert_to_cloudevent_invalid_overrides (
346+ self , config : CloudEventsConfig , sample_event : NotificationEvent
347+ ) -> None :
348+ """Test CloudEvent conversion with invalid K_CE_OVERRIDES JSON."""
349+ # Create adapter after environment variable is set
350+ adapter = CloudEventsAdapter (config )
351+ cloud_event = adapter ._convert_to_cloudevent (sample_event )
352+
353+ # Should work normally without overrides
354+ assert isinstance (cloud_event , CloudEvent )
355+ assert cloud_event ["source" ] == "/eoapi/stac"
356+
357+ @patch .dict (os .environ , {"K_CE_OVERRIDES" : '{"other": "field"}' })
358+ def test_convert_to_cloudevent_no_extensions (
359+ self , config : CloudEventsConfig , sample_event : NotificationEvent
360+ ) -> None :
361+ """Test CloudEvent conversion with K_CE_OVERRIDES but no extensions field."""
362+ # Create adapter after environment variable is set
363+ adapter = CloudEventsAdapter (config )
364+ cloud_event = adapter ._convert_to_cloudevent (sample_event )
365+
366+ # Should work normally without extensions
367+ assert isinstance (cloud_event , CloudEvent )
368+ assert cloud_event ["source" ] == "/eoapi/stac"
0 commit comments