You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following example shows a SQL input binding in a function.json file and a Python function that is [triggered by an HTTP](./functions-bindings-http-webhook-trigger.md)reques. It executes a stored procedure with input from the HTTP request query parameter.
984
+
The following example shows a SQL input binding in a function.json file and a Python function that is [triggered by an HTTP](./functions-bindings-http-webhook-trigger.md)request. It executes a stored procedure with input from the HTTP request query parameter.
985
985
986
986
The stored procedure `dbo.DeleteToDo` must be created on the database. In this example, the stored procedure deletes a single record or all records depending on the value of the parameter.
987
987
@@ -1078,7 +1078,7 @@ The [C# library](functions-dotnet-class-library.md) uses the [SqlAttribute](http
1078
1078
|**CommandText**| Required. The Transact-SQL query command or name of the stored procedure executed by the binding. |
1079
1079
|**ConnectionStringSetting**| Required. The name of an app setting that contains the connection string for the database against which the query or stored procedure is being executed. This value isn't the actual connection string and must instead resolve to an environment variable name. |
1080
1080
|**CommandType**| Required. A [CommandType](/dotnet/api/system.data.commandtype) value, which is [Text](/dotnet/api/system.data.commandtype#fields) for a query and [StoredProcedure](/dotnet/api/system.data.commandtype#fields) for a stored procedure. |
1081
-
|**Parameters**| Optional. Zero or more parameter values passed to the command during execution as a single string. Must follow the format `@param1=param1,@param2=param2`. Neither the parameter name nor the parameter value can contain a comma (`,`) or an equals sign (`=`). |
1081
+
|**Parameters**| Optional. Zero or more parameter values passed to the command during execution as a single string. Must follow the format `@param1=param1,@param2=param2`. The parameter name and the parameter value cannot contain a comma (`,`) or an equals sign (`=`). |
1082
1082
1083
1083
::: zone-end
1084
1084
@@ -1093,7 +1093,7 @@ In the [Java functions runtime library](/java/api/overview/azure/functions/runti
1093
1093
|**connectionStringSetting**| Required. The name of an app setting that contains the connection string for the database against which the query or stored procedure is being executed. This value isn't the actual connection string and must instead resolve to an environment variable name. |
1094
1094
|**commandType**| Required. A [CommandType](/dotnet/api/system.data.commandtype) value, which is ["Text"](/dotnet/api/system.data.commandtype#fields) for a query and ["StoredProcedure"](/dotnet/api/system.data.commandtype#fields) for a stored procedure. |
1095
1095
|**name**| Required. The unique name of the function binding. |
1096
-
|**parameters**| Optional. Zero or more parameter values passed to the command during execution as a single string. Must follow the format `@param1=param1,@param2=param2`. Neither the parameter name nor the parameter value can contain a comma (`,`) or an equals sign (`=`). |
1096
+
|**parameters**| Optional. Zero or more parameter values passed to the command during execution as a single string. Must follow the format `@param1=param1,@param2=param2`. The parameter name and the parameter value cannot contain a comma (`,`) or an equals sign (`=`). |
1097
1097
1098
1098
::: zone-end
1099
1099
::: zone pivot="programming-language-javascript,programming-language-typescript"
@@ -1109,7 +1109,7 @@ The following table explains the properties that you can set on the `options` ob
1109
1109
|**commandText**| Required. The Transact-SQL query command or name of the stored procedure executed by the binding. |
1110
1110
|**connectionStringSetting**| Required. The name of an app setting that contains the connection string for the database against which the query or stored procedure is being executed. This value isn't the actual connection string and must instead resolve to an environment variable name. Optional keywords in the connection string value are [available to refine SQL bindings connectivity](./functions-bindings-azure-sql.md#sql-connection-string). |
1111
1111
|**commandType**| Required. A [CommandType](/dotnet/api/system.data.commandtype) value, which is [Text](/dotnet/api/system.data.commandtype#fields) for a query and [StoredProcedure](/dotnet/api/system.data.commandtype#fields) for a stored procedure. |
1112
-
|**parameters**| Optional. Zero or more parameter values passed to the command during execution as a single string. Must follow the format `@param1=param1,@param2=param2`. Neither the parameter name nor the parameter value can contain a comma (`,`) or an equals sign (`=`). |
1112
+
|**parameters**| Optional. Zero or more parameter values passed to the command during execution as a single string. Must follow the format `@param1=param1,@param2=param2`. The parameter name and the parameter value cannot contain a comma (`,`) or an equals sign (`=`). |
1113
1113
1114
1114
# [Model v3](#tab/nodejs-v3)
1115
1115
@@ -1123,7 +1123,7 @@ The following table explains the binding configuration properties that you set i
1123
1123
|**commandText**| Required. The Transact-SQL query command or name of the stored procedure executed by the binding. |
1124
1124
|**connectionStringSetting**| Required. The name of an app setting that contains the connection string for the database against which the query or stored procedure is being executed. This value isn't the actual connection string and must instead resolve to an environment variable name. Optional keywords in the connection string value are [available to refine SQL bindings connectivity](./functions-bindings-azure-sql.md#sql-connection-string). |
1125
1125
|**commandType**| Required. A [CommandType](/dotnet/api/system.data.commandtype) value, which is [Text](/dotnet/api/system.data.commandtype#fields) for a query and [StoredProcedure](/dotnet/api/system.data.commandtype#fields) for a stored procedure. |
1126
-
|**parameters**| Optional. Zero or more parameter values passed to the command during execution as a single string. Must follow the format `@param1=param1,@param2=param2`. Neither the parameter name nor the parameter value can contain a comma (`,`) or an equals sign (`=`). |
1126
+
|**parameters**| Optional. Zero or more parameter values passed to the command during execution as a single string. Must follow the format `@param1=param1,@param2=param2`. The parameter name and the parameter value cannot contain a comma (`,`) or an equals sign (`=`). |
1127
1127
1128
1128
---
1129
1129
@@ -1141,7 +1141,7 @@ The following table explains the binding configuration properties that you set i
1141
1141
|**commandText**| Required. The Transact-SQL query command or name of the stored procedure executed by the binding. |
1142
1142
|**connectionStringSetting**| Required. The name of an app setting that contains the connection string for the database against which the query or stored procedure is being executed. This value isn't the actual connection string and must instead resolve to an environment variable name. Optional keywords in the connection string value are [available to refine SQL bindings connectivity](./functions-bindings-azure-sql.md#sql-connection-string). |
1143
1143
|**commandType**| Required. A [CommandType](/dotnet/api/system.data.commandtype) value, which is [Text](/dotnet/api/system.data.commandtype#fields) for a query and [StoredProcedure](/dotnet/api/system.data.commandtype#fields) for a stored procedure. |
1144
-
|**parameters**| Optional. Zero or more parameter values passed to the command during execution as a single string. Must follow the format `@param1=param1,@param2=param2`. Neither the parameter name nor the parameter value can contain a comma (`,`) or an equals sign (`=`). |
1144
+
|**parameters**| Optional. Zero or more parameter values passed to the command during execution as a single string. Must follow the format `@param1=param1,@param2=param2`. The parameter name and the parameter value cannot contain a comma (`,`) or an equals sign (`=`). |
1145
1145
::: zone-end
1146
1146
1147
1147
@@ -1155,7 +1155,7 @@ The binding definition includes the SQL command text, the command type, paramete
1155
1155
1156
1156
Queries executed by the input binding are [parameterized](/dotnet/api/microsoft.data.sqlclient.sqlparameter) in Microsoft.Data.SqlClient to reduce the risk of [SQL injection](/sql/relational-databases/security/sql-injection) from the parameter values passed into the binding.
1157
1157
1158
-
If an exception occurs when a SQL input binding is executed then the function code won't execute. This may result in an error code being returned, such as an HTTP trigger returning a 500 error code.
1158
+
If an exception occurs when a SQL input binding is executed, then the function code does not execute. This behavior may result in an error code being returned, such as an HTTP trigger returning a 500 error code.
Remember to replace `<APP_NAME>` with the name of your function app in Azure.
1176
1176
1177
1177
## Unit testing
1178
+
### Unit testing through pytest
1178
1179
1179
1180
Functions that are written in Python can be tested like other Python code by using standard testing frameworks. For most bindings, it's possible to create a mock input object by creating an instance of an appropriate class from the `azure.functions` package. Since the [`azure.functions`](https://pypi.org/project/azure-functions/) package isn't immediately available, be sure to install it via your *requirements.txt* file as described in the [package management](#package-management) section above.
1180
1181
@@ -1340,6 +1341,24 @@ class TestFunction(unittest.TestCase):
1340
1341
1341
1342
Inside your *.venv* Python virtual environment folder, install your favorite Python test framework, such as `pip install pytest`. Then run `pytest tests` to check the test result.
1342
1343
1344
+
### Unit testing by invoking the function directly
1345
+
With `azure-functions >= 1.21.0`, functions can also be called directly using the Python interpreter. This example shows how to unit test an HTTP trigger using the v2 programming model:
Note that with this approach, no additional package or setup is required. The function can be tested by calling `python function_app.py`, and it results in `Hello, World!` output in the terminal.
0 commit comments