Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SQL Bindings end to end test #1026

Merged
merged 15 commits into from
Jul 28, 2022
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
1 change: 1 addition & 0 deletions .ci/e2e_integration_test/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ steps:
AzureWebJobsCosmosDBConnectionString: $(AzureWebJobsCosmosDBConnectionString)
AzureWebJobsEventHubConnectionString: $(AzureWebJobsEventHubConnectionString)
AzureWebJobsServiceBusConnectionString: $(AzureWebJobsServiceBusConnectionString)
AzureWebJobsSqlConnectionString: $(AzureWebJobsSqlConnectionString)
AzureWebJobsEventGridTopicUri: $(AzureWebJobsEventGridTopicUri)
AzureWebJobsEventGridConnectionKey: $(AzureWebJobsEventGridConnectionKey)
PythonVersion: $(PYTHON_VERSION)
Expand Down
1 change: 1 addition & 0 deletions .ci/linux_devops_e2e_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export AzureWebJobsStorage=$LINUXSTORAGECONNECTIONSTRING
export AzureWebJobsCosmosDBConnectionString=$LINUXCOSMOSDBCONNECTIONSTRING
export AzureWebJobsEventHubConnectionString=$LINUXEVENTHUBCONNECTIONSTRING
export AzureWebJobsServiceBusConnectionString=$LINUXSERVICEBUSCONNECTIONSTRING
export AzureWebJobsSqlConnectionString=$LINUXSQLCONNECTIONSTRING
export AzureWebJobsEventGridTopicUri=$LINUXEVENTGRIDTOPICURI
export AzureWebJobsEventGridConnectionKey=$LINUXEVENTGRIDTOPICCONNECTIONKEY

Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/ci_e2e_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ jobs:
AzureWebJobsCosmosDBConnectionString: ${{ secrets.LinuxCosmosDBConnectionString36 }}
AzureWebJobsEventHubConnectionString: ${{ secrets.LinuxEventHubConnectionString36 }}
AzureWebJobsServiceBusConnectionString: ${{ secrets.LinuxServiceBusConnectionString36 }}
AzureWebJobsSqlConnectionString: ${{ secrets.LinuxSqlConnectionString36 }}
AzureWebJobsEventGridTopicUri: ${{ secrets.LinuxEventGridTopicUriString36 }}
AzureWebJobsEventGridConnectionKey: ${{ secrets.LinuxEventGridConnectionKeyString36 }}
run: |
Expand All @@ -87,6 +88,7 @@ jobs:
AzureWebJobsCosmosDBConnectionString: ${{ secrets.LinuxCosmosDBConnectionString37 }}
AzureWebJobsEventHubConnectionString: ${{ secrets.LinuxEventHubConnectionString37 }}
AzureWebJobsServiceBusConnectionString: ${{ secrets.LinuxServiceBusConnectionString37 }}
AzureWebJobsSqlConnectionString: ${{ secrets.LinuxSqlConnectionString37 }}
AzureWebJobsEventGridTopicUri: ${{ secrets.LinuxEventGridTopicUriString37 }}
AzureWebJobsEventGridConnectionKey: ${{ secrets.LinuxEventGridConnectionKeyString37 }}
run: |
Expand All @@ -98,6 +100,7 @@ jobs:
AzureWebJobsCosmosDBConnectionString: ${{ secrets.LinuxCosmosDBConnectionString38 }}
AzureWebJobsEventHubConnectionString: ${{ secrets.LinuxEventHubConnectionString38 }}
AzureWebJobsServiceBusConnectionString: ${{ secrets.LinuxServiceBusConnectionString38 }}
AzureWebJobsSqlConnectionString: ${{ secrets.LinuxSqlConnectionString38 }}
AzureWebJobsEventGridTopicUri: ${{ secrets.LinuxEventGridTopicUriString38 }}
AzureWebJobsEventGridConnectionKey: ${{ secrets.LinuxEventGridConnectionKeyString38 }}
run: |
Expand All @@ -109,6 +112,7 @@ jobs:
AzureWebJobsCosmosDBConnectionString: ${{ secrets.LinuxCosmosDBConnectionString39 }}
AzureWebJobsEventHubConnectionString: ${{ secrets.LinuxEventHubConnectionString39 }}
AzureWebJobsServiceBusConnectionString: ${{ secrets.LinuxServiceBusConnectionString39 }}
AzureWebJobsSqlConnectionString: ${{ secrets.LinuxSqlConnectionString39 }}
lucyzhang929 marked this conversation as resolved.
Show resolved Hide resolved
AzureWebJobsEventGridTopicUri: ${{ secrets.LinuxEventGridTopicUriString39 }}
AzureWebJobsEventGridConnectionKey: ${{ secrets.LinuxEventGridConnectionKeyString39 }}
run: |
Expand All @@ -120,6 +124,7 @@ jobs:
AzureWebJobsCosmosDBConnectionString: ${{ secrets.LinuxCosmosDBConnectionString310 }}
AzureWebJobsEventHubConnectionString: ${{ secrets.LinuxEventHubConnectionString310 }}
AzureWebJobsServiceBusConnectionString: ${{ secrets.LinuxServiceBusConnectionString310 }}
AzureWebJobsSqlConnectionString: ${{ secrets.LinuxSqlConnectionString310 }}
AzureWebJobsEventGridTopicUri: ${{ secrets.LinuxEventGridTopicUriString310 }}
AzureWebJobsEventGridConnectionKey: ${{ secrets.LinuxEventGridConnectionKeyString310 }}
run: |
Expand Down
4 changes: 4 additions & 0 deletions azure_functions_worker/testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,10 @@ def popen_webhost(*, stdout, stderr, script_root=FUNCS_PATH, port=None):
if servicebus:
extra_env['AzureWebJobsServiceBusConnectionString'] = servicebus

