Skip to content

Commit a93d9a0

Browse files
author
Victoria Hall
committed
Merge branch 'hallvictoria/test-312' of https://github.com/Azure/azure-functions-python-library into hallvictoria/test-312
2 parents 033923b + a5576ce commit a93d9a0

File tree

5 files changed

+57
-10
lines changed

5 files changed

+57
-10
lines changed

azure/functions/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,4 @@
102102
'BlobSource'
103103
)
104104

105-
__version__ = '1.22.0b2'
105+
__version__ = '1.22.0b4'

azure/functions/blob.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ def decode(cls, data: meta.Datum, *, trigger_metadata) -> Any:
113113
trigger_metadata, 'Properties', python_type=dict)
114114
if properties:
115115
blob_properties = properties
116-
length = properties.get('Length')
116+
length = properties.get('ContentLength') or \
117+
properties.get('Length')
117118
length = int(length) if length else None
118119
else:
119120
blob_properties = None

azure/functions/decorators/blob.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ def __init__(self,
1717
**kwargs):
1818
self.path = path
1919
self.connection = connection
20-
self.source = source.value if source else None
20+
if isinstance(source, BlobSource):
21+
self.source = source.value
22+
else:
23+
self.source = source # type: ignore
2124
super().__init__(name=name, data_type=data_type)
2225

2326
@staticmethod

tests/decorators/test_blob.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def test_blob_trigger_creation_with_source_as_string(self):
5050
trigger = BlobTrigger(name="req",
5151
path="dummy_path",
5252
connection="dummy_connection",
53-
source=BlobSource.EVENT_GRID,
53+
source="EventGrid",
5454
data_type=DataType.UNDEFINED,
5555
dummy_field="dummy")
5656

tests/test_blob.py

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def test_blob_input_with_metadata_no_blob_properties(self):
8484
self.assertEqual(result.metadata, None)
8585

8686
def test_blob_input_with_metadata_no_trigger_metadata(self):
87-
sample_blob_properties = '{"Length": "12"}'
87+
sample_blob_properties = '{"ContentLength": "12"}'
8888
datum: Datum = Datum(value=b'blob_content', type='bytes')
8989
trigger_metadata: Dict[str, Any] = {
9090
'Properties': Datum(sample_blob_properties, 'json'),
@@ -97,7 +97,7 @@ def test_blob_input_with_metadata_no_trigger_metadata(self):
9797
# Verify result metadata
9898
self.assertIsInstance(result, InputStream)
9999
self.assertEqual(result.name, 'blob_trigger_name')
100-
self.assertEqual(result.length, len(b'blob_content'))
100+
self.assertEqual(result.length, 12)
101101
self.assertEqual(result.uri, 'https://test.io/blob_trigger')
102102
self.assertEqual(result.blob_properties,
103103
json.loads(sample_blob_properties))
@@ -115,7 +115,7 @@ def test_blob_input_with_metadata_with_trigger_metadata(self):
115115
"LeaseStatus": 2,
116116
"LeaseState": 1,
117117
"LeaseDuration": 0,
118-
"Length": "12"
118+
"ContentLength": "12"
119119
}'''
120120
datum: Datum = Datum(value=b'blob_content', type='bytes')
121121
trigger_metadata: Dict[str, Any] = {
@@ -130,7 +130,7 @@ def test_blob_input_with_metadata_with_trigger_metadata(self):
130130
# Verify result metadata
131131
self.assertIsInstance(result, InputStream)
132132
self.assertEqual(result.name, 'blob_trigger_name')
133-
self.assertEqual(result.length, len(b'blob_content'))
133+
self.assertEqual(result.length, 12)
134134
self.assertEqual(result.uri, 'https://test.io/blob_trigger')
135135
self.assertEqual(result.blob_properties,
136136
json.loads(sample_blob_properties))
@@ -139,7 +139,7 @@ def test_blob_input_with_metadata_with_trigger_metadata(self):
139139

140140
def test_blob_input_with_metadata_with_incorrect_trigger_metadata(self):
141141
sample_metadata = 'Hello World'
142-
sample_blob_properties = '''{"Length": "12"}'''
142+
sample_blob_properties = '''{"ContentLength": "12"}'''
143143
datum: Datum = Datum(value=b'blob_content', type='bytes')
144144
trigger_metadata: Dict[str, Any] = {
145145
'Metadata': Datum(sample_metadata, 'string'),
@@ -153,7 +153,7 @@ def test_blob_input_with_metadata_with_incorrect_trigger_metadata(self):
153153
# Verify result metadata
154154
self.assertIsInstance(result, InputStream)
155155
self.assertEqual(result.name, 'blob_trigger_name')
156-
self.assertEqual(result.length, len(b'blob_content'))
156+
self.assertEqual(result.length, 12)
157157
self.assertEqual(result.uri, 'https://test.io/blob_trigger')
158158
self.assertEqual(result.blob_properties,
159159
json.loads(sample_blob_properties))
@@ -228,3 +228,46 @@ def read(self) -> Datum:
228228

229229
check_output_type = afb.BlobConverter.check_output_type_annotation
230230
self.assertTrue(check_output_type(CustomOutput))
231+
232+
def test_blob_input_with_metadata_with_length(self):
233+
sample_blob_properties = '{"Length": "12"}'
234+
datum: Datum = Datum(value=b'blob_content', type='bytes')
235+
trigger_metadata: Dict[str, Any] = {
236+
'Properties': Datum(sample_blob_properties, 'json')
237+
}
238+
result: InputStream = afb. \
239+
BlobConverter.decode(data=datum, trigger_metadata=trigger_metadata)
240+
241+
# Verify result metadata
242+
self.assertIsInstance(result, InputStream)
243+
self.assertEqual(result.length, 12)
244+
245+
def test_blob_input_with_metadata_with_both_length(self):
246+
sample_blob_properties = '''{
247+
"ContentLength": "12",
248+
"Length": "10"
249+
}'''
250+
datum: Datum = Datum(value=b'blob_content', type='bytes')
251+
trigger_metadata: Dict[str, Any] = {
252+
'Properties': Datum(sample_blob_properties, 'json')
253+
}
254+
result: InputStream = afb. \
255+
BlobConverter.decode(data=datum, trigger_metadata=trigger_metadata)
256+
257+
# Verify result metadata.
258+
# This should be 12, since we check for ContentLength first
259+
self.assertIsInstance(result, InputStream)
260+
self.assertEqual(result.length, 12)
261+
262+
def test_blob_input_with_metadata_with_no_length(self):
263+
sample_blob_properties = '''{}'''
264+
datum: Datum = Datum(value=b'blob_content', type='bytes')
265+
trigger_metadata: Dict[str, Any] = {
266+
'Properties': Datum(sample_blob_properties, 'json')
267+
}
268+
result: InputStream = afb. \
269+
BlobConverter.decode(data=datum, trigger_metadata=trigger_metadata)
270+
271+
# Verify result metadata.
272+
self.assertIsInstance(result, InputStream)
273+
self.assertEqual(result.length, None)

0 commit comments

Comments
 (0)