Debian Codegraph @

tests/test_exceptions.py

raw
1 """Tests for the exceptions module."""
2
3 import pytest
4
5 from aiowebdav2.exceptions import (
6 AccessDeniedError,
7 ConflictError,
8 ConnectionExceptionError,
9 LocalResourceNotFoundError,
10 MethodNotSupportedError,
11 NoConnectionError,
12 NotEnoughSpaceError,
13 OptionNotValidError,
14 RemoteParentNotFoundError,
15 RemoteResourceNotFoundError,
16 ResourceLockedError,
17 ResponseErrorCodeError,
18 UnauthorizedError,
19 )
20
21
22 @pytest.mark.parametrize(
23 ("exc", "expected"),
24 [
25 (
26 OptionNotValidError(name="path", value="bad", ns="webdav_"),
27 "Option (webdav_path=bad) have invalid name or value",
28 ),
29 (
30 LocalResourceNotFoundError("/missing"),
31 "Local file: /missing not found",
32 ),
33 (
34 RemoteResourceNotFoundError("/missing"),
35 "Remote resource: /missing not found",
36 ),
37 (
38 RemoteParentNotFoundError("/parent"),
39 "Remote parent for: /parent not found",
40 ),
41 (
42 MethodNotSupportedError(name="check", server="https://example.com"),
43 "Method 'check' not supported for https://example.com",
44 ),
45 (
46 NoConnectionError("https://example.com"),
47 "No connection with https://example.com",
48 ),
49 (
50 ResponseErrorCodeError(
51 url="https://example.com/file", code=500, message="boom"
52 ),
53 "Request to https://example.com/file failed with code 500 and message: boom",
54 ),
55 (
56 NotEnoughSpaceError(),
57 "Not enough space on the server",
58 ),
59 (
60 ResourceLockedError("/locked"),
61 "Resource /locked locked",
62 ),
63 (
64 UnauthorizedError("https://example.com"),
65 "Unauthorized access to https://example.com",
66 ),
67 (
68 AccessDeniedError("https://example.com"),
69 "Access denied to https://example.com",
70 ),
71 (
72 ConflictError("/file", "conflict"),
73 "Conflict error for /file with message conflict",
74 ),
75 ],
76 )
77 def test_exception_str(exc: Exception, expected: str) -> None:
78 """Test exception string representation."""
79 assert str(exc) == expected
80
81
82 def test_connection_exception_str() -> None:
83 """Test connection exception string representation."""
84 exc = ConnectionExceptionError(RuntimeError("boom"))
85 assert str(exc) == "boom"