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
3 changes: 2 additions & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ To set up SDK, follow the steps below:
git clone https://github.com/eclipse-uprotocol/uprotocol-python.git
----

. Execute the `pull_and_compile_protos.py` script using the following command:
. Execute the `pull_and_compile_protos.py` script using the following commands:
+
[source]
----
cd scripts
python pull_and_compile_protos.py
----
This script automates the following tasks:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "up-python"
version = "0.1.2-dev"
version = "0.1.3-dev"
description = "Language specific uProtocol library for building and using UUri, UUID, UAttributes, UTransport, and more."
authors = ["Neelam Kushwah <neelam.kushwah@gm.com>"]
license = "The Apache License, Version 2.0"
Expand Down
16 changes: 7 additions & 9 deletions tests/test_cloudevent/test_datamodel/test_ucloudevent.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
#
# -------------------------------------------------------------------------

from datetime import datetime, timezone, timedelta
from datetime import datetime, timezone

from uprotocol.proto.uri_pb2 import UUri, UEntity, UResource
from uprotocol.uri.serializer.longuriserializer import LongUriSerializer
from uprotocol.cloudevent.cloudevents_pb2 import CloudEvent
from uprotocol.proto.uattributes_pb2 import UMessageType, UPriority
from uprotocol.proto.upayload_pb2 import UPayloadFormat
from uprotocol.proto.upayload_pb2 import UPayloadFormat
from uprotocol.cloudevent.factory.cloudeventfactory import CloudEventFactory
from uprotocol.proto.ustatus_pb2 import UCode
from uprotocol.uuid.factory.uuidfactory import Factories
Expand Down Expand Up @@ -407,8 +407,6 @@ def test_from_message_with_valid_message(self):
UCloudEvent.get_type(cloud_event1),
)



