ForcePilot/backend/test/unit/channels/test_channels_imessage_exceptions.py

102 lines
3.1 KiB
Python
Raw Normal View History

from __future__ import annotations
import pytest
from yuxi.channels.adapters.imessage.exceptions import (
BlueBubblesAuthenticationError,
BlueBubblesConnectionError,
BlueBubblesHTTPError,
IMessageError,
TapbackError,
)
class TestIMessageError:
def test_default_values(self):
err = IMessageError("Something went wrong")
assert str(err) == "Something went wrong"
assert err.retryable is False
assert err.retry_after_ms == 0
def test_with_params(self):
err = IMessageError("Retry later", retryable=True, retry_after_ms=5000)
assert str(err) == "Retry later"
assert err.retryable is True
assert err.retry_after_ms == 5000
def test_is_channel_exception(self):
from yuxi.channels.exceptions import ChannelException
err = IMessageError("test")
assert isinstance(err, ChannelException)
assert isinstance(err, Exception)
class TestBlueBubblesHTTPError:
def test_basic_error(self):
err = BlueBubblesHTTPError(404, "Not found")
assert "404" in str(err)
assert "Not found" in str(err)
assert err.status_code == 404
assert err.retryable is False
def test_server_error_retryable(self):
err = BlueBubblesHTTPError(500, "Internal error")
assert err.retryable is True
def test_rate_limit_retryable(self):
err = BlueBubblesHTTPError(429, "Too many requests")
assert err.retryable is True
def test_client_error_not_retryable(self):
err = BlueBubblesHTTPError(400, "Bad request")
assert err.retryable is False
def test_is_iMessage_error(self):
err = BlueBubblesHTTPError(500)
assert isinstance(err, IMessageError)
def test_no_message(self):
err = BlueBubblesHTTPError(503)
assert "503" in str(err)
def test_custom_headers(self):
err = BlueBubblesHTTPError(401, "Unauthorized", headers={"Retry-After": "60"})
assert err.headers == {"Retry-After": "60"}
class TestBlueBubblesConnectionError:
def test_default_message(self):
err = BlueBubblesConnectionError()
assert "connection failed" in str(err).lower()
assert err.retryable is True
def test_custom_message(self):
err = BlueBubblesConnectionError("Custom connection error")
assert "Custom connection error" in str(err)
def test_retry_after(self):
err = BlueBubblesConnectionError()
assert err.retry_after_ms == 5000
class TestBlueBubblesAuthenticationError:
def test_default_message(self):
err = BlueBubblesAuthenticationError()
assert "authentication failed" in str(err).lower()
assert err.retryable is False
def test_custom_message(self):
err = BlueBubblesAuthenticationError("Invalid password")
assert "Invalid password" in str(err)
class TestTapbackError:
def test_default_message(self):
err = TapbackError()
assert "tapback" in str(err).lower()
assert err.retryable is False
def test_custom_message(self):
err = TapbackError("Unsupported emoji")
assert "Unsupported emoji" in str(err)