Skip to content

Commit

Permalink
Parametrized tests for validate hour
Browse files Browse the repository at this point in the history
  • Loading branch information
caseneuve committed Dec 15, 2023
1 parent 64fe60b commit 20d100b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/dzira/dzira.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,6 @@ def validate_time(_, __, time):


def validate_hour(ctx, param, value):
"TODO: update tests for happy path return value"
if (
param.name == "end"
and value
Expand Down
9 changes: 6 additions & 3 deletions tests/test_dzira.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,16 +760,19 @@ def test_passes_when_time_is_none_and_first_check_passed(self, mock_is_valid_hou
assert result is None
mock_is_valid_hour.assert_not_called()

def test_passes_when_validator_passes_and_returns_unified_value(self, mock_is_valid_hour):
@pytest.mark.parametrize("given_time", ["17h23", "17,23", "17.23", "17:23"])
def test_passes_when_validator_passes_and_returns_unified_value(
self, mock_is_valid_hour, given_time
):
mock_ctx = Mock(params={"start": "16h42"})
mock_param = Mock()
type(mock_param).name = PropertyMock(return_value="end")
mock_is_valid_hour.return_value = True

result = validate_hour(mock_ctx, mock_param, "17h23")
result = validate_hour(mock_ctx, mock_param, given_time)

assert result == "17:23"
mock_is_valid_hour.assert_called_once_with("17h23")
mock_is_valid_hour.assert_called_once_with(given_time)

def test_raises_otherwise(self, mock_is_valid_hour):
mock_ctx = Mock(params={})
Expand Down

0 comments on commit 20d100b

Please sign in to comment.