Skip to content

Commit 74aea84

Browse files
Add SQL Bindings end to end test (#1026)
* add sql bindings e2e test * update test * add sql bindings e2e test * update test * fix sql binding test * add python310 sql connection string * fix unit tests * fix sql end to end test Co-authored-by: gavin-aguiar <[email protected]>
1 parent 068fbf8 commit 74aea84

File tree

10 files changed

+122
-0
lines changed

10 files changed

+122
-0
lines changed

.ci/e2e_integration_test/pipeline.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ steps:
4242
AzureWebJobsCosmosDBConnectionString: $(AzureWebJobsCosmosDBConnectionString)
4343
AzureWebJobsEventHubConnectionString: $(AzureWebJobsEventHubConnectionString)
4444
AzureWebJobsServiceBusConnectionString: $(AzureWebJobsServiceBusConnectionString)
45+
AzureWebJobsSqlConnectionString: $(AzureWebJobsSqlConnectionString)
4546
AzureWebJobsEventGridTopicUri: $(AzureWebJobsEventGridTopicUri)
4647
AzureWebJobsEventGridConnectionKey: $(AzureWebJobsEventGridConnectionKey)
4748
PythonVersion: $(PYTHON_VERSION)

.ci/linux_devops_e2e_tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export AzureWebJobsStorage=$LINUXSTORAGECONNECTIONSTRING
55
export AzureWebJobsCosmosDBConnectionString=$LINUXCOSMOSDBCONNECTIONSTRING
66
export AzureWebJobsEventHubConnectionString=$LINUXEVENTHUBCONNECTIONSTRING
77
export AzureWebJobsServiceBusConnectionString=$LINUXSERVICEBUSCONNECTIONSTRING
8+
export AzureWebJobsSqlConnectionString=$LINUXSQLCONNECTIONSTRING
89
export AzureWebJobsEventGridTopicUri=$LINUXEVENTGRIDTOPICURI
910
export AzureWebJobsEventGridConnectionKey=$LINUXEVENTGRIDTOPICCONNECTIONKEY
1011

.github/workflows/ci_e2e_workflow.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ jobs:
7676
AzureWebJobsCosmosDBConnectionString: ${{ secrets.LinuxCosmosDBConnectionString36 }}
7777
AzureWebJobsEventHubConnectionString: ${{ secrets.LinuxEventHubConnectionString36 }}
7878
AzureWebJobsServiceBusConnectionString: ${{ secrets.LinuxServiceBusConnectionString36 }}
79+
AzureWebJobsSqlConnectionString: ${{ secrets.LinuxSqlConnectionString36 }}
7980
AzureWebJobsEventGridTopicUri: ${{ secrets.LinuxEventGridTopicUriString36 }}
8081
AzureWebJobsEventGridConnectionKey: ${{ secrets.LinuxEventGridConnectionKeyString36 }}
8182
run: |
@@ -87,6 +88,7 @@ jobs:
8788
AzureWebJobsCosmosDBConnectionString: ${{ secrets.LinuxCosmosDBConnectionString37 }}
8889
AzureWebJobsEventHubConnectionString: ${{ secrets.LinuxEventHubConnectionString37 }}
8990
AzureWebJobsServiceBusConnectionString: ${{ secrets.LinuxServiceBusConnectionString37 }}
91+
AzureWebJobsSqlConnectionString: ${{ secrets.LinuxSqlConnectionString37 }}
9092
AzureWebJobsEventGridTopicUri: ${{ secrets.LinuxEventGridTopicUriString37 }}
9193
AzureWebJobsEventGridConnectionKey: ${{ secrets.LinuxEventGridConnectionKeyString37 }}
9294
run: |
@@ -98,6 +100,7 @@ jobs:
98100
AzureWebJobsCosmosDBConnectionString: ${{ secrets.LinuxCosmosDBConnectionString38 }}
99101
AzureWebJobsEventHubConnectionString: ${{ secrets.LinuxEventHubConnectionString38 }}
100102
AzureWebJobsServiceBusConnectionString: ${{ secrets.LinuxServiceBusConnectionString38 }}
103+
AzureWebJobsSqlConnectionString: ${{ secrets.LinuxSqlConnectionString38 }}
101104
AzureWebJobsEventGridTopicUri: ${{ secrets.LinuxEventGridTopicUriString38 }}
102105
AzureWebJobsEventGridConnectionKey: ${{ secrets.LinuxEventGridConnectionKeyString38 }}
103106
run: |
@@ -109,6 +112,7 @@ jobs:
109112
AzureWebJobsCosmosDBConnectionString: ${{ secrets.LinuxCosmosDBConnectionString39 }}
110113
AzureWebJobsEventHubConnectionString: ${{ secrets.LinuxEventHubConnectionString39 }}
111114
AzureWebJobsServiceBusConnectionString: ${{ secrets.LinuxServiceBusConnectionString39 }}
115+
AzureWebJobsSqlConnectionString: ${{ secrets.LinuxSqlConnectionString39 }}
112116
AzureWebJobsEventGridTopicUri: ${{ secrets.LinuxEventGridTopicUriString39 }}
113117
AzureWebJobsEventGridConnectionKey: ${{ secrets.LinuxEventGridConnectionKeyString39 }}
114118
run: |
@@ -120,6 +124,7 @@ jobs:
120124
AzureWebJobsCosmosDBConnectionString: ${{ secrets.LinuxCosmosDBConnectionString310 }}
121125
AzureWebJobsEventHubConnectionString: ${{ secrets.LinuxEventHubConnectionString310 }}
122126
AzureWebJobsServiceBusConnectionString: ${{ secrets.LinuxServiceBusConnectionString310 }}
127+
AzureWebJobsSqlConnectionString: ${{ secrets.LinuxSqlConnectionString310 }}
123128
AzureWebJobsEventGridTopicUri: ${{ secrets.LinuxEventGridTopicUriString310 }}
124129
AzureWebJobsEventGridConnectionKey: ${{ secrets.LinuxEventGridConnectionKeyString310 }}
125130
run: |

azure_functions_worker/testutils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,10 @@ def popen_webhost(*, stdout, stderr, script_root=FUNCS_PATH, port=None):
878878
if servicebus:
879879
extra_env['AzureWebJobsServiceBusConnectionString'] = servicebus
880880

881+
sql = testconfig['azure'].get('sql_key')
882+
if sql:
883+
extra_env['AzureWebJobsSqlConnectionString'] = sql
884+
881885
eventgrid_topic_uri = testconfig['azure'].get('eventgrid_topic_uri')
882886
if eventgrid_topic_uri:
883887
extra_env['AzureWebJobsEventGridTopicUri'] = eventgrid_topic_uri

setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
Version="4.0.5" />
5151
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus"
5252
Version="4.2.1" />
53+
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Sql"
54+
Version="0.1.346-preview" />
5355
<PackageReference
5456
Include="Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator"
5557
Version="1.1.3" />
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
import json
5+
import azure.functions as func
6+
7+
8+
def main(req: func.HttpRequest, products: func.SqlRowList) -> func.HttpResponse:
9+
rows = list(map(lambda r: json.loads(r.to_json()), products))
10+
11+
return func.HttpResponse(
12+
json.dumps(rows),
13+
status_code=200,
14+
mimetype="application/json"
15+
)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"scriptFile": "__init__.py",
3+
"bindings": [
4+
{
5+
"authLevel": "function",
6+
"name": "req",
7+
"type": "httpTrigger",
8+
"direction": "in",
9+
"methods": [
10+
"get"
11+
]
12+
},
13+
{
14+
"name": "$return",
15+
"type": "http",
16+
"direction": "out"
17+
},
18+
{
19+
"name": "products",
20+
"type": "sql",
21+
"direction": "in",
22+
"commandText": "SELECT * FROM Products",
23+
"commandType": "Text",
24+
"connectionStringSetting": "AzureWebJobsSqlConnectionString"
25+
}
26+
]
27+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
import json
5+
import azure.functions as func
6+
7+
8+
def main(req: func.HttpRequest, r: func.Out[func.SqlRow]) -> func.HttpResponse:
9+
body = json.loads(req.get_body())
10+
row = func.SqlRow.from_dict(body)
11+
r.set(row)
12+
13+
return func.HttpResponse(
14+
body=req.get_body(),
15+
status_code=201,
16+
mimetype="application/json"
17+
)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"scriptFile": "__init__.py",
3+
"bindings": [
4+
{
5+
"authLevel": "function",
6+
"name": "req",
7+
"type": "httpTrigger",
8+
"direction": "in",
9+
"methods": [
10+
"post"
11+
]
12+
},
13+
{
14+
"name": "$return",
15+
"type": "http",
16+
"direction": "out"
17+
},
18+
{
19+
"name": "r",
20+
"type": "sql",
21+
"direction": "out",
22+
"commandText": "[dbo].[Products]",
23+
"connectionStringSetting": "AzureWebJobsSqlConnectionString"
24+
}
25+
]
26+
}

tests/endtoend/test_sql_functions.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
import json
4+
5+
from azure_functions_worker import testutils
6+
7+
8+
class TestSqlFunctions(testutils.WebHostTestCase):
9+
10+
@classmethod
11+
def get_script_dir(cls):
12+
return testutils.E2E_TESTS_FOLDER / 'sql_functions'
13+
14+
@testutils.retryable_test(3, 5)
15+
def test_sql_output_and_input(self):
16+
row = {"ProductId": 0, "Name": "test", "Cost": 100}
17+
r = self.webhost.request('POST', 'sql_output',
18+
data=json.dumps(row))
19+
self.assertEqual(r.status_code, 201)
20+
21+
r = self.webhost.request('GET', 'sql_input')
22+
self.assertEqual(r.status_code, 200)
23+
expectedText = "[{\"ProductId\": 0, \"Name\": \"test\", \"Cost\": 100}]"
24+
self.assertEqual(r.text, expectedText)

0 commit comments

Comments
 (0)