Skip to content

Commit

Permalink
typo fix and add more tests for add_parameter_presets method
Browse files Browse the repository at this point in the history
  • Loading branch information
MRyderOC committed Jun 13, 2024
1 parent d70f715 commit 97a67b4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/dfcx_scrapi/builders/fulfillments.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def add_parameter_presets(
if not all(isinstance(k, str) for k in parameter_map.keys()):
raise ValueError(
"Only strings are allowed as"
" dictionary keys in parameter_map."
" dictionary keys in `parameter_map`."
)
for param, val in parameter_map.items():
self.proto_obj.set_parameter_actions.append(
Expand All @@ -238,7 +238,7 @@ def add_parameter_presets(
return self.proto_obj
else:
raise ValueError(
"parameter_map should be a dictionary."
"`parameter_map` should be a dictionary."
)


Expand Down
21 changes: 21 additions & 0 deletions tests/dfcx_scrapi/builders/test_fulfillments.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,24 @@ def test_create_new_proto_obj_with_webhook():
fb.create_new_proto_obj(webhook=custom_wbhk, overwrite=True)


def test_add_parameter_presets_with_valid_dict():
valid_param_map = {"p1": "v1", "p2": 123, "p3": True, "p4": None}
fb = FulfillmentBuilder()
fb.create_new_proto_obj()
fb.add_parameter_presets(valid_param_map)

for p in fb.proto_obj.set_parameter_actions:
assert p.parameter in valid_param_map
assert p.value == valid_param_map[p.parameter]


def test_add_parameter_presets_with_invalid_dict():
invalid_param_map = {"p1": "v1", 123: "p2"}
fb = FulfillmentBuilder()
fb.create_new_proto_obj()
with pytest.raises(ValueError):
fb.add_parameter_presets(invalid_param_map)

# passing a list instead of dict
with pytest.raises(ValueError):
fb.add_parameter_presets(list(invalid_param_map.keys()))

0 comments on commit 97a67b4

Please sign in to comment.