@@ -49,3 +49,61 @@ def test_package_root_exports_error_classes():
4949 assert shade .InvalidRequestError is InvalidRequestError
5050 assert shade .NetworkError is NetworkError
5151 assert shade .NotFoundError is NotFoundError
52+
53+
54+ def test_not_found_error_is_shade_error ():
55+ error = NotFoundError ("not found" , status_code = 404 )
56+ assert isinstance (error , ShadeError )
57+
58+
59+ def test_not_found_error_parses_resource_from_body ():
60+ body = '{"resource_type": "payment", "resource_id": "pay_abc123"}'
61+ error = NotFoundError ("not found" , status_code = 404 , response_body = body )
62+
63+ assert error .resource_type == "payment"
64+ assert error .resource_id == "pay_abc123"
65+
66+
67+ def test_not_found_error_explicit_attrs_override_body ():
68+ body = '{"resource_type": "invoice", "resource_id": "inv_999"}'
69+ error = NotFoundError (
70+ "not found" ,
71+ status_code = 404 ,
72+ response_body = body ,
73+ resource_type = "payment" ,
74+ resource_id = "pay_001" ,
75+ )
76+
77+ assert error .resource_type == "payment"
78+ assert error .resource_id == "pay_001"
79+
80+
81+ def test_not_found_error_none_when_body_missing ():
82+ error = NotFoundError ("not found" , status_code = 404 )
83+
84+ assert error .resource_type is None
85+ assert error .resource_id is None
86+
87+
88+ def test_not_found_error_none_when_body_lacks_fields ():
89+ error = NotFoundError ("not found" , status_code = 404 , response_body = '{"error":"gone"}' )
90+
91+ assert error .resource_type is None
92+ assert error .resource_id is None
93+
94+
95+ def test_not_found_error_from_response_factory ():
96+ body = '{"resource_type": "invoice", "resource_id": "inv_456"}'
97+ error = NotFoundError .from_response ("invoice not found" , response_body = body )
98+
99+ assert error .status_code == 404
100+ assert error .resource_type == "invoice"
101+ assert error .resource_id == "inv_456"
102+ assert isinstance (error , ShadeError )
103+
104+
105+ def test_not_found_error_invalid_json_body ():
106+ error = NotFoundError ("not found" , status_code = 404 , response_body = "not-json" )
107+
108+ assert error .resource_type is None
109+ assert error .resource_id is None
0 commit comments