@@ -84,7 +84,7 @@ def test_blob_input_with_metadata_no_blob_properties(self):
84
84
self .assertEqual (result .metadata , None )
85
85
86
86
def test_blob_input_with_metadata_no_trigger_metadata (self ):
87
- sample_blob_properties = '{"Length ": "12"}'
87
+ sample_blob_properties = '{"ContentLength ": "12"}'
88
88
datum : Datum = Datum (value = b'blob_content' , type = 'bytes' )
89
89
trigger_metadata : Dict [str , Any ] = {
90
90
'Properties' : Datum (sample_blob_properties , 'json' ),
@@ -97,7 +97,7 @@ def test_blob_input_with_metadata_no_trigger_metadata(self):
97
97
# Verify result metadata
98
98
self .assertIsInstance (result , InputStream )
99
99
self .assertEqual (result .name , 'blob_trigger_name' )
100
- self .assertEqual (result .length , len ( b'blob_content' ) )
100
+ self .assertEqual (result .length , 12 )
101
101
self .assertEqual (result .uri , 'https://test.io/blob_trigger' )
102
102
self .assertEqual (result .blob_properties ,
103
103
json .loads (sample_blob_properties ))
@@ -115,7 +115,7 @@ def test_blob_input_with_metadata_with_trigger_metadata(self):
115
115
"LeaseStatus": 2,
116
116
"LeaseState": 1,
117
117
"LeaseDuration": 0,
118
- "Length ": "12"
118
+ "ContentLength ": "12"
119
119
}'''
120
120
datum : Datum = Datum (value = b'blob_content' , type = 'bytes' )
121
121
trigger_metadata : Dict [str , Any ] = {
@@ -130,7 +130,7 @@ def test_blob_input_with_metadata_with_trigger_metadata(self):
130
130
# Verify result metadata
131
131
self .assertIsInstance (result , InputStream )
132
132
self .assertEqual (result .name , 'blob_trigger_name' )
133
- self .assertEqual (result .length , len ( b'blob_content' ) )
133
+ self .assertEqual (result .length , 12 )
134
134
self .assertEqual (result .uri , 'https://test.io/blob_trigger' )
135
135
self .assertEqual (result .blob_properties ,
136
136
json .loads (sample_blob_properties ))
@@ -139,7 +139,7 @@ def test_blob_input_with_metadata_with_trigger_metadata(self):
139
139
140
140
def test_blob_input_with_metadata_with_incorrect_trigger_metadata (self ):
141
141
sample_metadata = 'Hello World'
142
- sample_blob_properties = '''{"Length ": "12"}'''
142
+ sample_blob_properties = '''{"ContentLength ": "12"}'''
143
143
datum : Datum = Datum (value = b'blob_content' , type = 'bytes' )
144
144
trigger_metadata : Dict [str , Any ] = {
145
145
'Metadata' : Datum (sample_metadata , 'string' ),
@@ -153,7 +153,7 @@ def test_blob_input_with_metadata_with_incorrect_trigger_metadata(self):
153
153
# Verify result metadata
154
154
self .assertIsInstance (result , InputStream )
155
155
self .assertEqual (result .name , 'blob_trigger_name' )
156
- self .assertEqual (result .length , len ( b'blob_content' ) )
156
+ self .assertEqual (result .length , 12 )
157
157
self .assertEqual (result .uri , 'https://test.io/blob_trigger' )
158
158
self .assertEqual (result .blob_properties ,
159
159
json .loads (sample_blob_properties ))
@@ -228,3 +228,46 @@ def read(self) -> Datum:
228
228
229
229
check_output_type = afb .BlobConverter .check_output_type_annotation
230
230
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