summaryrefslogtreecommitdiff
path: root/tests/test_exceptions.py
diff options
context:
space:
mode:
authorroberto berto <rberto@deepcausa.com>2025-11-02 22:54:44 +0000
committerroberto berto <rberto@deepcausa.com>2025-11-02 22:54:44 +0000
commit6b4e9015744ab8c9f17a6b8e23387cd676b1d827 (patch)
tree4c0a634730df2123ff506252cbec050de006dac8 /tests/test_exceptions.py
parent1ada32975f0bb559ec7526e0dd545700dde1cb94 (diff)
downloadpyvyos-feat/architecture-and-quality-improvements.tar.gz
pyvyos-feat/architecture-and-quality-improvements.zip
feat: v0.4.0 - Architecture refactor, bug fixes, and quality improvementsfeat/architecture-and-quality-improvements
- Fixed #25: config_file_save/load now include path: [] in payload - Added exception hierarchy (SDKError, HttpError, ApiError, ValidationError) - Added utility functions (json, ids, paths) - Added structured logging with request ID tracking - Added optional Pydantic validation models - Refactored to pyvyos.core.* structure with backward compatibility shims - Moved JSON specs to docs/development/vyos_api/ - Added comprehensive test suite (19 shim tests, 16 utils tests, 6 exception tests) - Updated pyproject.toml for uv sync editable installation - Added development documentation (architecture, roadmap, quality guidelines) Maintains 100% backward compatibility with 0.3.0
Diffstat (limited to 'tests/test_exceptions.py')
-rw-r--r--tests/test_exceptions.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py
new file mode 100644
index 0000000..22a4f34
--- /dev/null
+++ b/tests/test_exceptions.py
@@ -0,0 +1,51 @@
+"""Tests for pyvyos.exceptions module."""
+
+import pytest
+
+from pyvyos.exceptions import SDKError, HttpError, ApiError, ValidationError
+
+
+def test_sdk_error_base():
+ """Test SDKError is base exception."""
+ assert issubclass(HttpError, SDKError)
+ assert issubclass(ApiError, SDKError)
+ assert issubclass(ValidationError, SDKError)
+
+
+def test_http_error():
+ """Test HttpError creation and attributes."""
+ error = HttpError(status=404, message="Not Found")
+ assert error.status == 404
+ assert error.message == "Not Found"
+ assert "404" in str(error)
+ assert "Not Found" in str(error)
+
+
+def test_api_error():
+ """Test ApiError creation."""
+ error = ApiError(message="API failure")
+ assert error.message == "API failure"
+ assert "API failure" in str(error)
+
+
+def test_api_error_with_details():
+ """Test ApiError with details."""
+ details = {"code": "ERR001", "field": "path"}
+ error = ApiError(message="Validation failed", details=details)
+ assert error.message == "Validation failed"
+ assert error.details == details
+
+
+def test_validation_error():
+ """Test ValidationError creation."""
+ error = ValidationError(message="Invalid path format")
+ assert error.message == "Invalid path format"
+ assert "Invalid path format" in str(error)
+
+
+def test_exceptions_raiseable():
+ """Test that exceptions can be raised and caught."""
+ with pytest.raises(HttpError) as exc_info:
+ raise HttpError(status=500, message="Internal Error")
+ assert exc_info.value.status == 500
+