Skip to content

Commit 8d2b2c5

Browse files
author
Hanzhang Zeng (Roger)
committed
Add failure cases for test
1 parent 72e6eca commit 8d2b2c5

File tree

7 files changed

+87
-4
lines changed

7 files changed

+87
-4
lines changed

tests/unittests/eventhub_mock_functions/eventhub_cardinality_many/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
import azure.functions as func
33

44

5+
# This is testing the function load feature for the multiple events annotation
56
def main(events: List[func.EventHubEvent]) -> str:
6-
return 'OK'
7+
return 'OK_MANY'
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from typing import List
2+
import azure.functions as func
3+
4+
5+
# This is testing the function load feature for the multiple events annotation
6+
# The event shouldn't be List[str]
7+
def main(events: List[str]) -> str:
8+
return 'BAD'
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"scriptFile": "__init__.py",
3+
4+
"bindings": [
5+
{
6+
"type": "eventHubTrigger",
7+
"name": "events",
8+
"direction": "in",
9+
"eventHubName": "python-worker-iot-ci",
10+
"connection": "AzureWebJobsEventHubConnectionString",
11+
"cardinality": "many"
12+
},
13+
{
14+
"type": "blob",
15+
"direction": "out",
16+
"name": "$return",
17+
"connection": "AzureWebJobsStorage",
18+
"path": "python-worker-tests/test-eventhub-iot-triggered.txt"
19+
}
20+
]
21+
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import azure.functions as func
22

33

4+
# This is testing the function load feature for the single event annotation
45
def main(event: func.EventHubEvent) -> str:
5-
return 'OK'
6+
return 'OK_ONE'
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import azure.functions as func
2+
3+
4+
# This is testing the function load feature for the single event annotation
5+
# The event shouldn't be int
6+
def main(event: int) -> str:
7+
return 'BAD'
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"scriptFile": "__init__.py",
3+
4+
"bindings": [
5+
{
6+
"type": "eventHubTrigger",
7+
"name": "event",
8+
"direction": "in",
9+
"eventHubName": "python-worker-iot-ci",
10+
"connection": "AzureWebJobsEventHubConnectionString",
11+
"cardinality": "one"
12+
},
13+
{
14+
"type": "blob",
15+
"direction": "out",
16+
"name": "$return",
17+
"connection": "AzureWebJobsStorage",
18+
"path": "python-worker-tests/test-eventhub-iot-triggered.txt"
19+
}
20+
]
21+
}

tests/unittests/test_mock_eventhub_functions.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,19 @@ async def test_mock_eventhub_cardinality_one(self):
7575

7676
self.assertEqual(r.response.result.status,
7777
protos.StatusResult.Success)
78-
self.assertEqual(r.response.return_value.string, 'OK')
78+
self.assertEqual(r.response.return_value.string, 'OK_ONE')
79+
80+
async def test_mock_eventhub_cardinality_one_bad_annotation(self):
81+
async with testutils.start_mockhost(
82+
script_root=self.mock_funcs_dir) as host:
83+
84+
# This suppose to fail since the event should not be int
85+
func_id, r = await host.load_function(
86+
'eventhub_cardinality_one_bad_anno'
87+
)
88+
self.assertEqual(r.response.function_id, func_id)
89+
self.assertEqual(r.response.result.status,
90+
protos.StatusResult.Failure)
7991

8092
async def test_mock_eventhub_cardinality_many(self):
8193
async with testutils.start_mockhost(
@@ -103,4 +115,16 @@ async def test_mock_eventhub_cardinality_many(self):
103115

104116
self.assertEqual(r.response.result.status,
105117
protos.StatusResult.Success)
106-
self.assertEqual(r.response.return_value.string, 'OK')
118+
self.assertEqual(r.response.return_value.string, 'OK_MANY')
119+
120+
async def test_mock_eventhub_cardinality_many_bad_annotation(self):
121+
async with testutils.start_mockhost(
122+
script_root=self.mock_funcs_dir) as host:
123+
124+
# This suppose to fail since the event should not be List[str]
125+
func_id, r = await host.load_function(
126+
'eventhub_cardinality_many_bad_anno'
127+
)
128+
self.assertEqual(r.response.function_id, func_id)
129+
self.assertEqual(r.response.result.status,
130+
protos.StatusResult.Failure)

0 commit comments

Comments
 (0)