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

test: testing pipeline with snake case changes #1633

Draft
wants to merge 17 commits into
base: dev
Choose a base branch
from
13 changes: 13 additions & 0 deletions azure_functions_worker/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import inspect
import operator
import pathlib
import re
import typing
import uuid

Expand All @@ -11,6 +12,7 @@
from ._thirdparty import typing_inspect
from .constants import HTTP_TRIGGER
from .protos import BindingInfo
from .logging import logger


class ParamTypeInfo(typing.NamedTuple):
Expand Down Expand Up @@ -130,6 +132,15 @@ def is_context_required(params, bound_params: dict,
f'{ctx_anno!r}')
return requires_context

@staticmethod
def validate_arg_name(params: dict):
pattern = r'(^\d|\b\w*__\w*|\w{129,})'
for arg_name in params:
if re.search(pattern, arg_name):
logger.warning("Argument name %s is invalid. Please "
"ensure it does not contain '__', start with a digit, "
"or exceed 128 characters.", arg_name)

@staticmethod
def validate_function_params(params: dict, bound_params: dict,
annotations: dict, func_name: str):
Expand Down Expand Up @@ -389,6 +400,8 @@ def add_function(self, function_id: str,
annotations,
func_name)

self.validate_arg_name(params)

input_types, output_types, _ = self.validate_function_params(
params, bound_params, annotations, func_name)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,29 @@


