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
2 changes: 1 addition & 1 deletion CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
# AZURE FUNCTIONS TEAM
# For all file changes, github would automatically
# include the following people in the PRs.
* @vrdmr @gavin-aguiar @hallvictoria @EvanR-Dev
* @vrdmr @gavin-aguiar @hallvictoria
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@


_X_OPT_LOCK_TOKEN = b"x-opt-lock-token"
LOCK_TOKEN_LENGTH = 16

# AMQP format codes (subset)
FMT_NULL = 0x40
Expand All @@ -30,17 +31,17 @@ def get_lock_token(message: bytes, index: int) -> str:

# Convert the lock token to a UUID using the first 16 bytes
# Use little-endian to match SDK
lock_token_uuid = uuid.UUID(bytes_le=lock_token_encoded[:16])
lock_token_uuid = uuid.UUID(bytes_le=lock_token_encoded[:LOCK_TOKEN_LENGTH])
Comment thread
hallvictoria marked this conversation as resolved.

return lock_token_uuid


def get_amqp_message(message: bytes, index: int):
def get_amqp_message(message: bytes):
"""
Get the amqp message from the model_binding_data content
and create the message.
"""
amqp_message = message[index + len(_X_OPT_LOCK_TOKEN):]
Comment thread
swapnil-nagar marked this conversation as resolved.
amqp_message = message[LOCK_TOKEN_LENGTH:]
decoded_message = uamqp.Message().decode_from_bytes(amqp_message)

return decoded_message
Expand All @@ -62,7 +63,7 @@ def get_decoded_message(content: bytes):
lock_token = get_lock_token(content, index)
delivery_anno_dict = {_X_OPT_LOCK_TOKEN: lock_token}

decoded_message = get_amqp_message(content, index)
decoded_message = get_amqp_message(content)
decoded_message.delivery_annotations = delivery_anno_dict
return decoded_message
except Exception as e:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,30 @@ def test_input_get_decoded_message_ex(self):
_ = get_decoded_message("Invalid message")

self.assertIn("Failed to decode ServiceBus content", e.exception.args[0])

def test_populated_properties(self):
sample_mbd = MockMBD(
version="1.0",
source="AzureServiceBusReceivedMessage",
content_type="application/octet-stream",
content=SERVICEBUS_SAMPLE_CONTENT
)

datum: Datum = Datum(value=sample_mbd, type="model_binding_data")
result: ServiceBusReceivedMessage = ServiceBusConverter.decode(
data=datum, trigger_metadata=None, pytype=ServiceBusReceivedMessage
)

self.assertIsNotNone(result)
self.assertIsInstance(result, ServiceBusSDK)

self.assertIsNotNone(result.body)
self.assertIsNotNone(result.delivery_count)
self.assertIsNotNone(result.enqueued_time_utc)
self.assertIsNotNone(result.expires_at_utc)
self.assertIsNotNone(result.lock_token)
self.assertIsNotNone(result.locked_until_utc)
self.assertIsNotNone(result.message_id)
self.assertIsNotNone(result.sequence_number)
self.assertIsNotNone(result.state)
self.assertIsNotNone(result.time_to_live)