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
17 changes: 15 additions & 2 deletions azure/functions/decorators/eventgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,23 @@ def get_binding_name() -> str:

def __init__(self,
name: str,
topic_endpoint_uri: str,
topic_key_setting: str,
topic_endpoint_uri: Optional[str] = None,
topic_key_setting: Optional[str] = None,
connection: Optional[str] = None,
data_type: Optional[DataType] = None,
**kwargs):
if (connection is not None and (
topic_endpoint_uri is not None
or topic_key_setting is not None)) or \
(connection is None and (
topic_endpoint_uri is None
or topic_key_setting is None)):
raise ValueError(
"Specify either the 'Connection' property or both "
"'TopicKeySetting' and 'TopicEndpointUri' properties,"
" but not both.")

self.topic_endpoint_uri = topic_endpoint_uri
self.topic_key_setting = topic_key_setting
self.connection = connection
super().__init__(name=name, data_type=data_type)
8 changes: 6 additions & 2 deletions azure/functions/decorators/function_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2138,8 +2138,9 @@ def decorator():

def event_grid_output(self,
arg_name: str,
topic_endpoint_uri: str,
topic_key_setting: str,
topic_endpoint_uri: Optional[str] = None,
topic_key_setting: Optional[str] = None,
connection: Optional[str] = None,
data_type: Optional[
Union[DataType, str]] = None,
**kwargs) -> Callable[..., Any]:
Expand All @@ -2164,6 +2165,8 @@ def event_grid_output(self,
contains the URI for the custom topic.
:param topic_key_setting: The name of an app setting that
contains an access key for the custom topic.
:param connection: The value of the common prefix for the setting that
contains the topic endpoint URI.
:return: Decorator function.
"""

Expand All @@ -2175,6 +2178,7 @@ def decorator():
name=arg_name,
topic_endpoint_uri=topic_endpoint_uri,
topic_key_setting=topic_key_setting,
connection=connection,
data_type=parse_singular_param_to_enum(data_type,
DataType),
**kwargs))
Expand Down
47 changes: 38 additions & 9 deletions tests/decorators/test_eventgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,46 @@ def test_event_grid_output_valid_creation(self):
output = EventGridOutput(name="res",
topic_endpoint_uri="dummy_topic_endpoint_uri",
topic_key_setting="dummy_topic_key_setting",
connection="dummy_connection",
data_type=DataType.UNDEFINED,
dummy_field="dummy")

self.assertEqual(output.get_binding_name(), "eventGrid")
self.assertEqual(output.get_dict_repr(),
{'connection': 'dummy_connection',
'dataType': DataType.UNDEFINED,
'direction': BindingDirection.OUT,
'dummyField': 'dummy',
'topicEndpointUri': 'dummy_topic_endpoint_uri',
'topicKeySetting': 'dummy_topic_key_setting',
'name': 'res',
'type': EVENT_GRID})
{'dataType': DataType.UNDEFINED,
'direction': BindingDirection.OUT,
'dummyField': 'dummy',
'topicEndpointUri': 'dummy_topic_endpoint_uri',
'topicKeySetting': 'dummy_topic_key_setting',
'name': 'res',
'type': EVENT_GRID})

def test_event_grid_output_valid_creation_with_connection(self):
output = EventGridOutput(name="res",
connection="dummy_connection",
data_type=DataType.UNDEFINED,
dummy_field="dummy")

self.assertEqual(output.connection, "dummy_connection")
self.assertIsNone(output.topic_endpoint_uri)
self.assertIsNone(output.topic_key_setting)

def test_event_grid_output_invalid_creation_with_both(self):
with self.assertRaises(ValueError) as context:
EventGridOutput(name="res",
connection="dummy_connection",
topic_endpoint_uri="dummy_topic_endpoint_uri",
topic_key_setting="dummy_topic_key_setting")

self.assertTrue("Specify either the 'Connection' property or both "
"'TopicKeySetting' and 'TopicEndpointUri' properties, "
"but not both." in str(context.exception))

def test_event_grid_output_invalid_creation_with_none(self):
with self.assertRaises(ValueError) as context:
EventGridOutput(name="res",
data_type=DataType.UNDEFINED,
dummy_field="dummy")

self.assertTrue("Specify either the 'Connection' property or both "
"'TopicKeySetting' and 'TopicEndpointUri' properties,"
" but not both." in str(context.exception))