Skip to content

Commit df56cdf

Browse files
authored
clean_nones in raw bindings (#56)
1 parent f02c865 commit df56cdf

File tree

2 files changed

+48
-7
lines changed

2 files changed

+48
-7
lines changed

azurefunctions-extensions-base/azurefunctions/extensions/base/utils.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,9 @@ def get_raw_bindings(indexed_function, input_types):
250250
bindings_logs = {}
251251
for b in indexed_function._bindings:
252252
dict_repr, logs = Binding.get_dict_repr(b, input_types)
253-
binding_dict_repr.append(json.dumps(dict_repr, cls=StringifyEnumJsonEncoder))
253+
clean_dict_repr = BuildDictMeta.clean_nones(dict_repr)
254+
binding_dict_repr.append(
255+
json.dumps(clean_dict_repr, cls=StringifyEnumJsonEncoder)
256+
)
254257
bindings_logs.update(logs)
255258
return binding_dict_repr, bindings_logs

azurefunctions-extensions-base/tests/test_utils.py

+44-6
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def test_get_dict_repr_sdk(self):
6363
dict_repr,
6464
[
6565
'{"direction": "IN", '
66-
'"dataType": null, "type": "blob", '
66+
'"type": "blob", '
6767
'"properties": '
6868
'{"SupportsDeferredBinding": true}}'
6969
],
@@ -98,7 +98,7 @@ def test_get_dict_repr_non_sdk(self):
9898
dict_repr,
9999
[
100100
'{"direction": "IN", '
101-
'"dataType": null, "type": "blob", '
101+
'"type": "blob", '
102102
'"properties": '
103103
'{"SupportsDeferredBinding": false}}'
104104
],
@@ -138,9 +138,9 @@ def test_get_dict_repr_binding_name_none(self):
138138
self.assertEqual(
139139
dict_repr,
140140
[
141-
'{"direction": "IN", "dataType": null, "type": "blob", '
141+
'{"direction": "IN", "type": "blob", '
142142
'"properties": {"SupportsDeferredBinding": false}}',
143-
'{"direction": "OUT", "dataType": null, "type": "httpResponse", '
143+
'{"direction": "OUT", "type": "httpResponse", '
144144
'"properties": {"SupportsDeferredBinding": false}}',
145145
],
146146
)
@@ -175,8 +175,46 @@ def test_get_dict_repr_init_params(self):
175175
self.assertEqual(
176176
dict_repr,
177177
[
178-
'{"direction": "IN", "dataType": null, '
179-
'"type": "blob", "test": null, "properties": '
178+
'{"direction": "IN", '
179+
'"type": "blob", "properties": '
180+
'{"SupportsDeferredBinding": true}}'
181+
],
182+
)
183+
184+
self.assertEqual(logs, {"client": {sdkType.SdkType: "True"}})
185+
186+
def test_get_dict_repr_clean_nones(self):
187+
# Create mock blob
188+
meta._ConverterMeta._bindings = {"blob"}
189+
190+
# Create test binding
191+
mock_blob = MockInitParams(
192+
name="client",
193+
direction=utils.BindingDirection.IN,
194+
data_type=None,
195+
type="blob",
196+
path=None,
197+
init_params=["test", "type", "direction", "path"],
198+
)
199+
200+
# Create test input_types dict
201+
mock_input_types = {
202+
"client": MockParamTypeInfo(
203+
binding_name="blobTrigger", pytype=sdkType.SdkType
204+
)
205+
}
206+
207+
# Create test indexed_function
208+
mock_indexed_functions = MockFunction(bindings=[mock_blob])
209+
210+
dict_repr, logs = utils.get_raw_bindings(
211+
mock_indexed_functions, mock_input_types
212+
)
213+
self.assertEqual(
214+
dict_repr,
215+
[
216+
'{"direction": "IN", '
217+
'"type": "blob", "properties": '
180218
'{"SupportsDeferredBinding": true}}'
181219
],
182220
)

0 commit comments

Comments
 (0)