Skip to content

Commit bdeb2c2

Browse files
authored
Optional source param for blob trigger (#220)
* making source optional param * fixed tests * added tests
1 parent 3e87e81 commit bdeb2c2

File tree

5 files changed

+42
-8
lines changed

5 files changed

+42
-8
lines changed

azure/functions/decorators/blob.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def __init__(self,
1212
name: str,
1313
path: str,
1414
connection: str,
15-
source: BlobSource,
15+
source: Optional[BlobSource] = None,
1616
data_type: Optional[DataType] = None,
1717
**kwargs):
1818
self.path = path

azure/functions/decorators/function_app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,8 +1114,8 @@ def blob_trigger(self,
11141114
arg_name: str,
11151115
path: str,
11161116
connection: str,
1117-
source: BlobSource =
1118-
BlobSource.LOGS_AND_CONTAINER_SCAN,
1117+
source: Optional[BlobSource] =
1118+
None,
11191119
data_type: Optional[DataType] = None,
11201120
**kwargs) -> Callable[..., Any]:
11211121
"""

docs/ProgModelSpec.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ class TriggerApi(DecoratorApi, ABC):
495495
arg_name: str,
496496
path: str,
497497
connection: str,
498-
source: BlobSource = BlobSource.LOGS_AND_CONTAINER_SCAN,
498+
source: Optional[BlobSource] = None,
499499
data_type: Optional[DataType] = None,
500500
**kwargs) -> Callable:
501501
"""

tests/decorators/test_blob.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,44 @@
88

99

1010
class TestBlob(unittest.TestCase):
11+
def test_blob_trigger_creation_with_no_source(self):
12+
trigger = BlobTrigger(name="req",
13+
path="dummy_path",
14+
connection="dummy_connection",
15+
data_type=DataType.UNDEFINED,
16+
dummy_field="dummy")
17+
18+
self.assertEqual(trigger.get_binding_name(), "blobTrigger")
19+
self.assertEqual(trigger.get_dict_repr(), {
20+
"type": "blobTrigger",
21+
"direction": BindingDirection.IN,
22+
'dummyField': 'dummy',
23+
"name": "req",
24+
"dataType": DataType.UNDEFINED,
25+
"path": "dummy_path",
26+
"connection": "dummy_connection"
27+
})
28+
29+
def test_blob_trigger_creation_with_default_specified_source(self):
30+
trigger = BlobTrigger(name="req",
31+
path="dummy_path",
32+
connection="dummy_connection",
33+
source=BlobSource.LOGS_AND_CONTAINER_SCAN,
34+
data_type=DataType.UNDEFINED,
35+
dummy_field="dummy")
36+
37+
self.assertEqual(trigger.get_binding_name(), "blobTrigger")
38+
self.assertEqual(trigger.get_dict_repr(), {
39+
"type": "blobTrigger",
40+
"direction": BindingDirection.IN,
41+
'dummyField': 'dummy',
42+
"name": "req",
43+
"dataType": DataType.UNDEFINED,
44+
"path": "dummy_path",
45+
'source': BlobSource.LOGS_AND_CONTAINER_SCAN,
46+
"connection": "dummy_connection"
47+
})
48+
1149
def test_blob_trigger_creation_with_source_as_string(self):
1250
trigger = BlobTrigger(name="req",
1351
path="dummy_path",

tests/decorators/test_decorators.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,8 +1569,6 @@ def dummy():
15691569
"type": BLOB_TRIGGER,
15701570
"name": "req",
15711571
"path": "dummy_path",
1572-
"source":
1573-
BlobSource.LOGS_AND_CONTAINER_SCAN,
15741572
"connection": "dummy_conn"
15751573
}]})
15761574

@@ -1595,7 +1593,6 @@ def dummy():
15951593
"type": BLOB_TRIGGER,
15961594
"name": "req",
15971595
"path": "dummy_path",
1598-
"source": BlobSource.LOGS_AND_CONTAINER_SCAN,
15991596
"connection": "dummy_conn"
16001597
})
16011598

@@ -1665,7 +1662,6 @@ def dummy():
16651662
"type": BLOB_TRIGGER,
16661663
"name": "req",
16671664
"path": "dummy_path",
1668-
"source": BlobSource.LOGS_AND_CONTAINER_SCAN,
16691665
"connection": "dummy_conn"
16701666
})
16711667

0 commit comments

Comments
 (0)