diff --git a/tests/endtoend/http_functions/http_functions_stein/generic/function_app.py b/tests/endtoend/http_functions/http_functions_stein/generic/function_app.py new file mode 100644 index 000000000..c5d690ffc --- /dev/null +++ b/tests/endtoend/http_functions/http_functions_stein/generic/function_app.py @@ -0,0 +1,38 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +import logging + +import azure.functions as func + +app = func.FunctionApp() + + +@app.function_name(name="default_template") +@app.generic_trigger(arg_name="req", + type="httpTrigger", + route="default_template") +@app.generic_output_binding(arg_name="$return", type="http") +def default_template(req: func.HttpRequest) -> func.HttpResponse: + logging.info('Python HTTP trigger function processed a request.') + + name = req.params.get('name') + if not name: + try: + req_body = req.get_json() + except ValueError: + pass + else: + name = req_body.get('name') + + if name: + return func.HttpResponse( + f"Hello, {name}. This HTTP triggered function " + f"executed successfully.") + else: + return func.HttpResponse( + "This HTTP triggered function executed successfully. " + "Pass a name in the query string or in the request body for a" + " personalized response.", + status_code=200 + ) diff --git a/tests/endtoend/servicebus_functions/servicebus_functions_stein/generic/function_app.py b/tests/endtoend/servicebus_functions/servicebus_functions_stein/generic/function_app.py new file mode 100644 index 000000000..1be5c2a08 --- /dev/null +++ b/tests/endtoend/servicebus_functions/servicebus_functions_stein/generic/function_app.py @@ -0,0 +1,63 @@ +import json + +import azure.functions as func + +app = func.FunctionApp() + + +@app.function_name(name="put_message") +@app.generic_trigger(arg_name="req", type="httpTrigger", route="put_message") +@app.generic_output_binding(arg_name="msg", + type="serviceBus", + connection="AzureWebJobsServiceBusConnectionString", + queue_name="testqueue") +@app.generic_output_binding(arg_name="$return", type="http") +def put_message(req: func.HttpRequest, msg: func.Out[str]): + msg.set(req.get_body().decode('utf-8')) + return 'OK' + + +@app.function_name(name="get_servicebus_triggered") +@app.generic_trigger(arg_name="req", type="httpTrigger", + route="get_servicebus_triggered") +@app.generic_input_binding(arg_name="file", + type="blob", + path="python-worker-tests/test-servicebus-triggered.txt", # NoQA + connection="AzureWebJobsStorage") +@app.generic_output_binding(arg_name="$return", type="http") +def get_servicebus_triggered(req: func.HttpRequest, + file: func.InputStream) -> str: + return func.HttpResponse( + file.read().decode('utf-8'), mimetype='application/json') + + +@app.generic_trigger( + arg_name="msg", + type="serviceBusTrigger", + connection="AzureWebJobsServiceBusConnectionString", + queue_name="testqueue") +@app.generic_output_binding(arg_name="$return", + path="python-worker-tests/test-servicebus-triggered.txt", # NoQA + type="blob", + connection="AzureWebJobsStorage") +def servicebus_trigger(msg: func.ServiceBusMessage) -> str: + result = json.dumps({ + 'message_id': msg.message_id, + 'body': msg.get_body().decode('utf-8'), + 'content_type': msg.content_type, + 'delivery_count': msg.delivery_count, + 'expiration_time': (msg.expiration_time.isoformat() if + msg.expiration_time else None), + 'label': msg.label, + 'partition_key': msg.partition_key, + 'reply_to': msg.reply_to, + 'reply_to_session_id': msg.reply_to_session_id, + 'scheduled_enqueue_time': (msg.scheduled_enqueue_time.isoformat() if + msg.scheduled_enqueue_time else None), + 'session_id': msg.session_id, + 'time_to_live': msg.time_to_live, + 'to': msg.to, + 'user_properties': msg.user_properties, + }) + + return result diff --git a/tests/endtoend/test_http_functions.py b/tests/endtoend/test_http_functions.py index e324c583b..649a0b332 100644 --- a/tests/endtoend/test_http_functions.py +++ b/tests/endtoend/test_http_functions.py @@ -114,3 +114,12 @@ class TestHttpFunctionsStein(TestHttpFunctions): def get_script_dir(cls): return testutils.E2E_TESTS_FOLDER / 'http_functions' /\ 'http_functions_stein' + + +class TestHttpFunctionsSteinGeneric(TestHttpFunctions): + + @classmethod + def get_script_dir(cls): + return testutils.E2E_TESTS_FOLDER / 'http_functions' /\ + 'http_functions_stein' /\ + 'generic' diff --git a/tests/endtoend/test_servicebus_functions.py b/tests/endtoend/test_servicebus_functions.py index 8a9caa785..90626e27f 100644 --- a/tests/endtoend/test_servicebus_functions.py +++ b/tests/endtoend/test_servicebus_functions.py @@ -44,3 +44,12 @@ class TestServiceBusFunctionsStein(TestServiceBusFunctions): def get_script_dir(cls): return testutils.E2E_TESTS_FOLDER / 'servicebus_functions' / \ 'servicebus_functions_stein' + + +class TestServiceBusFunctionsSteinGeneric(TestServiceBusFunctions): + + @classmethod + def get_script_dir(cls): + return testutils.E2E_TESTS_FOLDER / 'servicebus_functions' / \ + 'servicebus_functions_stein' / \ + 'generic'