Skip to content

Commit 4cd388e

Browse files
authored
Merge branch 'dev' into evanroman/add-thread-local-context
2 parents be931e3 + 88ee3fb commit 4cd388e

File tree

5 files changed

+80
-18
lines changed

5 files changed

+80
-18
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ Here is the current status of Python in Azure Functions:
1414

1515
_What are the supported Python versions?_
1616

17-
| Azure Functions Runtime | Python 3.6 | Python 3.7 | Python 3.8 | Python 3.9 |
18-
|-------------------------|------------|------------|------------|------------|
19-
| Azure Functions 3.0 | ✓ | ✓ | ✓ | ✓ |
20-
| Azure Functions 4.0 | ✓ | ✓ | ✓ | ✓ |
17+
| Azure Functions Runtime | Python 3.6 | Python 3.7 | Python 3.8 | Python 3.9 | Python 3.10 | Python 3.11 |
18+
|-------------------------|--------|-------|-------|--------|--------------|-------------|
19+
| Azure Functions 3.0 | [EOL](https://learn.microsoft.com/azure/azure-functions/migrate-version-3-version-4)|[EOL](https://learn.microsoft.com/azure/azure-functions/migrate-version-3-version-4)|[EOL](https://learn.microsoft.com/azure/azure-functions/migrate-version-3-version-4)| [EOL](https://learn.microsoft.com/azure/azure-functions/migrate-version-3-version-4)| - |- |
20+
| Azure Functions 4.0 | ✓ | ✓ | ✓ | ✓ | ✓ | coming soon |
2121

2222
_What's available?_
2323
- Build, test, debug and publish using Azure Functions Core Tools (CLI) or Visual Studio Code

azure/functions/_http.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Licensed under the MIT License.
33

44
import collections.abc
5+
import http
56
import io
67
import json
78
import types
@@ -52,6 +53,7 @@ class HttpResponse(_abc.HttpResponse):
5253
5354
:param int status_code:
5455
Response status code. If not specified, defaults to 200.
56+
You can use an int status code or an http.HTTPStatus value
5557
5658
:param dict headers:
5759
An optional mapping containing response HTTP headers.
@@ -67,12 +69,16 @@ class HttpResponse(_abc.HttpResponse):
6769

6870
def __init__(self,
6971
body: typing.Optional[typing.Union[str, bytes]] = None, *,
70-
status_code: typing.Optional[int] = None,
72+
status_code: typing.Optional[typing.Union[
73+
http.HTTPStatus, int
74+
]] = None,
7175
headers: typing.Optional[typing.Mapping[str, str]] = None,
7276
mimetype: typing.Optional[str] = None,
7377
charset: typing.Optional[str] = None) -> None:
7478
if status_code is None:
7579
status_code = 200
80+
if isinstance(status_code, http.HTTPStatus):
81+
status_code = status_code.value
7682
self.__status_code = status_code
7783

7884
if mimetype is None:

azure/functions/decorators/function_app.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -399,14 +399,14 @@ def decorator():
399399

400400
return wrap
401401

402-
def schedule(self,
403-
arg_name: str,
404-
schedule: str,
405-
run_on_startup: Optional[bool] = None,
406-
use_monitor: Optional[bool] = None,
407-
data_type: Optional[Union[DataType, str]] = None,
408-
**kwargs: Any) -> Callable[..., Any]:
409-
"""The schedule decorator adds :class:`TimerTrigger` to the
402+
def timer_trigger(self,
403+
arg_name: str,
404+
schedule: str,
405+
run_on_startup: Optional[bool] = None,
406+
use_monitor: Optional[bool] = None,
407+
data_type: Optional[Union[DataType, str]] = None,
408+
**kwargs: Any) -> Callable[..., Any]:
409+
"""The schedule or timer decorator adds :class:`TimerTrigger` to the
410410
:class:`FunctionBuilder` object
411411
for building :class:`Function` object used in worker function
412412
indexing model. This is equivalent to defining TimerTrigger
@@ -448,6 +448,8 @@ def decorator():
448448

449449
return wrap
450450

451+
schedule = timer_trigger
452+
451453
def service_bus_queue_trigger(
452454
self,
453455
arg_name: str,

tests/decorators/test_decorators.py

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def dummy_func():
6565
self.assertTrue(isinstance(func.get_trigger(), HttpTrigger))
6666
self.assertTrue(func.get_trigger().route, "dummy")
6767

68-
def test_timer_trigger_default_args(self):
68+
def test_schedule_trigger_default_args(self):
6969
app = self.func_app
7070

7171
@app.schedule(arg_name="req", schedule="dummy_schedule")
@@ -86,7 +86,7 @@ def dummy_func():
8686
]
8787
})
8888

89-
def test_timer_trigger_full_args(self):
89+
def test_schedule_trigger_full_args(self):
9090
app = self.func_app
9191

9292
@app.schedule(arg_name="req", schedule="dummy_schedule",
@@ -112,6 +112,53 @@ def dummy():
112112
]
113113
})
114114

115+
def test_timer_trigger_default_args(self):
116+
app = self.func_app
117+
118+
@app.timer_trigger(arg_name="req", schedule="dummy_schedule")
119+
def dummy_func():
120+
pass
121+
122+
func = self._get_user_function(app)
123+
self.assertEqual(func.get_function_name(), "dummy_func")
124+
assert_json(self, func, {
125+
"scriptFile": "function_app.py",
126+
"bindings": [
127+
{
128+
"name": "req",
129+
"type": TIMER_TRIGGER,
130+
"direction": BindingDirection.IN,
131+
"schedule": "dummy_schedule"
132+
}
133+
]
134+
})
135+
136+
def test_timer_trigger_full_args(self):
137+
app = self.func_app
138+
139+
@app.timer_trigger(arg_name="req", schedule="dummy_schedule",
140+
run_on_startup=False, use_monitor=False,
141+
data_type=DataType.STRING, dummy_field='dummy')
142+
def dummy():
143+
pass
144+
145+
func = self._get_user_function(app)
146+
assert_json(self, func, {
147+
"scriptFile": "function_app.py",
148+
"bindings": [
149+
{
150+
"name": "req",
151+
"type": TIMER_TRIGGER,
152+
"dataType": DataType.STRING,
153+
"direction": BindingDirection.IN,
154+
'dummyField': 'dummy',
155+
"schedule": "dummy_schedule",
156+
"runOnStartup": False,
157+
"useMonitor": False
158+
}
159+
]
160+
})
161+
115162
def test_route_default_args(self):
116163
app = self.func_app
117164

tests/test_http.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
33
import sys
4+
import types
45
import unittest
6+
from http import HTTPStatus
57
from unittest import skipIf
6-
import types
8+
79
import azure.functions as func
810
import azure.functions.http as http
9-
from azure.functions._http import HttpResponseHeaders, HttpRequestHeaders
10-
11+
from azure.functions._http import HttpRequestHeaders, HttpResponseHeaders
1112
from azure.functions.meta import Datum
1213

1314

@@ -178,6 +179,12 @@ def test_http_response_does_not_have_explicit_output(self):
178179
getattr(http.HttpResponseConverter, 'has_implicit_output', None)
179180
)
180181

182+
def test_http_response_accepts_http_enums(self):
183+
response = func.HttpResponse(status_code=404)
184+
self.assertEquals(response.status_code, 404)
185+
response = func.HttpResponse(status_code=HTTPStatus.ACCEPTED)
186+
self.assertEquals(response.status_code, 202)
187+
181188
def test_http_request_converter_decode(self):
182189
data = {
183190
"method": Datum("POST", "string"),

0 commit comments

Comments
 (0)