def test_to_from_message_from_request_cloudevent(self):
# additional attributes
u_cloud_event_attributes = (
Expand Down Expand Up @@ -599,15 +597,15 @@ def test_cloud_event_to_string(self):

def test_cloud_event_to_string_none(self):
cloud_event_string = UCloudEvent.to_string(None)
self.assertEqual(
cloud_event_string, "null"
)
self.assertEqual(cloud_event_string, "null")

def test_get_upayload_format_from_content_type(self):
new_format = UCloudEvent().get_upayload_format_from_content_type("application/json")
new_format = UCloudEvent().get_upayload_format_from_content_type(
"application/json"
)
self.assertEqual(new_format, UPayloadFormat.UPAYLOAD_FORMAT_JSON)

def test_to_message_none_entry(self):
with self.assertRaises(ValueError) as context:
UCloudEvent().toMessage(None)
self.assertTrue("Cloud Event can't be None" in context.exception)
self.assertTrue("Cloud Event can't be None" in context.exception)
185 changes: 147 additions & 38 deletions tests/test_cloudevent/test_datamodel/test_ucloudeventattributes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# -------------------------------------------------------------------------

# Copyright (c) 2023 General Motors GTO LLC
Expand Down Expand Up @@ -27,45 +26,79 @@

import unittest

from uprotocol.cloudevent.datamodel.ucloudeventattributes import UCloudEventAttributesBuilder, \
UCloudEventAttributes
from uprotocol.cloudevent.datamodel.ucloudeventattributes import (
UCloudEventAttributesBuilder,
UCloudEventAttributes,
)
from uprotocol.proto.uattributes_pb2 import UPriority


class TestUCloudEventAttributes(unittest.TestCase):

def test_to_string(self):
u_cloud_event_attributes = UCloudEventAttributesBuilder().with_hash("somehash").with_priority(
UPriority.UPRIORITY_CS1).with_ttl(3).with_token("someOAuthToken").build()
u_cloud_event_attributes = (
UCloudEventAttributesBuilder()
.with_hash("somehash")
.with_priority(UPriority.UPRIORITY_CS1)
.with_ttl(3)
.with_token("someOAuthToken")
.build()
)

expected = "UCloudEventAttributes{hash='somehash', priority=UPRIORITY_CS1, ttl=3, token='someOAuthToken'}"
self.assertEqual(expected, str(u_cloud_event_attributes))

def test_create_valid_with_blank_traceparent(self):
u_cloud_event_attributes = UCloudEventAttributesBuilder().with_hash("somehash").with_priority(
UPriority.UPRIORITY_CS1).with_ttl(3).with_token("someOAuthToken").with_traceparent(" ").build()
u_cloud_event_attributes = (
UCloudEventAttributesBuilder()
.with_hash("somehash")
.with_priority(UPriority.UPRIORITY_CS1)
.with_ttl(3)
.with_token("someOAuthToken")
.with_traceparent(" ")
.build()
)
self.assertTrue(u_cloud_event_attributes.get_hash() is not None)
self.assertEqual("somehash", u_cloud_event_attributes.get_hash())
self.assertFalse(u_cloud_event_attributes.get_traceparent() is not None)
self.assertFalse(
u_cloud_event_attributes.get_traceparent() is not None
)

def test_create_empty_with_only_traceparent(self):
u_cloud_event_attributes = UCloudEventAttributesBuilder().with_traceparent("someTraceParent").build()
u_cloud_event_attributes = (
UCloudEventAttributesBuilder()
.with_traceparent("someTraceParent")
.build()
)
self.assertFalse(u_cloud_event_attributes.get_hash() is not None)
self.assertFalse(u_cloud_event_attributes.get_priority() is not None)
self.assertFalse(u_cloud_event_attributes.get_token() is not None)
self.assertFalse(u_cloud_event_attributes.get_ttl() is not None)
self.assertTrue(u_cloud_event_attributes.get_traceparent() is not None)
self.assertFalse(u_cloud_event_attributes.is_empty())
self.assertEqual("someTraceParent", u_cloud_event_attributes.get_traceparent())
self.assertEqual(
"someTraceParent", u_cloud_event_attributes.get_traceparent()
)

def test_create_valid(self):
u_cloud_event_attributes = UCloudEventAttributesBuilder().with_hash("somehash").with_priority(
UPriority.UPRIORITY_CS6).with_ttl(3).with_token("someOAuthToken").build()
u_cloud_event_attributes = (
UCloudEventAttributesBuilder()
.with_hash("somehash")
.with_priority(UPriority.UPRIORITY_CS6)
.with_ttl(3)
.with_token("someOAuthToken")
.build()
)

self.assertEqual("somehash", u_cloud_event_attributes.get_hash())
self.assertEqual(UPriority.Name(UPriority.UPRIORITY_CS6), u_cloud_event_attributes.get_priority())
self.assertEqual(
UPriority.Name(UPriority.UPRIORITY_CS6),
u_cloud_event_attributes.get_priority(),
)
self.assertEqual(3, u_cloud_event_attributes.get_ttl())
self.assertEqual("someOAuthToken", u_cloud_event_attributes.get_token())
self.assertEqual(
"someOAuthToken", u_cloud_event_attributes.get_token()
)

def test_is_empty_function(self):
u_cloud_event_attributes = UCloudEventAttributes.empty()
Expand All @@ -75,52 +108,128 @@ def test_is_empty_function(self):
self.assertTrue(u_cloud_event_attributes.ttl is None)

def test_is_empty_function_when_built_with_blank_strings(self):
u_cloud_event_attributes = UCloudEventAttributesBuilder().with_hash(" ").with_token(" ").build()
u_cloud_event_attributes = (
UCloudEventAttributesBuilder()
.with_hash(" ")
.with_token(" ")
.build()
)
self.assertTrue(u_cloud_event_attributes.is_empty())
self.assertTrue(u_cloud_event_attributes.hash.isspace())
self.assertTrue(u_cloud_event_attributes.priority is None)
self.assertTrue(u_cloud_event_attributes.token.isspace())
self.assertTrue(u_cloud_event_attributes.ttl is None)

def test_is_empty_function_permutations(self):
u_cloud_event_attributes = UCloudEventAttributesBuilder().with_hash(" ").with_token(" ").build()
u_cloud_event_attributes = (
UCloudEventAttributesBuilder()
.with_hash(" ")
.with_token(" ")
.build()
)
self.assertTrue(u_cloud_event_attributes.is_empty())

u_cloud_event_attributes2 = UCloudEventAttributesBuilder().with_hash("someHash").with_token(" ").build()
u_cloud_event_attributes2 = (
UCloudEventAttributesBuilder()
.with_hash("someHash")
.with_token(" ")
.build()
)
self.assertFalse(u_cloud_event_attributes2.is_empty())

u_cloud_event_attributes3 = UCloudEventAttributesBuilder().with_hash(" ").with_token("SomeToken").build()
u_cloud_event_attributes3 = (
UCloudEventAttributesBuilder()
.with_hash(" ")
.with_token("SomeToken")
.build()
)
self.assertFalse(u_cloud_event_attributes3.is_empty())

u_cloud_event_attributes4 = UCloudEventAttributesBuilder().with_priority(UPriority.UPRIORITY_CS0).build()
u_cloud_event_attributes4 = (
UCloudEventAttributesBuilder()
.with_priority(UPriority.UPRIORITY_CS0)
.build()
)
self.assertFalse(u_cloud_event_attributes4.is_empty())

u_cloud_event_attributes5 = UCloudEventAttributesBuilder().with_ttl(8).build()
u_cloud_event_attributes5 = (
UCloudEventAttributesBuilder().with_ttl(8).build()
)
self.assertFalse(u_cloud_event_attributes5.is_empty())

def test__eq__is_same(self):
u_cloud_event_attributes = UCloudEventAttributesBuilder().with_hash(" ").with_token(" ").build()
self.assertTrue(u_cloud_event_attributes.__eq__(u_cloud_event_attributes))
u_cloud_event_attributes = (
UCloudEventAttributesBuilder()
.with_hash(" ")
.with_token(" ")
.build()
)
self.assertTrue(
u_cloud_event_attributes.__eq__(u_cloud_event_attributes)
)

def test__eq__is_equal(self):
u_cloud_event_attributes_1 = UCloudEventAttributesBuilder().with_hash(" ").with_token(" ").build()
u_cloud_event_attributes_2 = UCloudEventAttributesBuilder().with_hash(" ").with_token(" ").build()
self.assertTrue(u_cloud_event_attributes_1.__eq__(u_cloud_event_attributes_2))

u_cloud_event_attributes_1 = (
UCloudEventAttributesBuilder()
.with_hash(" ")
.with_token(" ")
.build()
)
u_cloud_event_attributes_2 = (
UCloudEventAttributesBuilder()
.with_hash(" ")
.with_token(" ")
.build()
)
self.assertTrue(
u_cloud_event_attributes_1.__eq__(u_cloud_event_attributes_2)
)

def test__eq__is_not_equal(self):
u_cloud_event_attributes_1 = UCloudEventAttributesBuilder().with_hash(" ").with_token(" ").build()
u_cloud_event_attributes_2 = UCloudEventAttributesBuilder().with_hash(" ").with_token("12345").build()
self.assertFalse(u_cloud_event_attributes_1.__eq__(u_cloud_event_attributes_2))
u_cloud_event_attributes_1 = (
UCloudEventAttributesBuilder()
.with_hash(" ")
.with_token(" ")
.build()
)
u_cloud_event_attributes_2 = (
UCloudEventAttributesBuilder()
.with_hash(" ")
.with_token("12345")
.build()
)
self.assertFalse(
u_cloud_event_attributes_1.__eq__(u_cloud_event_attributes_2)
)

def test__hash__same(self):
u_cloud_event_attributes_1 = UCloudEventAttributesBuilder().with_hash(" ").with_token(" ").build()
self.assertEqual(hash(u_cloud_event_attributes_1), hash(u_cloud_event_attributes_1))

def test__hash__different(self):
u_cloud_event_attributes_1 = UCloudEventAttributesBuilder().with_hash(" ").with_token(" ").build()
u_cloud_event_attributes_2 = UCloudEventAttributesBuilder().with_hash(" ").with_token("12345").build()
self.assertNotEqual(hash(u_cloud_event_attributes_1), hash(u_cloud_event_attributes_2))

u_cloud_event_attributes_1 = (
UCloudEventAttributesBuilder()
.with_hash(" ")
.with_token(" ")
.build()
)
self.assertEqual(
hash(u_cloud_event_attributes_1), hash(u_cloud_event_attributes_1)
)

if __name__ == '__main__':
def test__hash__different(self):
u_cloud_event_attributes_1 = (
UCloudEventAttributesBuilder()
.with_hash(" ")
.with_token(" ")
.build()
)
u_cloud_event_attributes_2 = (
UCloudEventAttributesBuilder()
.with_hash(" ")
.with_token("12345")
.build()
)
self.assertNotEqual(
hash(u_cloud_event_attributes_1), hash(u_cloud_event_attributes_2)
)


if __name__ == "__main__":
unittest.main()
Original file line number Diff line number Diff line change
Expand Up @@ -640,4 +640,4 @@ def fetching_the_notification_validator(self):
validator = CloudEventValidator.get_validator(cloud_event)
status = validator.validate_type(cloud_event).to_status()
self.assertEqual(status, ValidationResult.STATUS_SUCCESS)
self.assertEqual("CloudEventValidator.Notification", str(validator))
self.assertEqual("CloudEventValidator.Notification", str(validator))
5 changes: 2 additions & 3 deletions tests/test_transport/test_builder/test_uattributesbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,9 @@ def test_response_reqid_is_none(self):

def test_response_request_is_none(self):
with self.assertRaises(ValueError) as context:
UAttributesBuilder.response(
None
)
UAttributesBuilder.response(None)
self.assertTrue("request cannot be null." in context.exception)


if __name__ == "__main__":
unittest.main()
6 changes: 0 additions & 6 deletions tests/test_transport/test_builder/test_upayloadbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,6 @@ def test_unpack_given_upayload_proto_returns_method(self):
def test_unpack_exception(self):
builder = self._create_upayload_builder()

original_msg: Message = Method(
name="name",
request_type_url="request_type_url",
response_type_url="response_type_url",
request_streaming=None,
)
upayload: UPayload = UPayload(
format=UPayloadFormat.UPAYLOAD_FORMAT_PROTOBUF,
value=b"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
Expand Down
Loading