Skip to content

Commit 9b97a19

Browse files
committed
Added UT
1 parent a2e178b commit 9b97a19

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

azure_functions_worker/dispatcher.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,12 @@ def load_function_metadata(self, function_app_directory, caller_info):
383383
function_path = os.path.join(function_app_directory,
384384
script_file_name)
385385

386-
self._function_metadata_result = (
387-
self.index_functions(function_path, function_app_directory)) \
388-
if os.path.exists(function_path) else None
386+
if not os.path.exists(function_path):
387+
raise FileNotFoundError("function_app.py not "
388+
f"found in {function_path}")
389+
390+
self._function_metadata_result = self.index_functions(
391+
function_path, function_app_directory)
389392

390393
async def _handle__functions_metadata_request(self, request):
391394
metadata_request = request.functions_metadata_request

tests/unittests/test_dispatcher.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,34 @@ def test_functions_metadata_request_with_indexing_exception(
915915
metadata_response.function_metadata_response.result.status,
916916
protos.StatusResult.Failure)
917917

918+
@patch.dict(os.environ, {PYTHON_ENABLE_INIT_INDEXING: 'false'})
919+
def test_functions_metadata_request_with_filenotfound_exception(self):
920+
921+
request = protos.StreamingMessage(
922+
worker_init_request=protos.WorkerInitRequest(
923+
host_version="2.3.4",
924+
function_app_directory=str(FUNCTION_APP_DIRECTORY)
925+
)
926+
)
927+
928+
metadata_request = protos.StreamingMessage(
929+
functions_metadata_request=protos.FunctionsMetadataRequest(
930+
function_app_directory="NonExistentDirectory"
931+
)
932+
)
933+
934+
self.loop.run_until_complete(
935+
self.dispatcher._handle__worker_init_request(request))
936+
937+
metadata_response = self.loop.run_until_complete(
938+
self.dispatcher._handle__functions_metadata_request(
939+
metadata_request))
940+
941+
self.assertEqual(
942+
metadata_response.function_metadata_response.result.exception.message,
943+
"FileNotFoundError: function_app.py not "
944+
"found in NonExistentDirectory\\function_app.py")
945+
918946
@patch.dict(os.environ, {PYTHON_ENABLE_INIT_INDEXING: 'false'})
919947
def test_dispatcher_indexing_in_load_request(self):
920948
init_request = protos.StreamingMessage(

0 commit comments

Comments
 (0)