Skip to content

Commit 1b8d87f

Browse files
committed
Merge branch 'wangbill/enable-dep-logging-filtering-v2' of https://github.com/Azure/azure-functions-python-worker into wangbill/enable-dep-logging-filtering-v2
2 parents 35e8834 + 285bf69 commit 1b8d87f

File tree

5 files changed

+83
-2
lines changed

5 files changed

+83
-2
lines changed

tests/endtoend/test_http_functions.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ def test_function_index_page_should_return_ok(self):
3939
"""The index page of Azure Functions should return OK in any
4040
circumstances
4141
"""
42-
root_url = self.webhost._addr
43-
r = requests.get(root_url, timeout=REQUEST_TIMEOUT_SEC)
42+
r = self.webhost.request('GET', '', no_prefix=True,
43+
timeout=REQUEST_TIMEOUT_SEC)
4444
self.assertTrue(r.ok)
4545

4646
@testutils.retryable_test(3, 5)
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
import time
4+
import typing
5+
from tests.utils import testutils
6+
7+
REQUEST_TIMEOUT_SEC = 5
8+
9+
10+
class TestTimerFunctions(testutils.WebHostTestCase):
11+
"""Test the Timer in the local webhost.
12+
13+
This test class will spawn a webhost from your <project_root>/build/webhost
14+
folder and replace the built-in Python with azure_functions_worker from
15+
your code base. Since the Timer Trigger is a native support from host, we
16+
don't need to setup any external resources.
17+
18+
Compared to the unittests/test_timer_functions.py, this file is more focus
19+
on testing the E2E flow scenarios.
20+
"""
21+
22+
@classmethod
23+
def get_script_dir(cls):
24+
return testutils.E2E_TESTS_FOLDER / 'timer_functions'
25+
26+
def test_timer(self):
27+
time.sleep(1)
28+
# Checking webhost status.
29+
r = self.webhost.request('GET', '', no_prefix=True,
30+
timeout=REQUEST_TIMEOUT_SEC)
31+
self.assertTrue(r.ok)
32+
33+
def check_log_timer(self, host_out: typing.List[str]):
34+
self.assertEqual(host_out.count("This timer trigger function executed "
35+
"successfully"), 1)
36+
37+
38+
class TestTimerFunctionsStein(TestTimerFunctions):
39+
40+
@classmethod
41+
def get_script_dir(cls):
42+
return testutils.E2E_TESTS_FOLDER / 'timer_functions' / \
43+
'timer_functions_stein'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
import logging
5+
6+
import azure.functions as func
7+
8+
9+
def main(mytimer: func.TimerRequest) -> None:
10+
logging.info("This timer trigger function executed successfully")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"scriptFile": "__init__.py",
3+
"bindings": [
4+
{
5+
"name": "mytimer",
6+
"type": "timerTrigger",
7+
"direction": "in",
8+
"schedule": "*/1 * * * * *",
9+
"runOnStartup": false
10+
}
11+
]
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
import logging
5+
6+
import azure.functions as func
7+
8+
app = func.FunctionApp()
9+
10+
11+
@app.function_name(name="mytimer")
12+
@app.schedule(schedule="*/1 * * * * *", arg_name="mytimer",
13+
run_on_startup=False,
14+
use_monitor=False)
15+
def mytimer(mytimer: func.TimerRequest) -> None:
16+
logging.info("This timer trigger function executed successfully")

0 commit comments

Comments
 (0)