-
Notifications
You must be signed in to change notification settings - Fork 107
test: add ServiceBus SDK tests #1678
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
base: dev
Are you sure you want to change the base?
Changes from all commits
9f91548
43e4b4f
b43cd48
b1d88ee
f92b5a2
3078d4d
a6b1d0d
ab038f4
fad1242
d30a219
a3cf630
4ade5eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,7 +79,8 @@ dev = [ | |
"numpy", | ||
"pre-commit", | ||
"invoke", | ||
"cryptography" | ||
"cryptography", | ||
"jsonpickle" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added |
||
] | ||
test-http-v2 = [ | ||
"azurefunctions-extensions-http-fastapi==1.0.0b2", | ||
|
@@ -88,7 +89,8 @@ test-http-v2 = [ | |
] | ||
test-deferred-bindings = [ | ||
"azurefunctions-extensions-bindings-blob==1.0.0b3", | ||
"azurefunctions-extensions-bindings-eventhub==1.0.0b1" | ||
"azurefunctions-extensions-bindings-eventhub==1.0.0b1", | ||
"azurefunctions-extensions-bindings-servicebus==1.0.0b1" | ||
] | ||
|
||
[build-system] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import json | ||
import jsonpickle | ||
|
||
import azure.functions as func | ||
import azurefunctions.extensions.bindings.servicebus as sb | ||
|
||
app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS) | ||
|
||
|
||
@app.route(route="put_message_sdk") | ||
@app.service_bus_queue_output( | ||
arg_name="msg", | ||
connection="AzureWebJobsServiceBusSDKConnectionString", | ||
queue_name="testqueue") | ||
def put_message_sdk(req: func.HttpRequest, msg: func.Out[str]): | ||
msg.set(req.get_body().decode('utf-8')) | ||
return 'OK' | ||
|
||
|
||
@app.route(route="get_servicebus_triggered_sdk") | ||
@app.blob_input(arg_name="file", | ||
path="python-worker-tests/test-servicebus-sdk-triggered.txt", | ||
connection="AzureWebJobsStorage") | ||
def get_servicebus_triggered_sdk(req: func.HttpRequest, | ||
file: func.InputStream) -> str: | ||
return func.HttpResponse( | ||
file.read().decode('utf-8'), mimetype='application/json') | ||
|
||
|
||
@app.service_bus_queue_trigger( | ||
arg_name="msg", | ||
connection="AzureWebJobsServiceBusSDKConnectionString", | ||
queue_name="testqueue") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add a test for SB topics? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the extension support topics? |
||
@app.blob_output(arg_name="$return", | ||
path="python-worker-tests/test-servicebus-sdk-triggered.txt", | ||
connection="AzureWebJobsStorage") | ||
def servicebus_trigger_sdk(msg: sb.ServiceBusReceivedMessage) -> str: | ||
msg_json = jsonpickle.encode(msg) | ||
body_json = jsonpickle.encode(msg.body) | ||
enqueued_time_json = jsonpickle.encode(msg.enqueued_time_utc) | ||
lock_token_json = jsonpickle.encode(msg.lock_token) | ||
result = json.dumps({ | ||
'message': msg_json, | ||
'body': body_json, | ||
'enqueued_time_utc': enqueued_time_json, | ||
'lock_token': lock_token_json, | ||
'message_id': msg.message_id, | ||
'sequence_number': msg.sequence_number | ||
}) | ||
|
||
return result | ||
|
||
|
||
@app.route(route="put_message_sdk_topic") | ||
@app.service_bus_topic_output(arg_name="msg", | ||
connection="AzureWebJobsServiceBusSDKConnectionString", | ||
topic_name="testtopic") | ||
def put_message_sdk_topic(req: func.HttpRequest, msg: func.Out[str]): | ||
msg.set(req.get_body().decode('utf-8')) | ||
return 'OK' | ||
|
||
|
||
@app.route(route="get_servicebus_triggered_sdk_topic") | ||
@app.blob_input(arg_name="file", | ||
path="python-worker-tests/test-servicebus-sdk-triggered-topic.txt", | ||
connection="AzureWebJobsStorage") | ||
def get_servicebus_triggered_sdk_topic(req: func.HttpRequest, | ||
file: func.InputStream) -> str: | ||
return func.HttpResponse( | ||
file.read().decode('utf-8'), mimetype='application/json') | ||
|
||
|
||
@app.service_bus_topic_trigger(arg_name="msg", | ||
topic_name="testtopic", | ||
connection="AzureWebJobsServiceBusSDKConnectionString", | ||
subscription_name="testsub") | ||
@app.blob_output(arg_name="$return", | ||
path="python-worker-tests/test-servicebus-sdk-triggered-topic.txt", | ||
connection="AzureWebJobsStorage") | ||
def servicebus_trigger_sdk_topic(msg: sb.ServiceBusReceivedMessage) -> str: | ||
msg_json = jsonpickle.encode(msg) | ||
body_json = jsonpickle.encode(msg.body) | ||
enqueued_time_json = jsonpickle.encode(msg.enqueued_time_utc) | ||
lock_token_json = jsonpickle.encode(msg.lock_token) | ||
result = json.dumps({ | ||
'message': msg_json, | ||
'body': body_json, | ||
'enqueued_time_utc': enqueued_time_json, | ||
'lock_token': lock_token_json, | ||
'message_id': msg.message_id, | ||
'sequence_number': msg.sequence_number | ||
}) | ||
|
||
return result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for the
extension_tests
folder anymore -- blob SDK bindings tests are moved to emulators folder, and HttpV2 moved to E2E