Skip to content

Commit

Permalink
comment refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
peterstone2017 authored and YunchuWang committed Apr 20, 2022
1 parent 4ef4b25 commit e0130bf
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 39 deletions.
29 changes: 18 additions & 11 deletions azure/functions/decorators/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ def get_binding_name() -> str:

def __init__(self, name: str,
direction: BindingDirection,
data_type: Optional[DataType] = None):
self.type = self.get_binding_name()
data_type: Optional[DataType] = None,
type: Optional[str] = None): # NoQa
self.type = self.get_binding_name() \
if self.get_binding_name() is not None else type
self.name = name
self._direction = direction
self._data_type = data_type
Expand Down Expand Up @@ -122,31 +124,36 @@ class Trigger(Binding, ABC, metaclass=ABCBuildDictMeta):
Ref: https://aka.ms/functions-triggers-bindings-overview
"""

def __init__(self, name, data_type) -> None:
def __init__(self, name: str, data_type: Optional[DataType] = None,
type: Optional[str] = None) -> None:
super().__init__(direction=BindingDirection.IN,
name=name, data_type=data_type)
name=name, data_type=data_type, type=type)


class InputBinding(Binding, ABC, metaclass=ABCBuildDictMeta):
"""Class representation of Azure Function Input Binding. \n
Ref: https://aka.ms/functions-triggers-bindings-overview
"""

def __init__(self, name, data_type) -> None:
def __init__(self, name: str, data_type: Optional[DataType] = None,
type: Optional[str] = None) -> None:
super().__init__(direction=BindingDirection.IN,
name=name, data_type=data_type)
name=name, data_type=data_type, type=type)


class OutputBinding(Binding, ABC, metaclass=ABCBuildDictMeta):
"""Class representation of Azure Function Output Binding. \n
Ref: https://aka.ms/functions-triggers-bindings-overview
"""

def __init__(self, name, data_type) -> None:
def __init__(self, name: str, data_type: Optional[DataType] = None,
type: Optional[str] = None) -> None:
super().__init__(direction=BindingDirection.OUT,
name=name, data_type=data_type)
name=name, data_type=data_type, type=type)


def is_supported_trigger_type(trigger: Trigger, trigger_type: Type[Trigger]):
return isinstance(trigger, trigger_type) or \
trigger.get_binding_name() == trigger_type.get_binding_name()
def is_supported_trigger_type(trigger_instance: Trigger,
trigger_type: Type[Trigger]):
return isinstance(trigger_instance,
trigger_type) or \
trigger_instance.type == trigger_type.get_binding_name()
22 changes: 7 additions & 15 deletions azure/functions/decorators/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,43 @@


class CustomInputBinding(InputBinding):
binding_name: str = ""

@staticmethod
def get_binding_name() -> str:
return CustomInputBinding.binding_name
pass

def __init__(self,
name: str,
type: str,
data_type: Optional[DataType] = None,
**kwargs):
self.type = type
CustomInputBinding.binding_name = type
super().__init__(name=name, data_type=data_type)
super().__init__(name=name, data_type=data_type, type=type)


class CustomOutputBinding(OutputBinding):
binding_name: str = ""
# binding_name: str = ""

@staticmethod
def get_binding_name() -> str:
return CustomOutputBinding.binding_name
pass

def __init__(self,
name: str,
type: str,
data_type: Optional[DataType] = None,
**kwargs):
self.type = type
CustomOutputBinding.binding_name = type
super().__init__(name=name, data_type=data_type)
super().__init__(name=name, data_type=data_type, type=type)


class CustomTrigger(Trigger):
binding_name: str = ""

@staticmethod
def get_binding_name() -> str:
return CustomTrigger.binding_name
pass

def __init__(self,
name: str,
type: str,
data_type: Optional[DataType] = None,
**kwargs):
self.type = type
CustomTrigger.binding_name = type
super().__init__(name=name, data_type=data_type)
super().__init__(name=name, data_type=data_type, type=type)
3 changes: 1 addition & 2 deletions azure/functions/decorators/function_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,7 @@ def decorator():

def _add_http_app(self,
http_middleware: Union[AsgiMiddleware, WsgiMiddleware],
app_kwargs: typing.Dict
) -> None:
app_kwargs: typing.Dict) -> None:
"""Add a Wsgi or Asgi app integrated http function.
:param http_middleware: :class:`AsgiMiddleware` or
Expand Down
8 changes: 0 additions & 8 deletions tests/decorators/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ def __init__(self,

class TestBindings(unittest.TestCase):
def test_trigger_creation(self):
"""Testing if the trigger creation sets the correct values by default
"""
test_trigger = DummyTrigger(name="dummy", data_type=DataType.UNDEFINED)

expected_dict = {'dataType': DataType.UNDEFINED,
Expand All @@ -57,8 +55,6 @@ def test_trigger_creation(self):
self.assertEqual(test_trigger.get_dict_repr(), expected_dict)

def test_param_direction_unset(self):
"""Testing if the trigger creation sets the correct values by default
"""
test_trigger = DummyTrigger(name="dummy", data_type=DataType.UNDEFINED,
direction="dummy", type="hello")

Expand All @@ -70,8 +66,6 @@ def test_param_direction_unset(self):
self.assertEqual(test_trigger.get_dict_repr(), expected_dict)

def test_input_creation(self):
"""Testing if the input creation sets the correct values by default
"""
test_input = DummyInputBinding(name="dummy",
data_type=DataType.UNDEFINED)

Expand All @@ -84,8 +78,6 @@ def test_input_creation(self):
self.assertEqual(test_input.get_dict_repr(), expected_dict)

def test_output_creation(self):
"""Testing if the output creation sets the correct values by default
"""
test_output = DummyOutputBinding(name="dummy",
data_type=DataType.UNDEFINED)

Expand Down
7 changes: 4 additions & 3 deletions tests/decorators/test_custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def test_custom_trigger_valid_creation(self):
methods=["GET", "POST"],
route="dummy")

self.assertEqual(trigger.get_binding_name(), HTTP_TRIGGER)
self.assertEqual(trigger.get_binding_name(), None)
self.assertEqual(trigger.type, HTTP_TRIGGER)
self.assertEqual(trigger.get_dict_repr(), {
"authLevel": AuthLevel.ANONYMOUS,
"type": HTTP_TRIGGER,
Expand All @@ -39,7 +40,7 @@ def test_custom_input_valid_creation(self):
id='dummy_id',
partitionKey='dummy_partitions',
sqlQuery='dummy_query')
self.assertEqual(cosmosdb_input.get_binding_name(), COSMOS_DB)
self.assertEqual(cosmosdb_input.get_binding_name(), None)
self.assertEqual(cosmosdb_input.get_dict_repr(),
{'collectionName': 'dummy_collection',
'connectionStringSetting': 'dummy_str',
Expand All @@ -57,7 +58,7 @@ def test_custom_output_valid_creation(self):
path="dummy_path",
connection="dummy_connection")

self.assertEqual(blob_output.get_binding_name(), BLOB)
self.assertEqual(blob_output.get_binding_name(), None)
self.assertEqual(blob_output.get_dict_repr(), {
"type": BLOB,
"direction": BindingDirection.OUT,
Expand Down

0 comments on commit e0130bf

Please sign in to comment.