@@ -34,17 +34,18 @@ def test_given_valid_path_and_input_validate_is_successful(self):
3434 assert strategy .validate_called
3535 assert strategy .validated_value
3636
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 ):
3840 strategy = MockValidationStrategy ()
39- validator = DpathValidator (field_path = ["user" , "profile" , "phone" ], strategy = strategy )
41+ validator = DpathValidator (field_path = ["user" ], strategy = strategy )
4042
41- test_data = {
"user" : {
"profile" : {
"email" :
"[email protected] " }}}
43+ test_data = {
"user" : {
"profile" : {
"email" :
"[email protected] " , "name" : "Test User" }}}
4244
43- with pytest .raises (ValueError ) as context :
44- validator .validate (test_data )
45+ validator .validate (test_data )
4546
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
4849
4950 def test_given_strategy_fails_when_validate_then_raise_value_error (self ):
5051 error_message = "Invalid email format"
@@ -53,7 +54,7 @@ def test_given_strategy_fails_when_validate_then_raise_value_error(self):
5354
5455 test_data = {"user" : {"email" : "invalid-email" }}
5556
56- with pytest .raises (ValueError ) as context :
57+ with pytest .raises (ValueError ):
5758 validator .validate (test_data )
5859
5960 assert strategy .validate_called
@@ -67,15 +68,6 @@ def test_given_empty_path_list_when_validate_then_validate_raises_exception(self
6768 with pytest .raises (ValueError ):
6869 validator .validate (test_data )
6970
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-
7971 def test_path_with_wildcard_when_validate_then_validate_is_successful (self ):
8072 strategy = MockValidationStrategy ()
8173 validator = DpathValidator (field_path = ["users" , "*" , "email" ], strategy = strategy )
0 commit comments