summaryrefslogtreecommitdiff
path: root/tests/test_exceptions.py
blob: 22a4f34433c58d7566a68e09b2bc6c0f377b9d9d (plain)
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
"""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