File tree Expand file tree Collapse file tree 2 files changed +12
-0
lines changed
Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -215,6 +215,15 @@ def get_time(self) -> Optional[datetime]:
215215 :return: The time of the event.
216216 """
217217 return self ._attributes .get ("time" )
218+
219+ def get_extension (self , extension_name : str ) -> Any :
220+ """
221+ Retrieve an extension attribute of the event.
222+
223+ :param extension_name: The name of the extension attribute.
224+ :return: The value of the extension attribute.
225+ """
226+ return self ._attributes .get (extension_name )
218227
219228 def get_data (self ) -> Optional [dict ]:
220229 """
Original file line number Diff line number Diff line change @@ -219,6 +219,7 @@ def test_cloud_event_constructor() -> None:
219219 subject = "test_subject"
220220 time = datetime .now (tz = timezone .utc )
221221 data = {"key" : "value" }
222+ customextension = "customExtension"
222223
223224 event = CloudEvent (
224225 attributes = {
@@ -230,6 +231,7 @@ def test_cloud_event_constructor() -> None:
230231 "dataschema" : dataschema ,
231232 "subject" : subject ,
232233 "time" : time ,
234+ "customextension" : customextension ,
233235 },
234236 data = data ,
235237 )
@@ -242,4 +244,5 @@ def test_cloud_event_constructor() -> None:
242244 assert event .get_dataschema () == dataschema
243245 assert event .get_subject () == subject
244246 assert event .get_time () == time
247+ assert event .get_extension ("customextension" ) == customextension
245248 assert event .get_data () == data
You can’t perform that action at this time.
0 commit comments