Skip to content

Commit f064fff

Browse files
committed
Addressed comments
1 parent f45122c commit f064fff

File tree

2 files changed

+36
-13
lines changed

2 files changed

+36
-13
lines changed

azure_functions_worker/functions.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ def validate_binding_route(func_name: str, binding: BindingInfo,
8585
'/') and func_type == 'function':
8686
raise FunctionLoadError(
8787
func_name,
88-
f'Invalid route name. {binding.route}')
88+
f'Invalid route name: {binding.route}. Route name cannot begin'
89+
f' with a /')
8990

9091
@staticmethod
9192
def validate_binding_direction(binding_name: str,
@@ -102,6 +103,14 @@ def validate_binding_direction(binding_name: str,
102103
func_name,
103104
'"$return" binding must have direction set to "out"')
104105

106+
def validate_bindings(self, func_name: str, binding: BindingInfo,
107+
func_type: str):
108+
self.validate_binding_route(func_name, binding, func_type)
109+
110+
self.validate_binding_direction(binding.name,
111+
binding.direction,
112+
func_name)
113+
105114
@staticmethod
106115
def is_context_required(params, bound_params: dict,
107116
annotations: dict,
@@ -378,11 +387,7 @@ def add_indexed_function(self, function_id: str,
378387

379388
bound_params = {}
380389
for binding in function.get_bindings():
381-
self.validate_binding_route(func_name, binding, func_type)
382-
383-
self.validate_binding_direction(binding.name,
384-
binding.direction,
385-
func_name)
390+
self.validate_bindings(func_name, binding, func_type)
386391

387392
has_explicit_return, has_implicit_return = \
388393
self.get_explicit_and_implicit_return(

tests/unittests/test_functions_registry.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
# Licensed under the MIT License.
33

44
import unittest
5+
56
from azure.functions import Function
7+
from azure.functions.decorators.blob import BlobInput
68
from azure.functions.decorators.http import HttpTrigger
79

810
from azure_functions_worker import functions
@@ -19,13 +21,29 @@ def dummy():
1921
self.func = Function(self.dummy, "test.py")
2022
self.function_registry = functions.Registry()
2123

22-
def test_add_index_functions_invalid_route(self):
23-
function_id = '123'
24+
def test_add_indexed_function_invalid_route(self):
25+
trigger1 = HttpTrigger(name="req1", route="/")
26+
self.func.add_trigger(trigger=trigger1)
27+
28+
with self.assertRaises(FunctionLoadError) as ex:
29+
self.function_registry.add_indexed_function(function_id='123',
30+
function=self.func)
2431

25-
trigger1 = HttpTrigger(name="req1",
26-
route="/")
32+
self.assertEqual(str(ex.exception),
33+
'cannot load the dummy function: Invalid route name: '
34+
'/. Route name cannot begin with a /')
35+
36+
def test_add_indexed_function_invalid_direction(self):
37+
trigger1 = HttpTrigger(name="req1", route="test")
38+
binding = BlobInput(name="$return", path="testpath",
39+
connection="testconnection")
2740
self.func.add_trigger(trigger=trigger1)
41+
self.func.add_binding(binding=binding)
42+
43+
with self.assertRaises(FunctionLoadError) as ex:
44+
self.function_registry.add_indexed_function(function_id='123',
45+
function=self.func)
2846

29-
with self.assertRaises(FunctionLoadError):
30-
self.function_registry.add_indexed_function(function_id,
31-
self.func)
47+
self.assertEqual(str(ex.exception),
48+
'cannot load the dummy function: \"$return\" '
49+
'binding must have direction set to \"out\"')

0 commit comments

Comments
 (0)