@@ -34,17 +34,18 @@ def test_given_valid_path_and_input_validate_is_successful(self):
34
34
assert strategy .validate_called
35
35
assert strategy .validated_value
36
36
37
- def test_given_invalid_path_when_validate_then_raise_key_error (self ):
37
+
38
+ class TestDpathValidator (TestCase ):
39
+ def test_given_valid_top_level_path_and_input_validate_is_successful (self ):
38
40
strategy = MockValidationStrategy ()
39
- validator = DpathValidator (field_path = ["user" , "profile" , "phone" ], strategy = strategy )
41
+ validator = DpathValidator (field_path = ["user" ], strategy = strategy )
40
42
41
- test_data = {"user" : {"profile" : {"email" : "test@example.com" }}}
43
+ test_data = {"user" : {"profile" : {"email" : "test@example.com" , "name" : "Test User" }}}
42
44
43
- with pytest .raises (ValueError ) as context :
44
- validator .validate (test_data )
45
+ validator .validate (test_data )
45
46
46
- assert "Error validating path" in str ( context . value )
47
- assert not strategy .validate_called
47
+ assert strategy . validate_called
48
+ assert strategy .validated_value
48
49
49
50
def test_given_strategy_fails_when_validate_then_raise_value_error (self ):
50
51
error_message = "Invalid email format"
@@ -53,7 +54,7 @@ def test_given_strategy_fails_when_validate_then_raise_value_error(self):
53
54
54
55
test_data = {"user" : {"email" : "invalid-email" }}
55
56
56
- with pytest .raises (ValueError ) as context :
57
+ with pytest .raises (ValueError ):
57
58
validator .validate (test_data )
58
59
59
60
assert strategy .validate_called
@@ -67,15 +68,6 @@ def test_given_empty_path_list_when_validate_then_validate_raises_exception(self
67
68
with pytest .raises (ValueError ):
68
69
validator .validate (test_data )
69
70
70
- def test_given_empty_input_data_when_validate_then_validate_raises_exception (self ):
71
- strategy = MockValidationStrategy ()
72
- validator = DpathValidator (field_path = ["data" , "field" ], strategy = strategy )
73
-
74
- test_data = {}
75
-
76
- with pytest .raises (ValueError ):
77
- validator .validate (test_data )
78
-
79
71
def test_path_with_wildcard_when_validate_then_validate_is_successful (self ):
80
72
strategy = MockValidationStrategy ()
81
73
validator = DpathValidator (field_path = ["users" , "*" , "email" ], strategy = strategy )
0 commit comments