Skip to content

Commit a29e424

Browse files
committed
Merge branch 'pnilan/feat/implement-validators' into pnilan/feat/extend-spec-class-for-config-migrations
2 parents d3287a1 + 4727b28 commit a29e424

File tree

3 files changed

+15
-22
lines changed

3 files changed

+15
-22
lines changed

airbyte_cdk/sources/declarative/validators/dpath_validator.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,13 @@ def validate(self, input_data: dict[str, Any]) -> None:
4747
if "*" in path:
4848
try:
4949
values = dpath.values(input_data, path)
50-
except KeyError as e:
51-
raise KeyError(f"Error validating path '{self.field_path}': {e}")
52-
for value in values:
53-
try:
50+
for value in values:
5451
self.strategy.validate(value)
55-
except Exception as e:
56-
raise ValueError(f"Error validating value '{value}': {e}")
52+
except KeyError as e:
53+
raise ValueError(f"Error validating path '{self.field_path}': {e}")
5754
else:
5855
try:
5956
value = dpath.get(input_data, path)
60-
except KeyError as e:
61-
raise KeyError(f"Error validating path '{self.field_path}': {e}")
62-
try:
6357
self.strategy.validate(value)
64-
except Exception as e:
65-
raise ValueError(f"Error validating value '{value}': {e}")
58+
except KeyError as e:
59+
raise ValueError(f"Error validating path '{self.field_path}': {e}")

unit_tests/sources/declarative/validators/test_dpath_validator.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@ def test_given_invalid_path_when_validate_then_raise_key_error(self):
3838

3939
test_data = {"user": {"profile": {"email": "[email protected]"}}}
4040

41-
with pytest.raises(KeyError) as context:
41+
with pytest.raises(ValueError) as context:
4242
validator.validate(test_data)
43-
assert "Error validating path" in str(context.exception)
44-
assert not strategy.validate_called
43+
44+
assert "Error validating path" in str(context.value)
45+
assert not strategy.validate_called
4546

4647
def test_given_strategy_fails_when_validate_then_raise_value_error(self):
4748
error_message = "Invalid email format"
@@ -53,10 +54,8 @@ def test_given_strategy_fails_when_validate_then_raise_value_error(self):
5354
with pytest.raises(ValueError) as context:
5455
validator.validate(test_data)
5556

56-
assert "Error validating value" in str(context.exception)
57-
assert error_message in str(context.exception)
58-
assert strategy.validate_called
59-
assert strategy.validated_value == "invalid-email"
57+
assert strategy.validate_called
58+
assert strategy.validated_value == "invalid-email"
6059

6160
def test_given_empty_path_list_when_validate_then_validate_raises_exception(self):
6261
strategy = MockValidationStrategy()
@@ -72,7 +71,7 @@ def test_given_empty_input_data_when_validate_then_validate_raises_exception(sel
7271

7372
test_data = {}
7473

75-
with pytest.raises(KeyError):
74+
with pytest.raises(ValueError):
7675
validator.validate(test_data)
7776

7877
def test_path_with_wildcard_when_validate_then_validate_is_successful(self):

unit_tests/sources/declarative/validators/test_predicate_validator.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ def test_given_invalid_input_when_validate_then_raise_value_error(self):
4040
with pytest.raises(ValueError) as context:
4141
validator.validate()
4242

43-
assert error_message in str(context.exception)
44-
assert strategy.validate_called
45-
assert strategy.validated_value == test_value
43+
assert error_message in str(context.value)
44+
assert strategy.validate_called
45+
assert strategy.validated_value == test_value
4646

4747
def test_given_complex_object_when_validate_then_successful(self):
4848
strategy = MockValidationStrategy()

0 commit comments

Comments
 (0)