Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions tests/test_cloudevent/test_datamodel/test_ucloudevent.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,20 @@ def test_to_from_message_from_request_cloudevent_without_attributes(self):
self.assertEquals(UCloudEvent.get_id(cloud_event),UCloudEvent.get_id(cloud_event1))
self.assertEquals(UCloudEvent.get_type(cloud_event),UCloudEvent.get_type(cloud_event1))
self.assertEquals(UCloudEvent.get_request_id(cloud_event),UCloudEvent.get_request_id(cloud_event1))

def test_to_from_message_from_UCP_cloudevent(self):
# additional attributes
u_cloud_event_attributes = UCloudEventAttributesBuilder().with_ttl(3).with_token("someOAuthToken").build()

cloud_event = CloudEventFactory.request(build_uri_for_test(), "//bo.cloud/petapp/1/rpc.response",
CloudEventFactory.generate_cloud_event_id(),
build_proto_payload_for_test(),
u_cloud_event_attributes)
cloud_event.__setitem__("priority", "CS4")

result = UCloudEvent.toMessage(cloud_event)
self.assertIsNotNone(result)
self.assertEquals(UPriority.UPRIORITY_CS4,result.attributes.priority)
cloud_event1 = UCloudEvent.fromMessage(result)
self.assertEquals(UCloudEvent.get_priority(cloud_event1),UPriority.Name(result.attributes.priority))

4 changes: 4 additions & 0 deletions uprotocol/cloudevent/factory/ucloudevent.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,10 @@ def toMessage(event: CloudEvent) -> UMessage:
if UCloudEvent.has_communication_status_problem(event):
attributes.commstatus = UCloudEvent.get_communication_status(event)
priority = UCloudEvent.get_priority(event)

if priority and 'UPRIORITY_' not in priority:
priority = 'UPRIORITY_' + priority

if priority is not None:
attributes.priority = priority

Expand Down