Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ default_install_hook_types:
- post-rewrite
exclude: |
(?x)^(
otdf_python/.*
| otdf-python-proto/proto-files/.*
| otdf-python-proto/generated/.*
| otdf-python-proto/src/otdf_python_proto/.*
| otdf-python-proto/buf.yaml
| otdf-python-proto/buf.gen.yaml
otdf-python-proto/generated/.*
| packages/otdf-python-proto/src/otdf_python_proto/.*
| packages/otdf-python-proto/proto-files/.*
| packages/otdf-python-proto/buf.yaml
| packages/otdf-python-proto/buf.gen.yaml
)$
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks#
Expand All @@ -29,12 +28,12 @@ repos:
[
"--ignore-words-list",
"b-long, otdf_python",
"--skip=uv.lock,otdf-python-proto/uv.lock",
"--skip=uv.lock",
]

- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.15.12
rev: v0.15.15
hooks:
# Run the linter.
- id: ruff-check
Expand All @@ -45,4 +44,4 @@ repos:
hooks:
- id: conventional-pre-commit
stages: [commit-msg]
args: [--verbose, feat, fix, docs, style, test, chore, ci]
args: [--verbose, feat, fix, docs, style, refactor, perf, revert, build, test, chore, ci]
79 changes: 40 additions & 39 deletions tests/test_sdk.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Basic tests for the Python SDK class."""

import pytest
from otdf_python.sdk import SDK


Expand All @@ -23,84 +24,84 @@ def test_sdk_init_and_close():
# Test context manager exit calls close
with SDK(services):
pass
Comment thread
b-long marked this conversation as resolved.
# Optionally, check if close was called if you want
assert services.closed


def test_split_key_exception():
"""Test SDK SplitKeyException."""
try:
with pytest.raises(SDK.SplitKeyException, match="split key error"):
raise SDK.SplitKeyException("split key error")
except SDK.SplitKeyException:
pass


def test_data_size_not_supported():
"""Test SDK DataSizeNotSupported exception."""
try:
with pytest.raises(SDK.DataSizeNotSupported, match="too large"):
raise SDK.DataSizeNotSupported("too large")
except SDK.DataSizeNotSupported:
pass


def test_kas_info_missing():
"""Test SDK KasInfoMissing exception."""
try:
with pytest.raises(SDK.KasInfoMissing, match="kas info missing"):
raise SDK.KasInfoMissing("kas info missing")
except SDK.KasInfoMissing:
pass


def test_kas_public_key_missing():
"""Test SDK KasPublicKeyMissing exception."""
try:
with pytest.raises(SDK.KasPublicKeyMissing, match="kas pubkey missing"):
raise SDK.KasPublicKeyMissing("kas pubkey missing")
except SDK.KasPublicKeyMissing:
pass


def test_tamper_exception():
"""Test SDK TamperException."""
try:
"""Test SDK TamperException prefixes message with [tamper detected]."""
with pytest.raises(SDK.TamperException, match=r"\[tamper detected\] tamper"):
raise SDK.TamperException("tamper")
except SDK.TamperException:
pass


def test_root_signature_validation_exception():
"""Test SDK RootSignatureValidationException."""
try:
"""Test SDK RootSignatureValidationException includes tamper prefix."""
with pytest.raises(
SDK.RootSignatureValidationException, match=r"\[tamper detected\] root sig"
):
raise SDK.RootSignatureValidationException("root sig")
except SDK.RootSignatureValidationException:
pass


def test_segment_signature_mismatch():
"""Test SDK SegmentSignatureMismatch exception."""
try:
"""Test SDK SegmentSignatureMismatch includes tamper prefix."""
with pytest.raises(
SDK.SegmentSignatureMismatch, match=r"\[tamper detected\] seg sig"
):
raise SDK.SegmentSignatureMismatch("seg sig")
except SDK.SegmentSignatureMismatch:
pass


def test_kas_bad_request_exception():
"""Test SDK KasBadRequestException."""
try:
with pytest.raises(SDK.KasBadRequestException, match="kas bad req"):
raise SDK.KasBadRequestException("kas bad req")
except SDK.KasBadRequestException:
pass


def test_kas_allowlist_exception():
"""Test SDK KasAllowlistException."""
try:
raise SDK.KasAllowlistException("kas allowlist")
except SDK.KasAllowlistException:
pass
def test_kas_allowlist_exception_custom_message():
"""Test SDK KasAllowlistException with explicit message."""
with pytest.raises(SDK.KasAllowlistException, match="kas allowlist"):
raise SDK.KasAllowlistException(
"http://kas.example.com", message="kas allowlist"
)


def test_kas_allowlist_exception_auto_message():
"""Test SDK KasAllowlistException auto-generates message from url and origins."""
exc = SDK.KasAllowlistException(
"http://kas.example.com", allowed_origins={"http://allowed.com"}
)
assert exc.url == "http://kas.example.com"
assert "http://kas.example.com" in str(exc)
assert "http://allowed.com" in str(exc)


def test_assertion_exception():
"""Test SDK AssertionException."""
try:
raise SDK.AssertionException("assertion", "id123")
except SDK.AssertionException:
pass
"""Test SDK AssertionException stores assertion_id."""
exc = SDK.AssertionException("assertion failed", "id123")
assert str(exc) == "assertion failed"
assert exc.assertion_id == "id123"

with pytest.raises(SDK.AssertionException, match="assertion failed"):
raise SDK.AssertionException("assertion failed", "id123")
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading