Skip to content
This repository was archived by the owner on Sep 12, 2025. It is now read-only.

Commit 4d32f3a

Browse files
committed
Add function app which delegates requests to Flask
1 parent 28cd36e commit 4d32f3a

File tree

5 files changed

+57
-0
lines changed

5 files changed

+57
-0
lines changed

function_app.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import azure.functions as func
2+
from app import create_app
3+
4+
funcapp = func.FunctionApp()
5+
flaskapp = create_app()
6+
7+
8+
@funcapp.route(
9+
route="{*route}",
10+
auth_level=func.AuthLevel.ANONYMOUS,
11+
methods=[func.HttpMethod.GET, func.HttpMethod.POST],
12+
)
13+
def main(req: func.HttpRequest, context: func.Context) -> func.HttpResponse:
14+
return func.WsgiMiddleware(flaskapp.wsgi_app).handle(req, context)

host.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"version": "2.0",
3+
"extensionBundle": {
4+
"id": "Microsoft.Azure.Functions.ExtensionBundle",
5+
"version": "[4.*, 5.0.0)"
6+
}
7+
}

local.settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"IsEncrypted": false,
3+
"Values": {
4+
"FUNCTIONS_WORKER_RUNTIME": "python",
5+
"AzureWebJobsFeatureFlags": "EnableWorkerIndexing"
6+
}
7+
}

tests/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import os
2+
import sys
3+
4+
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
5+
sys.path.insert(0, os.path.dirname(SCRIPT_DIR) + "/../app/")

tests/unit/test_function_app.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from unittest.mock import MagicMock
2+
import azure.functions as func
3+
from function_app import main
4+
import json
5+
6+
7+
def test_function_app_calls_flask_app():
8+
"""Test that the function calls the flask app."""
9+
req = func.HttpRequest(
10+
method="GET",
11+
body=b"",
12+
url="/api/status/health-check",
13+
)
14+
mock_context = MagicMock(
15+
function_directory=".",
16+
invocation_id="123",
17+
function_name="Notify"
18+
)
19+
20+
func_call = main.build().get_user_function()
21+
resp = func_call(req, mock_context)
22+
23+
assert resp.status_code == 200
24+
assert json.loads(resp.get_body()) == {"status": "healthy"}

0 commit comments

Comments
 (0)