Skip to content

Commit d82e3cb

Browse files
pdthummarYunchuWang
authored andcommitted
added E2E pystein and generic binding tests.
1 parent c7a5236 commit d82e3cb

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
import json
4+
import uuid
5+
import azure.functions as func
6+
7+
app = func.FunctionApp()
8+
9+
10+
@app.function_name(name="table_in_binding")
11+
@app.route(route="table_in_binding/{id}")
12+
@app.read_table(arg_name="testEntity",
13+
connection="AzureWebJobsStorage",
14+
table_name="BindingTestTable",
15+
row_key='{id}',
16+
partition_key="test")
17+
def table_in_binding(req: func.HttpRequest, testEntity):
18+
headers_dict = json.loads(testEntity)
19+
return func.HttpResponse(status_code=200, headers=headers_dict)
20+
21+
22+
@app.function_name(name="table_out_binding")
23+
@app.route(route="table_out_binding", binding_arg_name="resp")
24+
@app.write_table(arg_name="$return",
25+
connection="AzureWebJobsStorage",
26+
table_name="BindingTestTable")
27+
def table_out_binding(req: func.HttpRequest, resp: func.Out[func.HttpResponse]):
28+
row_key_uuid = str(uuid.uuid4())
29+
table_dict = {'PartitionKey': 'test', 'RowKey': row_key_uuid}
30+
table_json = json.dumps(table_dict)
31+
http_resp = func.HttpResponse(status_code=200, headers=table_dict)
32+
resp.set(http_resp)
33+
return table_json
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
import json
4+
import uuid
5+
import azure.functions as func
6+
7+
app = func.FunctionApp()
8+
9+
10+
@app.function_name(name="table_in_binding")
11+
@app.generic_trigger(arg_name="req", type="httpTrigger",
12+
route="table_in_binding/{id}")
13+
@app.generic_output_binding(arg_name="$return", type="http")
14+
@app.generic_input_binding(
15+
arg_name="testEntity",
16+
type="table",
17+
connection="AzureWebJobsStorage",
18+
table_name="BindingTestTable",
19+
row_key="{id}",
20+
partition_key="test")
21+
def table_in_binding(req: func.HttpRequest, testEntity):
22+
headers_dict = json.loads(testEntity)
23+
return func.HttpResponse(status_code=200, headers=headers_dict)
24+
25+
26+
@app.function_name(name="table_out_binding")
27+
@app.generic_trigger(arg_name="req", type="httpTrigger",
28+
route="table_out_binding")
29+
@app.generic_output_binding(arg_name="resp", type="http")
30+
@app.generic_output_binding(
31+
arg_name="$return",
32+
type="table",
33+
connection="AzureWebJobsStorage",
34+
table_name="BindingTestTable")
35+
def table_out_binding(req: func.HttpRequest, resp: func.Out[func.HttpResponse]):
36+
row_key_uuid = str(uuid.uuid4())
37+
table_dict = {'PartitionKey': 'test', 'RowKey': row_key_uuid}
38+
table_json = json.dumps(table_dict)
39+
http_resp = func.HttpResponse(status_code=200, headers=table_dict)
40+
resp.set(http_resp)
41+
return table_json

tests/endtoend/test_table_functions.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,30 @@ def test_table_bindings(self):
3737
self.assertEqual(in_resp.status_code, 200)
3838
in_row_key = in_resp.headers['rowKey']
3939
self.assertEqual(in_row_key, row_key)
40+
41+
42+
class TestTableFunctionsStein(testutils.WebHostTestCase):
43+
44+
@classmethod
45+
def get_script_dir(cls):
46+
return testutils.E2E_TESTS_FOLDER / 'table_functions' / \
47+
'table_functions_stein'
48+
49+
@testutils.retryable_test(3, 5)
50+
def test_table_bindings(self):
51+
out_resp = self.webhost.request('POST', 'table_out_binding')
52+
self.assertEqual(out_resp.status_code, 200)
53+
row_key = out_resp.headers['rowKey']
54+
55+
in_resp = self.webhost.request('GET', f'table_in_binding/{row_key}')
56+
self.assertEqual(in_resp.status_code, 200)
57+
in_row_key = in_resp.headers['rowKey']
58+
self.assertEqual(in_row_key, row_key)
59+
60+
61+
class TestTableFunctionsGeneric(TestTableFunctionsStein):
62+
63+
@classmethod
64+
def get_script_dir(cls):
65+
return testutils.E2E_TESTS_FOLDER / 'table_functions' / \
66+
'table_functions_stein' / 'generic'

0 commit comments

Comments
 (0)