Skip to content
Open
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 azure/functions/decorators/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class HttpMethod(StringifyEnum):
PATCH = "PATCH"
PUT = "PUT"
OPTIONS = "OPTIONS"
QUERY = "QUERY"


class HttpTrigger(Trigger):
Expand Down
30 changes: 30 additions & 0 deletions tests/decorators/test_function_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,36 @@ def test_add_trigger(self):
f"is {trigger1} and New trigger "
f"being added is {trigger2}")

def test_function_creation_with_query_method_trigger(self):
output = HttpOutput(name="out", data_type=DataType.UNDEFINED)
trigger = HttpTrigger(name="req",
methods=(HttpMethod.QUERY,),
data_type=DataType.UNDEFINED,
auth_level=AuthLevel.ANONYMOUS, route="dummy")
self.func.add_binding(output)
self.func.add_trigger(trigger)

assert_json(self, self.func, {"scriptFile": "dummy.py",
"bindings": [
{
"type": HTTP_OUTPUT,
"direction":
BindingDirection.OUT,
"name": "out",
"dataType": DataType.UNDEFINED
},
{
"authLevel": AuthLevel.ANONYMOUS,
"type": HTTP_TRIGGER,
"direction": BindingDirection.IN,
"name": "req",
"dataType": DataType.UNDEFINED,
"route": "dummy",
"methods": [HttpMethod.QUERY]
}
]
})

def test_function_creation_with_binding_and_trigger(self):
output = HttpOutput(name="out", data_type=DataType.UNDEFINED)
trigger = HttpTrigger(name="req",
Expand Down
2 changes: 1 addition & 1 deletion tests/decorators/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_http_method_enum(self):
self.assertEqual([e for e in HttpMethod],
[HttpMethod.GET, HttpMethod.POST, HttpMethod.DELETE,
HttpMethod.HEAD, HttpMethod.PATCH, HttpMethod.PUT,
HttpMethod.OPTIONS])
HttpMethod.OPTIONS, HttpMethod.QUERY])

def test_http_trigger_valid_creation_with_methods(self):
http_trigger = HttpTrigger(name='req',
Expand Down
17 changes: 17 additions & 0 deletions tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,23 @@ def test_http_request_converter_decode(self):
"dummy_params_key": "dummy_params_value"}))
self.assertEqual(http_request.get_body(), b"test_body")

def test_http_request_converter_decode_query_method(self):
data = {
"method": Datum("QUERY", "string"),
"url": Datum("www.dummy.com/products", "string"),
"headers": {'Content-Type': Datum("application/json", "string")},
"query": {},
"params": {},
"body": Datum('{"category": "laptops"}', "string")
}
datum = Datum(data, "http")

http_request = http.HttpRequestConverter.decode(
data=datum, trigger_metadata={})

self.assertEqual(http_request.method, "QUERY")
self.assertEqual(http_request.get_body(), b'{"category": "laptops"}')

def test_http_with_bytes_data(self):
data = (
b"--foo\r\n"
Expand Down
3 changes: 2 additions & 1 deletion tests/test_http_asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ async def __call__(self, scope, receive, send):
assert scope['http_version'] in ['1.0', '1.1', '2']
assert isinstance(scope['http_version'], str)

assert scope['method'] in ['POST', 'GET', 'PUT', 'DELETE', 'PATCH']
assert scope['method'] in ['POST', 'GET', 'PUT', 'DELETE', 'PATCH',
'QUERY']
assert isinstance(scope['method'], str)

assert scope['scheme'] in ['http', 'https']
Expand Down