Skip to content

Commit df3292d

Browse files
authored
feat: base changes for message settlement (#139)
* base changes for message settlement * fix import * flake * test fix
1 parent db24389 commit df3292d

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

azurefunctions-extensions-base/azurefunctions/extensions/base/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
33

4+
from .grpcClientType import GrpcClientType
45
from .meta import (
56
Datum,
67
InConverter,
@@ -31,6 +32,7 @@
3132
"get_binding_registry",
3233
"ModuleTrackerMeta",
3334
"RequestTrackerMeta",
35+
"GrpcClientType",
3436
"ResponseTrackerMeta",
3537
"HttpV2FeatureChecker",
3638
"ResponseLabels",
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
5+
class GrpcClientType:
6+
def __init__(self, *, data: dict = None):
7+
self._data = data or {}

azurefunctions-extensions-base/azurefunctions/extensions/base/meta.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import json
77
from typing import Any, Dict, Mapping, Optional, Tuple, Union, get_args, get_origin
88

9-
from . import sdkType, utils
9+
from . import grpcClientType, sdkType, utils
1010

1111

1212
class Datum:
@@ -99,6 +99,15 @@ def check_supported_type(cls, annotation: type) -> bool:
9999
# An iterable who only has one inner type and is a subclass of SdkType
100100
return cls._is_iterable_supported_type(annotation)
101101

102+
@classmethod
103+
def check_supported_grpc_client_type(cls, annotation: type) -> bool:
104+
if annotation is None:
105+
return False
106+
107+
# The annotation is a class/type (not an object) - not iterable
108+
return (isinstance(annotation, type)
109+
and issubclass(annotation, grpcClientType.GrpcClientType))
110+
102111
@classmethod
103112
def _is_iterable_supported_type(cls, annotation: type) -> bool:
104113
# Check base type from type hint. Ex: List from List[SdkType]

azurefunctions-extensions-base/tests/test_meta.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from unittest.mock import patch
77

88
from azurefunctions.extensions.base import meta, sdkType
9+
from azurefunctions.extensions.base.grpcClientType import GrpcClientType
910

1011

1112
class TestMeta(unittest.TestCase):
@@ -162,6 +163,21 @@ class MockIndexedFunction:
162163
self.assertTrue(registry.check_supported_type(set[sdkType.SdkType]))
163164
self.assertFalse(registry.check_supported_type(dict[str, sdkType.SdkType]))
164165

166+
def test_registry_grpc_client(self):
167+
registry = meta.get_binding_registry()
168+
self.assertIsInstance(registry, type(meta._ConverterMeta))
169+
self.assertIsNone(registry.get("test"))
170+
171+
class MockIndexedFunction:
172+
_bindings = {}
173+
_trigger = None
174+
175+
self.assertEqual(registry.get_raw_bindings(MockIndexedFunction, []), ([], {}))
176+
177+
self.assertFalse(registry.check_supported_grpc_client_type(None))
178+
self.assertFalse(registry.check_supported_grpc_client_type("hello"))
179+
self.assertTrue(registry.check_supported_grpc_client_type(GrpcClientType))
180+
165181
def test_decode_typed_data(self):
166182
# Case 1: data is None
167183
self.assertIsNone(

0 commit comments

Comments
 (0)