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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

from .grpcClientType import GrpcClientType
from .meta import (
Datum,
InConverter,
Expand Down Expand Up @@ -31,6 +32,7 @@
"get_binding_registry",
"ModuleTrackerMeta",
"RequestTrackerMeta",
"GrpcClientType",
"ResponseTrackerMeta",
"HttpV2FeatureChecker",
"ResponseLabels",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.


class GrpcClientType:
def __init__(self, *, data: dict = None):
self._data = data or {}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import json
from typing import Any, Dict, Mapping, Optional, Tuple, Union, get_args, get_origin

from . import sdkType, utils
from . import grpcClientType, sdkType, utils


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

@classmethod
def check_supported_grpc_client_type(cls, annotation: type) -> bool:
if annotation is None:
return False

# The annotation is a class/type (not an object) - not iterable
return (isinstance(annotation, type)
and issubclass(annotation, grpcClientType.GrpcClientType))

@classmethod
def _is_iterable_supported_type(cls, annotation: type) -> bool:
# Check base type from type hint. Ex: List from List[SdkType]
Expand Down
16 changes: 16 additions & 0 deletions azurefunctions-extensions-base/tests/test_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from unittest.mock import patch

from azurefunctions.extensions.base import meta, sdkType
from azurefunctions.extensions.base.grpcClientType import GrpcClientType


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

def test_registry_grpc_client(self):
registry = meta.get_binding_registry()
self.assertIsInstance(registry, type(meta._ConverterMeta))
self.assertIsNone(registry.get("test"))

class MockIndexedFunction:
_bindings = {}
_trigger = None

self.assertEqual(registry.get_raw_bindings(MockIndexedFunction, []), ([], {}))

self.assertFalse(registry.check_supported_grpc_client_type(None))
self.assertFalse(registry.check_supported_grpc_client_type("hello"))
self.assertTrue(registry.check_supported_grpc_client_type(GrpcClientType))

def test_decode_typed_data(self):
# Case 1: data is None
self.assertIsNone(
Expand Down
Loading