diff --git a/tests/endtoend/test_http_functions.py b/tests/endtoend/test_http_functions.py index e62cabf5f..167aadb4d 100644 --- a/tests/endtoend/test_http_functions.py +++ b/tests/endtoend/test_http_functions.py @@ -39,8 +39,8 @@ def test_function_index_page_should_return_ok(self): """The index page of Azure Functions should return OK in any circumstances """ - root_url = self.webhost._addr - r = requests.get(root_url, timeout=REQUEST_TIMEOUT_SEC) + r = self.webhost.request('GET', '', no_prefix=True, + timeout=REQUEST_TIMEOUT_SEC) self.assertTrue(r.ok) @testutils.retryable_test(3, 5) diff --git a/tests/endtoend/test_timer_functions.py b/tests/endtoend/test_timer_functions.py new file mode 100644 index 000000000..12055bc6c --- /dev/null +++ b/tests/endtoend/test_timer_functions.py @@ -0,0 +1,43 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. +import time +import typing +from tests.utils import testutils + +REQUEST_TIMEOUT_SEC = 5 + + +class TestTimerFunctions(testutils.WebHostTestCase): + """Test the Timer in the local webhost. + + This test class will spawn a webhost from your /build/webhost + folder and replace the built-in Python with azure_functions_worker from + your code base. Since the Timer Trigger is a native support from host, we + don't need to setup any external resources. + + Compared to the unittests/test_timer_functions.py, this file is more focus + on testing the E2E flow scenarios. + """ + + @classmethod + def get_script_dir(cls): + return testutils.E2E_TESTS_FOLDER / 'timer_functions' + + def test_timer(self): + time.sleep(1) + # Checking webhost status. + r = self.webhost.request('GET', '', no_prefix=True, + timeout=REQUEST_TIMEOUT_SEC) + self.assertTrue(r.ok) + + def check_log_timer(self, host_out: typing.List[str]): + self.assertEqual(host_out.count("This timer trigger function executed " + "successfully"), 1) + + +class TestTimerFunctionsStein(TestTimerFunctions): + + @classmethod + def get_script_dir(cls): + return testutils.E2E_TESTS_FOLDER / 'timer_functions' / \ + 'timer_functions_stein' diff --git a/tests/endtoend/timer_functions/timer_func/__init__.py b/tests/endtoend/timer_functions/timer_func/__init__.py new file mode 100644 index 000000000..5cdd1a102 --- /dev/null +++ b/tests/endtoend/timer_functions/timer_func/__init__.py @@ -0,0 +1,10 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +import logging + +import azure.functions as func + + +def main(mytimer: func.TimerRequest) -> None: + logging.info("This timer trigger function executed successfully") diff --git a/tests/endtoend/timer_functions/timer_func/function.json b/tests/endtoend/timer_functions/timer_func/function.json new file mode 100644 index 000000000..dba900a90 --- /dev/null +++ b/tests/endtoend/timer_functions/timer_func/function.json @@ -0,0 +1,12 @@ +{ + "scriptFile": "__init__.py", + "bindings": [ + { + "name": "mytimer", + "type": "timerTrigger", + "direction": "in", + "schedule": "*/1 * * * * *", + "runOnStartup": false + } + ] +} \ No newline at end of file diff --git a/tests/endtoend/timer_functions/timer_functions_stein/function_app.py b/tests/endtoend/timer_functions/timer_functions_stein/function_app.py new file mode 100644 index 000000000..0cd7f8ee1 --- /dev/null +++ b/tests/endtoend/timer_functions/timer_functions_stein/function_app.py @@ -0,0 +1,16 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +import logging + +import azure.functions as func + +app = func.FunctionApp() + + +@app.function_name(name="mytimer") +@app.schedule(schedule="*/1 * * * * *", arg_name="mytimer", + run_on_startup=False, + use_monitor=False) +def mytimer(mytimer: func.TimerRequest) -> None: + logging.info("This timer trigger function executed successfully")