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
48 changes: 24 additions & 24 deletions azure/functions/decorators/function_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,30 @@ def app_script_file(self) -> str:
"""
return self._app_script_file

def function_name(self, name: str,
setting_extra_fields: Dict[str, Any] = {},
) -> Callable[..., Any]:
"""Optional: Sets name of the :class:`Function` object. If not set,
it will default to the name of the method name.

:param name: Name of the function.
:param setting_extra_fields: Keyword arguments for specifying
additional setting fields
:return: Decorator function.
"""

@self._configure_function_builder
def wrap(fb):
def decorator():
fb.add_setting(setting=FunctionName(
function_name=name,
**setting_extra_fields))
return fb

return decorator()

return wrap

def _validate_type(self,
func: Union[Callable[..., Any], FunctionBuilder]) \
-> FunctionBuilder:
Expand Down Expand Up @@ -2601,30 +2625,6 @@ class SettingsApi(DecoratorApi, ABC):
"""Interface to extend for using existing settings decorator in
functions."""

def function_name(self, name: str,
setting_extra_fields: Dict[str, Any] = {},
) -> Callable[..., Any]:
"""Optional: Sets name of the :class:`Function` object. If not set,
it will default to the name of the method name.

:param name: Name of the function.
:param setting_extra_fields: Keyword arguments for specifying
additional setting fields
:return: Decorator function.
"""

@self._configure_function_builder
def wrap(fb):
def decorator():
fb.add_setting(setting=FunctionName(
function_name=name,
**setting_extra_fields))
return fb

return decorator()

return wrap

def retry(self,
strategy: str,
max_retry_count: str,
Expand Down
33 changes: 29 additions & 4 deletions tests/decorators/test_function_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
TIMER_TRIGGER
from azure.functions.decorators.core import DataType, AuthLevel, \
BindingDirection, SCRIPT_FILE_NAME
from azure.functions.decorators.function_app import FunctionBuilder, \
FunctionApp, Function, Blueprint, DecoratorApi, AsgiFunctionApp, \
WsgiFunctionApp, HttpFunctionsAuthLevelMixin, FunctionRegister, \
TriggerApi, ExternalHttpFunctionApp
from azure.functions.decorators.function_app import BindingApi, \
FunctionBuilder, FunctionApp, Function, Blueprint, DecoratorApi, \
AsgiFunctionApp, WsgiFunctionApp, HttpFunctionsAuthLevelMixin, \
FunctionRegister, TriggerApi, ExternalHttpFunctionApp
from azure.functions.decorators.http import HttpTrigger, HttpOutput, \
HttpMethod
from azure.functions.decorators.retry_policy import RetryPolicy
Expand Down Expand Up @@ -489,6 +489,31 @@ def hello(name: str):
self.assertEqual(setting.get_settings_value("function_name"),
"timer_function")

def test_legacy_blueprints_with_function_name(self):
class LegacyBluePrint(TriggerApi, BindingApi):
pass

Comment on lines +493 to +495
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

notice this doesn't inherit from SettingsApi :)

class DummyFunctionApp(FunctionRegister, TriggerApi):
pass

app = DummyFunctionApp(auth_level=AuthLevel.ANONYMOUS)
blueprint = LegacyBluePrint()

@blueprint.function_name("timer_function")
@blueprint.schedule(arg_name="name", schedule="10****")
def hello(name: str):
return name

app.register_blueprint(blueprint)

functions = app.get_functions()
self.assertEqual(len(functions), 1)

setting = functions[0].get_setting("function_name")

self.assertEqual(setting.get_settings_value("function_name"),
"timer_function")

def test_function_register_register_function_register_error(self):
class DummyFunctionApp(FunctionRegister):
pass
Expand Down