Skip to content

Commit d82958f

Browse files
authored
Validate that step functions exist when parsing actions (#619)
1 parent b310b4c commit d82958f

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

jbi/models.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from pydantic import BaseModel, Extra, Field, validator
1515
from pydantic_yaml import YamlModel
1616

17-
from jbi import Operation
17+
from jbi import Operation, steps
1818
from jbi.errors import ActionNotFoundError
1919

2020
logger = logging.getLogger(__name__)
@@ -41,6 +41,19 @@ class ActionSteps(BaseModel):
4141
"create_comment",
4242
]
4343

44+
@validator("*")
45+
def validate_steps(cls, function_names): # pylint: disable=no-self-argument
46+
"""Validate that all configure step functions exist in the steps module"""
47+
48+
invalid_functions = [
49+
func_name for func_name in function_names if not hasattr(steps, func_name)
50+
]
51+
if invalid_functions:
52+
raise ValueError(
53+
f"The following functions are not available in the `steps` module: {', '.join(invalid_functions)}"
54+
)
55+
return function_names
56+
4457

4558
class JiraComponents(BaseModel):
4659
"""Controls how Jira components are set on issues in the `maybe_update_components` step."""

jbi/router.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def get_whiteboard_tags(
101101
@router.get("/bugzilla_webhooks/")
102102
def get_bugzilla_webhooks(bugzilla_service: BugzillaServiceDep):
103103
"""API for viewing webhooks details"""
104-
return bugzilla_service.client.list_webhooks()
104+
return bugzilla_service.list_webhooks()
105105

106106

107107
@router.get("/jira_projects/")

tests/unit/test_models.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ def test_no_actions_fails():
2323
assert "ensure this value has at least 1 items" in str(exc_info.value)
2424

2525

26+
def test_default_invalid_step():
27+
with pytest.raises(pydantic.ValidationError) as exc:
28+
ActionSteps(new=["BOOM", "POW"], comment=["BAM"])
29+
error_message = str(exc.value)
30+
31+
assert "BOOM" in error_message
32+
assert "POW" in error_message
33+
assert "BAM" in error_message
34+
35+
2636
def test_duplicated_whiteboard_tag_fails(action_factory):
2737
with pytest.raises(ValueError) as exc_info:
2838
Actions.parse_obj(

tests/unit/test_runner.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,6 @@ def test_default_invalid_init():
283283
Executor()
284284

285285

286-
def test_default_invalid_step(action_params_factory):
287-
with pytest.raises(AttributeError):
288-
Executor(action_params_factory(steps={"new": ["unknown_step"]}))
289-
290-
291286
def test_unspecified_groups_come_from_default_steps(action_params_factory):
292287
action = Executor(action_params_factory(steps={"comment": ["create_comment"]}))
293288

0 commit comments

Comments
 (0)