Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import json
import uuid
import azure.functions as func

app = func.FunctionApp()


@app.function_name(name="table_in_binding")
@app.route(route="table_in_binding/{id}")
@app.read_table(arg_name="testEntity",
connection="AzureWebJobsStorage",
table_name="BindingTestTable",
row_key='{id}',
partition_key="test")
def table_in_binding(req: func.HttpRequest, testEntity):
headers_dict = json.loads(testEntity)
return func.HttpResponse(status_code=200, headers=headers_dict)


@app.function_name(name="table_out_binding")
@app.route(route="table_out_binding", binding_arg_name="resp")
@app.write_table(arg_name="$return",
connection="AzureWebJobsStorage",
table_name="BindingTestTable")
def table_out_binding(req: func.HttpRequest, resp: func.Out[func.HttpResponse]):
row_key_uuid = str(uuid.uuid4())
table_dict = {'PartitionKey': 'test', 'RowKey': row_key_uuid}
table_json = json.dumps(table_dict)
http_resp = func.HttpResponse(status_code=200, headers=table_dict)
resp.set(http_resp)
return table_json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import json
import uuid
import azure.functions as func

app = func.FunctionApp()


@app.function_name(name="table_in_binding")
@app.generic_trigger(arg_name="req", type="httpTrigger",
route="table_in_binding/{id}")
@app.generic_output_binding(arg_name="$return", type="http")
@app.generic_input_binding(
arg_name="testEntity",
type="table",
connection="AzureWebJobsStorage",
table_name="BindingTestTable",
row_key="{id}",
partition_key="test")
def table_in_binding(req: func.HttpRequest, testEntity):
headers_dict = json.loads(testEntity)
return func.HttpResponse(status_code=200, headers=headers_dict)


@app.function_name(name="table_out_binding")
@app.generic_trigger(arg_name="req", type="httpTrigger",
route="table_out_binding")
@app.generic_output_binding(arg_name="resp", type="http")
@app.generic_output_binding(
arg_name="$return",
type="table",
connection="AzureWebJobsStorage",
table_name="BindingTestTable")
def table_out_binding(req: func.HttpRequest, resp: func.Out[func.HttpResponse]):
row_key_uuid = str(uuid.uuid4())
table_dict = {'PartitionKey': 'test', 'RowKey': row_key_uuid}
table_json = json.dumps(table_dict)
http_resp = func.HttpResponse(status_code=200, headers=table_dict)
resp.set(http_resp)
return table_json
27 changes: 27 additions & 0 deletions tests/endtoend/test_table_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,30 @@ def test_table_bindings(self):
self.assertEqual(in_resp.status_code, 200)
in_row_key = in_resp.headers['rowKey']
self.assertEqual(in_row_key, row_key)


class TestTableFunctionsStein(testutils.WebHostTestCase):

@classmethod
def get_script_dir(cls):
return testutils.E2E_TESTS_FOLDER / 'table_functions' / \
'table_functions_stein'

@testutils.retryable_test(3, 5)
def test_table_bindings(self):
out_resp = self.webhost.request('POST', 'table_out_binding')
self.assertEqual(out_resp.status_code, 200)
row_key = out_resp.headers['rowKey']

in_resp = self.webhost.request('GET', f'table_in_binding/{row_key}')
self.assertEqual(in_resp.status_code, 200)
in_row_key = in_resp.headers['rowKey']
self.assertEqual(in_row_key, row_key)


class TestTableFunctionsGeneric(TestTableFunctionsStein):

@classmethod
def get_script_dir(cls):
return testutils.E2E_TESTS_FOLDER / 'table_functions' / \
'table_functions_stein' / 'generic'