Skip to content

Commit a616373

Browse files
author
Victoria Hall
committed
blueprint tests
1 parent 55fc46d commit a616373

File tree

5 files changed

+70
-0
lines changed

5 files changed

+70
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import logging
2+
import time
3+
from datetime import datetime
4+
5+
import azure.functions as func
6+
7+
bp = func.Blueprint()
8+
9+
10+
@bp.route(route="default_template")
11+
def default_template(req: func.HttpRequest) -> func.HttpResponse:
12+
logging.info('Python HTTP trigger function processed a request.')
13+
14+
name = req.params.get('name')
15+
if not name:
16+
try:
17+
req_body = req.get_json()
18+
except ValueError:
19+
pass
20+
else:
21+
name = req_body.get('name')
22+
23+
if name:
24+
return func.HttpResponse(
25+
f"Hello, {name}. This HTTP triggered function "
26+
f"executed successfully.")
27+
else:
28+
return func.HttpResponse(
29+
"This HTTP triggered function executed successfully. "
30+
"Pass a name in the query string or in the request body for a"
31+
" personalized response.",
32+
status_code=200
33+
)
34+
35+
36+
@bp.route(route="http_func")
37+
def http_func(req: func.HttpRequest) -> func.HttpResponse:
38+
time.sleep(1)
39+
40+
current_time = datetime.now().strftime("%H:%M:%S")
41+
return func.HttpResponse(f"{current_time}")
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import azure.functions as func
2+
from blueprint_directory.blueprint import bp
3+
4+
app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS)
5+
6+
app.register_functions(bp)

tests/endtoend/test_blueprint_functions.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,17 @@ def test_only_blueprint(self):
5353
"""
5454
r = self.webhost.request('GET', 'default_template')
5555
self.assertEqual(r.status_code, 404)
56+
57+
58+
class TestBlueprintDifferentDirectory(testutils.WebHostTestCase):
59+
@classmethod
60+
def get_script_dir(cls):
61+
return testutils.E2E_TESTS_FOLDER / 'blueprint_functions' / \
62+
'blueprint_different_dir'
63+
64+
def test_blueprint_in_different_dir(self):
65+
r = self.webhost.request('GET', 'default_template')
66+
self.assertTrue(r.ok)
67+
68+
r = self.webhost.request('GET', 'http_func')
69+
self.assertTrue(r.ok)

tests/endtoend/test_worker_process_count_functions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,11 @@ class TestWorkerProcessCountWithBlueprintStein(TestWorkerProcessCount):
7171
def get_script_dir(cls):
7272
return testutils.E2E_TESTS_FOLDER / 'blueprint_functions' /\
7373
'functions_in_blueprint_only'
74+
75+
76+
class TestWorkerProcessCountWithBlueprintDiffDirStein(TestWorkerProcessCount):
77+
78+
@classmethod
79+
def get_script_dir(cls):
80+
return testutils.E2E_TESTS_FOLDER / 'blueprint_functions' /\
81+
'blueprint_different_dir'

tests/unittests/test_enable_debug_logging_functions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def tearDownClass(cls):
3838
def get_script_dir(cls):
3939
return testutils.UNIT_TESTS_FOLDER / 'log_filtering_functions'
4040

41+
@testutils.retryable_test(4, 5)
4142
def test_debug_logging_enabled(self):
4243
"""
4344
Verify when cx debug logging is enabled, cx function debug logs

0 commit comments

Comments
 (0)