@app.function_name(name="blob_trigger")
@app.blob_trigger(arg_name="file",
@app.blob_trigger(arg_name="file_snake",
path="python-worker-tests/test-blob-trigger.txt",
connection="AzureWebJobsStorage")
@app.blob_output(arg_name="$return",
path="python-worker-tests/test-blob-triggered.txt",
connection="AzureWebJobsStorage")
def blob_trigger(file: func.InputStream) -> str:
def blob_trigger(file_snake: func.InputStream) -> str:
return json.dumps({
'name': file.name,
'length': file.length,
'content': file.read().decode('utf-8')
'name': file_snake.name,
'length': file_snake.length,
'content': file_snake.read().decode('utf-8')
})


@app.function_name(name="get_blob_as_bytes")
@app.route(route="get_blob_as_bytes")
@app.blob_input(arg_name="file",
@app.blob_input(arg_name="file_snake",
path="python-worker-tests/test-bytes.txt",
data_type="BINARY",
connection="AzureWebJobsStorage")
def get_blob_as_bytes(req: func.HttpRequest, file: bytes) -> str:
assert isinstance(file, bytes)
return file.decode('utf-8')
def get_blob_as_bytes(req: func.HttpRequest, file_snake: bytes) -> str:
assert isinstance(file_snake, bytes)
return file_snake.decode('utf-8')


@app.function_name(name="get_blob_as_bytes_return_http_response")
Expand Down Expand Up @@ -189,13 +189,13 @@ def get_blob_triggered(req: func.HttpRequest, file: func.InputStream) -> str:


@app.function_name(name="put_blob_as_bytes_return_http_response")
@app.blob_output(arg_name="file",
@app.blob_output(arg_name="file_snake",
path="python-worker-tests/shmem-test-bytes-out.txt",
data_type="BINARY",
connection="AzureWebJobsStorage")
@app.route(route="put_blob_as_bytes_return_http_response")
def put_blob_as_bytes_return_http_response(req: func.HttpRequest,
file: func.Out[
file_snake: func.Out[
bytes]) -> func.HttpResponse:
"""
Write a blob (bytes) and respond back (in HTTP response) with the number of
Expand All @@ -214,7 +214,7 @@ def put_blob_as_bytes_return_http_response(req: func.HttpRequest,
content = bytearray(random.getrandbits(8) for _ in range(content_size))
content_sha256 = hashlib.sha256(content).hexdigest()

file.set(content)
file_snake.set(content)

response_dict = {
'content_size': content_size,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"type": "blobTrigger",
"direction": "in",
"name": "file",
"name": "file_snake",
"connection": "AzureWebJobsStorage",
"path": "python-worker-tests/test-blob-trigger.txt"
},
Expand Down
8 changes: 4 additions & 4 deletions tests/emulator_tests/blob_functions/blob_trigger/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import azure.functions as azf


def main(file: azf.InputStream) -> str:
def main(file_snake: azf.InputStream) -> str:
return json.dumps({
'name': file.name,
'length': file.length,
'content': file.read().decode('utf-8')
'name': file_snake.name,
'length': file_snake.length,
'content': file_snake.read().decode('utf-8')
})
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{
"type": "blob",
"direction": "in",
"name": "file",
"name": "file_snake",
"dataType": "binary",
"connection": "AzureWebJobsStorage",
"path": "python-worker-tests/test-bytes.txt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
import azure.functions as azf


def main(req: azf.HttpRequest, file: bytes) -> str:
assert isinstance(file, bytes)
return file.decode('utf-8')
def main(req: azf.HttpRequest, file_snake: bytes) -> str:
assert isinstance(file_snake, bytes)
return file_snake.decode('utf-8')
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{
"type": "blob",
"direction": "out",
"name": "file",
"name": "file_snake",
"dataType": "binary",
"connection": "AzureWebJobsStorage",
"path": "python-worker-tests/shmem-test-bytes-out.txt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import azure.functions as azf


def main(req: azf.HttpRequest, file: azf.Out[bytes]) -> azf.HttpResponse:
def main(req: azf.HttpRequest, file_snake: azf.Out[bytes]) -> azf.HttpResponse:
"""
Write a blob (bytes) and respond back (in HTTP response) with the number of
bytes written and the MD5 digest of the content.
Expand All @@ -26,7 +26,7 @@ def main(req: azf.HttpRequest, file: azf.Out[bytes]) -> azf.HttpResponse:
content = bytearray(random.getrandbits(8) for _ in range(content_size))
content_sha256 = hashlib.sha256(content).hexdigest()

file.set(content)
file_snake.set(content)

response_dict = {
'content_size': content_size,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@
# An HttpTrigger to generating EventHub event from EventHub Output Binding
@app.function_name(name="eventhub_output")
@app.route(route="eventhub_output")
@app.event_hub_output(arg_name="event",
@app.event_hub_output(arg_name="event_snake",
event_hub_name="python-worker-ci-eventhub-one",
connection="AzureWebJobsEventHubConnectionString")
def eventhub_output(req: func.HttpRequest, event: func.Out[str]):
event.set(req.get_body().decode('utf-8'))
def eventhub_output(req: func.HttpRequest, event_snake: func.Out[str]):
event_snake.set(req.get_body().decode('utf-8'))
return 'OK'


# This is an actual EventHub trigger which will convert the event data
# into a storage blob.
@app.function_name(name="eventhub_trigger")
@app.event_hub_message_trigger(arg_name="event",
@app.event_hub_message_trigger(arg_name="event_snake",
event_hub_name="python-worker-ci-eventhub-one",
connection="AzureWebJobsEventHubConnectionString"
)
@app.blob_output(arg_name="$return",
path="python-worker-tests/test-eventhub-triggered.txt",
connection="AzureWebJobsStorage")
def eventhub_trigger(event: func.EventHubEvent) -> bytes:
return event.get_body()
def eventhub_trigger(event_snake: func.EventHubEvent) -> bytes:
return event_snake.get_body()


# Retrieve the event data from storage blob and return it as Http response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


# An HttpTrigger to generating EventHub event from EventHub Output Binding
def main(req: func.HttpRequest, event: func.Out[str]):
event.set(req.get_body().decode('utf-8'))
def main(req: func.HttpRequest, event_snake: func.Out[str]):
event_snake.set(req.get_body().decode('utf-8'))

return 'OK'
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
{
"type": "eventHub",
"name": "event",
"name": "event_snake",
"direction": "out",
"eventHubName": "python-worker-ci-eventhub-one",
"connection": "AzureWebJobsEventHubConnectionString"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@

# This is an actual EventHub trigger which will convert the event data
# into a storage blob.
def main(event: func.EventHubEvent) -> bytes:
return event.get_body()
def main(event_snake: func.EventHubEvent) -> bytes:
return event_snake.get_body()
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"bindings": [
{
"type": "eventHubTrigger",
"name": "event",
"name": "event_snake",
"direction": "in",
"eventHubName": "python-worker-ci-eventhub-one",
"connection": "AzureWebJobsEventHubConnectionString"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
{
"direction": "out",
"name": "msg",
"name": "msg_snake",
"queueName": "testqueue",
"connection": "AzureWebJobsStorage",
"type": "queue"
Expand Down
4 changes: 2 additions & 2 deletions tests/emulator_tests/queue_functions/put_queue/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import azure.functions as azf


def main(req: azf.HttpRequest, msg: azf.Out[str]):
msg.set(req.get_body())
def main(req: azf.HttpRequest, msg_snake: azf.Out[str]):
msg_snake.set(req.get_body())

return 'OK'
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ def get_queue_untyped_blob_return(req: func.HttpRequest,

@app.function_name(name="put_queue")
@app.route(route="put_queue")
@app.queue_output(arg_name="msg",
@app.queue_output(arg_name="msg_snake",
connection="AzureWebJobsStorage",
queue_name="testqueue")
def put_queue(req: func.HttpRequest, msg: func.Out[str]):
msg.set(req.get_body())
def put_queue(req: func.HttpRequest, msg_snake: func.Out[str]):
msg_snake.set(req.get_body())

return 'OK'

Expand Down Expand Up @@ -110,24 +110,24 @@ def put_queue_untyped_return(req: func.HttpRequest,


@app.function_name(name="queue_trigger")
@app.queue_trigger(arg_name="msg",
@app.queue_trigger(arg_name="msg_snake",
queue_name="testqueue",
connection="AzureWebJobsStorage")
@app.blob_output(arg_name="$return",
connection="AzureWebJobsStorage",
path="python-worker-tests/test-queue-blob.txt")
def queue_trigger(msg: func.QueueMessage) -> str:
def queue_trigger(msg_snake: func.QueueMessage) -> str:
result = json.dumps({
'id': msg.id,
'body': msg.get_body().decode('utf-8'),
'expiration_time': (msg.expiration_time.isoformat()
if msg.expiration_time else None),
'insertion_time': (msg.insertion_time.isoformat()
if msg.insertion_time else None),
'time_next_visible': (msg.time_next_visible.isoformat()
if msg.time_next_visible else None),
'pop_receipt': msg.pop_receipt,
'dequeue_count': msg.dequeue_count
'id': msg_snake.id,
'body': msg_snake.get_body().decode('utf-8'),
'expiration_time': (msg_snake.expiration_time.isoformat()
if msg_snake.expiration_time else None),
'insertion_time': (msg_snake.insertion_time.isoformat()
if msg_snake.insertion_time else None),
'time_next_visible': (msg_snake.time_next_visible.isoformat()
if msg_snake.time_next_visible else None),
'pop_receipt': msg_snake.pop_receipt,
'dequeue_count': msg_snake.dequeue_count
})

return result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"type": "queueTrigger",
"direction": "in",
"name": "msg",
"name": "msg_snake",
"queueName": "testqueue",
"connection": "AzureWebJobsStorage",
},
Expand Down
22 changes: 11 additions & 11 deletions tests/emulator_tests/queue_functions/queue_trigger/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
import azure.functions as azf


def main(msg: azf.QueueMessage) -> str:
def main(msg_snake: azf.QueueMessage) -> str:
result = json.dumps({
'id': msg.id,
'body': msg.get_body().decode('utf-8'),
'expiration_time': (msg.expiration_time.isoformat()
if msg.expiration_time else None),
'insertion_time': (msg.insertion_time.isoformat()
if msg.insertion_time else None),
'time_next_visible': (msg.time_next_visible.isoformat()
if msg.time_next_visible else None),
'pop_receipt': msg.pop_receipt,
'dequeue_count': msg.dequeue_count
'id': msg_snake.id,
'body': msg_snake.get_body().decode('utf-8'),
'expiration_time': (msg_snake.expiration_time.isoformat()
if msg_snake.expiration_time else None),
'insertion_time': (msg_snake.insertion_time.isoformat()
if msg_snake.insertion_time else None),
'time_next_visible': (msg_snake.time_next_visible.isoformat()
if msg_snake.time_next_visible else None),
'pop_receipt': msg_snake.pop_receipt,
'dequeue_count': msg_snake.dequeue_count
})

return result
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import azure.functions as azf


def main(req: azf.HttpRequest, msg: azf.Out[str]):
msg.set(req.get_body().decode('utf-8'))
def main(req: azf.HttpRequest, msg_snake: azf.Out[str]):
msg_snake.set(req.get_body().decode('utf-8'))

return 'OK'
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
{
"direction": "out",
"name": "msg",
"name": "msg_snake",
"queueName": "testqueue",
"connection": "AzureWebJobsServiceBusConnectionString",
"type": "serviceBus"
Expand Down
Loading
Loading