Skip to content

Commit 6cd64ae

Browse files
committed
✅ test: add test cases for RFC 9457 implementation
1 parent 04f9d69 commit 6cd64ae

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

osc_sdk/test_problems.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import json
2+
from typing import List
3+
4+
import pytest
5+
6+
from .sdk import Problem, ProblemDecoder
7+
8+
RAW_JSONS: List[str] = [
9+
r'{"type":"/errors/unsupported_media_type","status":415,"title":"Unsupported Media Type","detail":"Expected request with `Content-Type: application/json`"}',
10+
r'{"type":"/errors/invalid_parameter","status":400,"title":"Bad Request","detail":"Origin: unknown variant `BAD_VALUE`, expected `OSC_KMS` or `EXTERNAL`"}',
11+
r'{"type":"/errors/invalid_parameter","status":400,"title":"Bad Request","detail":"missing field `KeyId`"}',
12+
r'{"type":"/errors/invalid_parameter","status":400,"title":"Bad Request","detail":"KeyId: \'mck-toto\' is not a key ID, an alias name, a key ORN or an alias ORN"}',
13+
r'{"type":"/errors/invalid_parameter","status":404,"title":"Not Found","detail":"Key not found: mck-6480ba0cd94845deb4967f18c6b32cb1"}',
14+
]
15+
16+
17+
@pytest.mark.parametrize("raw_json", RAW_JSONS)
18+
def test_decode_raw_json_errors(raw_json: str):
19+
"""Test that ProblemDecoder can correctly decode raw JSON error strings."""
20+
decoded = json.loads(raw_json, cls=ProblemDecoder)
21+
assert isinstance(decoded, Problem)

0 commit comments

Comments
 (0)