-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathtest_errors.py
More file actions
38 lines (25 loc) · 1.4 KB
/
test_errors.py
File metadata and controls
38 lines (25 loc) · 1.4 KB
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
# Copyright (c) Microsoft. All rights reserved.
"""Unit tests for custom exception types."""
import pytest
from agent_framework_azurefunctions._errors import IncomingRequestError
class TestIncomingRequestError:
"""Test suite for IncomingRequestError exception."""
def test_incoming_request_error_default_status_code(self) -> None:
"""Test that IncomingRequestError has a default status code of 400."""
error = IncomingRequestError("Invalid request")
assert str(error) == "Invalid request"
assert error.status_code == 400
def test_incoming_request_error_custom_status_code(self) -> None:
"""Test that IncomingRequestError can have a custom status code."""
error = IncomingRequestError("Unauthorized", status_code=401)
assert str(error) == "Unauthorized"
assert error.status_code == 401
def test_incoming_request_error_is_value_error(self) -> None:
"""Test that IncomingRequestError inherits from ValueError."""
error = IncomingRequestError("Test error")
assert isinstance(error, ValueError)
def test_incoming_request_error_can_be_raised_and_caught(self) -> None:
"""Test that IncomingRequestError can be raised and caught."""
with pytest.raises(IncomingRequestError) as exc_info:
raise IncomingRequestError("Bad request", status_code=400)
assert exc_info.value.status_code == 400