sql = testconfig['azure'].get('sql_key')
if sql:
extra_env['AzureWebJobsSqlConnectionString'] = sql

eventgrid_topic_uri = testconfig['azure'].get('eventgrid_topic_uri')
if eventgrid_topic_uri:
extra_env['AzureWebJobsEventGridTopicUri'] = eventgrid_topic_uri
Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
Version="4.0.5" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus"
Version="4.2.1" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Sql"
Version="0.1.346-preview" />
<PackageReference
Include="Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator"
Version="1.1.3" />
Expand Down
15 changes: 15 additions & 0 deletions tests/endtoend/sql_functions/sql_input/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

import json
import azure.functions as func


def main(req: func.HttpRequest, products: func.SqlRowList) -> func.HttpResponse:
rows = list(map(lambda r: json.loads(r.to_json()), products))

return func.HttpResponse(
json.dumps(rows),
status_code=200,
mimetype="application/json"
)
27 changes: 27 additions & 0 deletions tests/endtoend/sql_functions/sql_input/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"scriptFile": "__init__.py",
"bindings": [
{
"authLevel": "function",
"name": "req",
"type": "httpTrigger",
"direction": "in",
"methods": [
"get"
]
},
{
"name": "$return",
"type": "http",
"direction": "out"
},
{
"name": "products",
"type": "sql",
"direction": "in",
"commandText": "SELECT * FROM Products",
"commandType": "Text",
"connectionStringSetting": "AzureWebJobsSqlConnectionString"
}
]
}
17 changes: 17 additions & 0 deletions tests/endtoend/sql_functions/sql_output/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

import json
import azure.functions as func


def main(req: func.HttpRequest, r: func.Out[func.SqlRow]) -> func.HttpResponse:
body = json.loads(req.get_body())
row = func.SqlRow.from_dict(body)
r.set(row)

return func.HttpResponse(
body=req.get_body(),
status_code=201,
mimetype="application/json"
)
26 changes: 26 additions & 0 deletions tests/endtoend/sql_functions/sql_output/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"scriptFile": "__init__.py",
"bindings": [
{
"authLevel": "function",
"name": "req",
"type": "httpTrigger",
"direction": "in",
"methods": [
"post"
]
},
{
"name": "$return",
"type": "http",
"direction": "out"
},
{
"name": "r",
"type": "sql",
"direction": "out",
"commandText": "[dbo].[Products]",
"connectionStringSetting": "AzureWebJobsSqlConnectionString"
}
]
}
24 changes: 24 additions & 0 deletions tests/endtoend/test_sql_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import json

from azure_functions_worker import testutils


class TestSqlFunctions(testutils.WebHostTestCase):

@classmethod
def get_script_dir(cls):
return testutils.E2E_TESTS_FOLDER / 'sql_functions'

@testutils.retryable_test(3, 5)
def test_sql_output_and_input(self):
row = {"ProductId": 0, "Name": "test", "Cost": 100}
r = self.webhost.request('POST', 'sql_output',
data=json.dumps(row))
self.assertEqual(r.status_code, 201)

r = self.webhost.request('GET', 'sql_input')
self.assertEqual(r.status_code, 200)
expectedText = "[{\"ProductId\": 0, \"Name\": \"test\", \"Cost\": 100}]"
self.assertEqual(r.text, expectedText)