Skip to content

Commit c8a346a

Browse files
committed
Fixups from review
1 parent 5bdfb55 commit c8a346a

2 files changed

Lines changed: 21 additions & 12 deletions

File tree

promise-types/appstreams/appstreams.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,38 +54,37 @@ def __init__(self, **kwargs):
5454
)
5555

5656
def _validate_state(self, value):
57-
if value not in (
57+
accepted = (
5858
"enabled",
5959
"disabled",
6060
"installed",
6161
"removed",
6262
"default",
6363
"reset",
64-
):
65-
raise ValidationError(
66-
"State attribute must be 'enabled', 'disabled', 'installed', "
67-
"'removed', 'default', or 'reset'"
68-
)
64+
)
65+
if value not in accepted:
66+
accepted_str = "', '".join(accepted)
67+
raise ValidationError(f"State attribute must be '{accepted_str}'")
6968

7069
def _validate_module_name(self, name):
7170
# Validate module name to prevent injection
72-
if not re.match(r"^[a-zA-Z0-9_.-]+$", name):
71+
if not re.fullmatch(r"[a-zA-Z0-9_.-]+", name):
7372
raise ValidationError(
7473
f"Invalid module name: {name}. Only alphanumeric, underscore, "
7574
f"dot, and dash characters are allowed."
7675
)
7776

7877
def _validate_stream_name(self, stream):
7978
# Validate stream name to prevent injection
80-
if stream and not re.match(r"^[a-zA-Z0-9_.-]+$", stream):
79+
if stream and not re.fullmatch(r"[a-zA-Z0-9_.-]+", stream):
8180
raise ValidationError(
8281
f"Invalid stream name: {stream}. Only alphanumeric, underscore, "
8382
f"dot, and dash characters are allowed."
8483
)
8584

8685
def _validate_profile_name(self, profile):
8786
# Validate profile name to prevent injection
88-
if profile and not re.match(r"^[a-zA-Z0-9_.-]+$", profile):
87+
if profile and not re.fullmatch(r"[a-zA-Z0-9_.-]+", profile):
8988
raise ValidationError(
9089
f"Invalid profile name: {profile}. Only alphanumeric, underscore, "
9190
f"dot, and dash characters are allowed."

promise-types/appstreams/test_appstreams_logic.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ def test_install_profile_repaired(module, mock_base, mock_mpc):
110110
# Initial state: enabled but not fully installed with profile
111111
mock_mpc.getModuleState.return_value = mock_mpc.ModuleState_ENABLED
112112
mock_mpc.getEnabledStream.return_value = "12"
113-
mock_mpc.getInstalledProfiles.return_value = []
113+
# First call (pre-install check) returns [], second call (post-install verify) returns ["common"]
114+
mock_mpc.getInstalledProfiles.side_effect = [[], ["common"]]
114115

115116
# helper for _get_profile_packages
116117
# It queries module, gets stream, gets profiles, gets content
@@ -132,7 +133,11 @@ def test_install_profile_repaired(module, mock_base, mock_mpc):
132133

133134
def test_remove_module_repaired(module, mock_base, mock_mpc):
134135
"""Test removing a module using 'removed' state (REPAIRED)"""
135-
mock_mpc.getModuleState.return_value = mock_mpc.ModuleState_INSTALLED
136+
# First call (current state check) returns INSTALLED, second (post-remove verify) returns DEFAULT
137+
mock_mpc.getModuleState.side_effect = [
138+
mock_mpc.ModuleState_INSTALLED,
139+
mock_mpc.ModuleState_DEFAULT,
140+
]
136141
mock_mpc.getEnabledStream.return_value = "12"
137142
mock_mpc.getInstalledProfiles.return_value = ["common"]
138143

@@ -167,7 +172,12 @@ def test_install_profile_idempotency_success(module, mock_base, mock_mpc):
167172

168173
def test_reset_module_repaired(module, mock_base, mock_mpc):
169174
"""Test resetting a module to default state (REPAIRED)"""
170-
mock_mpc.getModuleState.return_value = mock_mpc.ModuleState_ENABLED
175+
# evaluate_promise calls _get_module_state first, then _reset_module calls it twice more
176+
mock_mpc.getModuleState.side_effect = [
177+
mock_mpc.ModuleState_ENABLED, # evaluate_promise current-state check
178+
mock_mpc.ModuleState_ENABLED, # _reset_module early-exit check
179+
mock_mpc.ModuleState_DEFAULT, # _reset_module post-reset verification
180+
]
171181

172182
result = module.evaluate_promise("nodejs", {"state": "default", "stream": "12"}, {})
173183

0 commit comments

Comments
 (0)