Skip to content

Commit f5d41ec

Browse files
Gavin AguiarGavin Aguiar
authored andcommitted
Minor fixes and refactoring
1 parent 5fe55b9 commit f5d41ec

File tree

5 files changed

+113
-10
lines changed

5 files changed

+113
-10
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
import azure.functions as func
4+
5+
app = func.FunctionApp()
6+
7+
8+
@app.route()
9+
@app.cosmos_db_input_v3(
10+
arg_name="docs", database_name="test",
11+
collection_name="items",
12+
id="cosmosdb-input-test",
13+
connection_string_setting="AzureWebJobsCosmosDBConnectionString")
14+
def cosmosdb_input(req: func.HttpRequest, docs: func.DocumentList) -> str:
15+
return func.HttpResponse(docs[0].to_json(), mimetype='application/json')
16+
17+
18+
@app.cosmos_db_trigger_v3(
19+
arg_name="docs", database_name="test",
20+
collection_name="items",
21+
lease_collection_name="leases",
22+
connection_string_setting="AzureWebJobsCosmosDBConnectionString",
23+
create_lease_collection_if_not_exists=True)
24+
@app.blob_output(arg_name="$return", connection="AzureWebJobsStorage",
25+
path="python-worker-tests/test-cosmosdb-triggered.txt")
26+
def cosmosdb_trigger(docs: func.DocumentList) -> str:
27+
return docs[0].to_json()
28+
29+
30+
@app.route()
31+
@app.blob_input(arg_name="file", connection="AzureWebJobsStorage",
32+
path="python-worker-tests/test-cosmosdb-triggered.txt")
33+
def get_cosmosdb_triggered(req: func.HttpRequest,
34+
file: func.InputStream) -> str:
35+
return file.read().decode('utf-8')
36+
37+
38+
@app.route()
39+
@app.cosmos_db_output_v3(
40+
arg_name="doc", database_name="test",
41+
collection_name="items",
42+
create_if_not_exists=True,
43+
connection_string_setting="AzureWebJobsCosmosDBConnectionString")
44+
def put_document(req: func.HttpRequest, doc: func.Out[func.Document]):
45+
doc.set(func.Document.from_json(req.get_body()))
46+
47+
return 'OK'
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
import azure.functions as func
4+
5+
app = func.FunctionApp()
6+
7+
8+
@app.generic_trigger(arg_name="req", type="httpTrigger")
9+
@app.generic_output_binding(arg_name="$return", type="http")
10+
@app.generic_input_binding(
11+
arg_name="docs",
12+
type="cosmosDB",
13+
database_name="test",
14+
collection_name="items",
15+
id="cosmosdb-input-test",
16+
connection_string_setting="AzureWebJobsCosmosDBConnectionString")
17+
def cosmosdb_input(req: func.HttpRequest, docs: func.DocumentList) -> str:
18+
return func.HttpResponse(docs[0].to_json(), mimetype='application/json')
19+
20+
21+
@app.generic_trigger(
22+
arg_name="docs",
23+
type="cosmosDBTrigger",
24+
database_name="test",
25+
collection_name="items",
26+
lease_collection_name="leases",
27+
connection_string_setting="AzureWebJobsCosmosDBConnectionString",
28+
create_lease_collection_if_not_exists=True)
29+
@app.generic_output_binding(
30+
arg_name="$return",
31+
type="blob",
32+
connection="AzureWebJobsStorage",
33+
path="python-worker-tests/test-cosmosdb-triggered.txt")
34+
def cosmosdb_trigger(docs: func.DocumentList) -> str:
35+
return docs[0].to_json()
36+
37+
38+
@app.generic_trigger(arg_name="req", type="httpTrigger")
39+
@app.generic_output_binding(arg_name="$return", type="http")
40+
@app.generic_input_binding(
41+
arg_name="file",
42+
connection="AzureWebJobsStorage",
43+
type="blob",
44+
path="python-worker-tests/test-cosmosdb-triggered.txt")
45+
def get_cosmosdb_triggered(req: func.HttpRequest,
46+
file: func.InputStream) -> str:
47+
return file.read().decode('utf-8')
48+
49+
50+
@app.generic_trigger(arg_name="req", type="httpTrigger")
51+
@app.generic_output_binding(arg_name="$return", type="http")
52+
@app.generic_output_binding(
53+
arg_name="doc",
54+
database_name="test",
55+
type="cosmosDB",
56+
collection_name="items",
57+
create_if_not_exists=True,
58+
connection_string_setting="AzureWebJobsCosmosDBConnectionString")
59+
def put_document(req: func.HttpRequest, doc: func.Out[func.Document]):
60+
doc.set(func.Document.from_json(req.get_body()))
61+
62+
return 'OK'

tests/endtoend/test_dependency_isolation_functions.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
REQUEST_TIMEOUT_SEC = 5
1717

1818

19+
@skipIf(is_envvar_true(DEDICATED_DOCKER_TEST)
20+
or is_envvar_true(CONSUMPTION_DOCKER_TEST),
21+
'Docker tests do not work with dependency isolation ')
1922
class TestGRPCandProtobufDependencyIsolationOnDedicated(
2023
testutils.WebHostTestCase):
2124
"""Test the dependency manager E2E scenario via Http Trigger.
@@ -76,10 +79,6 @@ def test_feature_flag_is_turned_on(self):
7679
flag_value = environments['PYTHON_ISOLATE_WORKER_DEPENDENCIES']
7780
self.assertEqual(flag_value, '1')
7881

79-
@skipIf(is_envvar_true(DEDICATED_DOCKER_TEST)
80-
or is_envvar_true(CONSUMPTION_DOCKER_TEST),
81-
"Docker test expects dependencies derived from agents folder"
82-
)
8382
def test_working_directory_resolution(self):
8483
"""Check from the dependency manager and see if the current working
8584
directory is resolved correctly
@@ -93,9 +92,7 @@ def test_working_directory_resolution(self):
9392
os.path.join(dir, 'dependency_isolation_functions').lower()
9493
)
9594

96-
@skipIf(is_envvar_true(PYAZURE_INTEGRATION_TEST)
97-
or is_envvar_true(DEDICATED_DOCKER_TEST)
98-
or is_envvar_true(CONSUMPTION_DOCKER_TEST),
95+
@skipIf(is_envvar_true(PYAZURE_INTEGRATION_TEST),
9996
'Integration test expects dependencies derived from core '
10097
'tools folder')
10198
def test_paths_resolution(self):
@@ -121,9 +118,6 @@ def test_paths_resolution(self):
121118
).lower()
122119
)
123120

124-
@skipIf(is_envvar_true(DEDICATED_DOCKER_TEST)
125-
or is_envvar_true(CONSUMPTION_DOCKER_TEST),
126-
'Docker tests do not work with dependency isolation ')
127121
def test_loading_libraries_from_customers_package(self):
128122
"""Since the Python now loaded the customer's dependencies, the
129123
libraries version should match the ones in

0 commit comments

Comments
 (0)