-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_errors.py
More file actions
62 lines (44 loc) · 2 KB
/
Copy pathtest_errors.py
File metadata and controls
62 lines (44 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import pytest
from agentscore.errors import AgentScoreError
def test_fields_are_stored():
err = AgentScoreError(code="not_found", message="Address not found", status_code=404)
assert err.code == "not_found"
assert err.status_code == 404
assert str(err) == "Address not found"
def test_is_exception():
err = AgentScoreError(code="unauthorized", message="Invalid API key", status_code=401)
assert isinstance(err, Exception)
def test_can_be_raised_and_caught():
with pytest.raises(AgentScoreError) as exc_info:
raise AgentScoreError(code="rate_limited", message="Too many requests", status_code=429)
err = exc_info.value
assert err.code == "rate_limited"
assert err.status_code == 429
assert str(err) == "Too many requests"
def test_string_representation_uses_message():
err = AgentScoreError(code="server_error", message="Internal server error", status_code=500)
assert str(err) == "Internal server error"
def test_unknown_error_code():
err = AgentScoreError(code="unknown_error", message="Something went wrong", status_code=500)
assert err.code == "unknown_error"
assert err.status_code == 500
def test_details_defaults_to_empty_dict_when_omitted():
err = AgentScoreError(code="not_found", message="Not found", status_code=404)
assert err.details == {}
def test_status_property_aliases_status_code():
err = AgentScoreError(code="rate_limited", message="Too many requests", status_code=429)
assert err.status == 429
assert err.status == err.status_code
def test_details_preserves_response_body_fields_for_granular_recovery():
err = AgentScoreError(
code="wallet_signer_mismatch",
message="Signer mismatch",
status_code=403,
details={
"claimed_operator": "op_abc",
"actual_signer": "0xdef",
"linked_wallets": ["0xabc", "0xdef"],
},
)
assert err.details["claimed_operator"] == "op_abc"
assert err.details["linked_wallets"] == ["0xabc", "0xdef"]