Skip to content

Commit d3d0dd4

Browse files
author
Victoria Hall
committed
refactor debug logging unit tests
1 parent 3eccfc2 commit d3d0dd4

File tree

7 files changed

+75
-3
lines changed

7 files changed

+75
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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(http_auth_level=func.AuthLevel.ANONYMOUS)
9+
10+
11+
@app.route(route="debug_logging")
12+
def default_template(req: func.HttpRequest):
13+
logging.info('logging info', exc_info=True)
14+
logging.warning('logging warning', exc_info=True)
15+
logging.debug('logging debug', exc_info=True)
16+
logging.error('logging error', exc_info=True)
17+
return 'OK-debug'

tests/unittests/test_enable_debug_logging_functions.py renamed to tests/endtoend/test_debug_logging_functions.py

+24-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def tearDownClass(cls):
3838

3939
@classmethod
4040
def get_script_dir(cls):
41-
return testutils.UNIT_TESTS_FOLDER / 'log_filtering_functions'
41+
return testutils.E2E_TESTS_FOLDER / 'debug_logging_functions'
4242

4343
def test_debug_logging_enabled(self):
4444
"""
@@ -72,7 +72,7 @@ def tearDownClass(cls):
7272

7373
@classmethod
7474
def get_script_dir(cls):
75-
return testutils.UNIT_TESTS_FOLDER / 'log_filtering_functions'
75+
return testutils.E2E_TESTS_FOLDER / 'debug_logging_functions'
7676

7777
def test_debug_logging_disabled(self):
7878
"""
@@ -115,7 +115,7 @@ def tearDownClass(cls):
115115

116116
@classmethod
117117
def get_script_dir(cls):
118-
return testutils.UNIT_TESTS_FOLDER / 'log_filtering_functions'
118+
return testutils.E2E_TESTS_FOLDER / 'debug_logging_functions'
119119

120120
def test_debug_logging_filtered(self):
121121
"""
@@ -131,3 +131,24 @@ def check_log_debug_logging_filtered(self, host_out: typing.List[str]):
131131
self.assertIn('logging warning', host_out)
132132
self.assertNotIn('logging debug', host_out)
133133
self.assertIn('logging error', host_out)
134+
135+
136+
class TestDebugLoggingEnabledFunctionsStein(TestDebugLoggingEnabledFunctions):
137+
138+
@classmethod
139+
def get_script_dir(cls):
140+
return testutils.E2E_TESTS_FOLDER / 'debug_logging_functions_stein'
141+
142+
143+
class TestDebugLoggingDisabledFunctionsStein(TestDebugLoggingDisabledFunctions):
144+
145+
@classmethod
146+
def get_script_dir(cls):
147+
return testutils.E2E_TESTS_FOLDER / 'debug_logging_functions_stein'
148+
149+
150+
class TestDebugLogEnabledHostFilteringFunctionsStein(TestDebugLogEnabledHostFilteringFunctions): # noqa
151+
152+
@classmethod
153+
def get_script_dir(cls):
154+
return testutils.E2E_TESTS_FOLDER / 'debug_logging_functions_stein'

tests/extension_tests/deferred_bindings_tests/deferred_bindings_blob_functions/function_app.py

+9
Original file line numberDiff line numberDiff line change
@@ -267,3 +267,12 @@ def blob_cache(req: func.HttpRequest,
267267
def invalid_connection_info(req: func.HttpRequest,
268268
client: blob.BlobClient) -> str:
269269
return client.download_blob(encoding='utf-8').readall()
270+
271+
272+
@app.function_name(name="nonexistent_blob")
273+
@app.route(route="nonexistent_blob")
274+
@app.blob_input(arg_name="client",
275+
path="python-worker-tests/nonexistent-file.txt",
276+
connection="AzureWebJobsStorage")
277+
def nonexistent_blob(req: func.HttpRequest, client: blob.BlobClient) -> str:
278+
return client.download_blob(encoding='utf-8').readall()

tests/extension_tests/deferred_bindings_tests/test_deferred_bindings.py

+21
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,27 @@ def test_deferred_bindings_enabled_decode(self):
157157

158158
self.assertIsNotNone(obj)
159159

160+
def test_deferred_bindings_enabled_decode_failed(self):
161+
binding = BlobClientConverter
162+
pb = protos.ParameterBinding(name='test',
163+
data=protos.TypedData(
164+
string='test'))
165+
sample_mbd = MockMBD(version="1.0",
166+
source="AzureStorageBlobs",
167+
content_type="application/json",
168+
content="{\"Connection\":\"NotARealConnectionString\","
169+
"\"ContainerName\":"
170+
"\"python-worker-tests\","
171+
"\"BlobName\":"
172+
"\"nonexistent-blob.txt\"}")
173+
datum = datumdef.Datum(value=sample_mbd, type='model_binding_data')
174+
175+
with self.assertRaises(AttributeError):
176+
# Decode will fail here because the connection string does not exist
177+
meta.deferred_bindings_decode(binding=binding, pb=pb,
178+
pytype=BlobClient, datum=datum,
179+
metadata={})
180+
160181
async def test_check_deferred_bindings_enabled(self):
161182
"""
162183
check_deferred_bindings_enabled checks if deferred bindings is enabled at fx

tests/extension_tests/deferred_bindings_tests/test_deferred_bindings_blob_functions.py

+4
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,7 @@ def test_failed_client_creation(self):
190190
# Without the http_v2_enabled default definition, this request would time out.
191191
# Instead, it fails immediately
192192
self.assertEqual(r.status_code, 500)
193+
194+
def test_nonexistent_blob(self):
195+
r = self.webhost.request('GET', 'nonexistent_blob')
196+
self.assertEqual(r.status_code, 500)

0 commit comments

Comments
 (0)