mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-12-06 07:55:10 +00:00
test: delete slow, timing-based and redundant tests
This commit is contained in:
@@ -59,11 +59,6 @@ def test_api_error_default_http_status_per_code() -> None:
|
||||
assert all(status < 500 for status in cases.values())
|
||||
|
||||
|
||||
def test_api_error_explicit_http_status_overrides_default() -> None:
|
||||
err = APIError(APIErrorCode.INVALID_INPUT, "x", http_status=418)
|
||||
assert err.http_status == 418
|
||||
|
||||
|
||||
def test_build_error_response_from_api_error() -> None:
|
||||
err = APIError(
|
||||
APIErrorCode.SESSION_NOT_FOUND,
|
||||
@@ -83,12 +78,6 @@ def test_build_error_response_from_api_error() -> None:
|
||||
assert "timestamp" in body
|
||||
|
||||
|
||||
def test_build_error_response_retryable_flag() -> None:
|
||||
err = APIError(APIErrorCode.NETWORK_ERROR, "boom", retryable=True)
|
||||
body = _body(build_error_response(err))
|
||||
assert body["retryable"] is True
|
||||
|
||||
|
||||
def test_build_error_response_from_generic_exception() -> None:
|
||||
resp = build_error_response(RuntimeError("oops"))
|
||||
assert resp.status == 422
|
||||
@@ -97,12 +86,6 @@ def test_build_error_response_from_generic_exception() -> None:
|
||||
assert body["message"] == f"oops (ref {body['ref']})"
|
||||
|
||||
|
||||
def test_categorize_fallback_names_no_exception_class() -> None:
|
||||
err = categorize_exception(RuntimeError("oops"), context={"op": "x"})
|
||||
assert err.error_code == APIErrorCode.INTERNAL_ERROR
|
||||
assert err.details == {"op": "x"}
|
||||
|
||||
|
||||
def test_build_error_response_debug_mode_includes_traceback() -> None:
|
||||
try:
|
||||
raise ValueError("kaboom")
|
||||
@@ -182,34 +165,6 @@ def test_a_body_that_ended_early_is_a_retryable_network_error(make: Callable[[],
|
||||
assert (resp.status, body["error_code"], body.get("retryable")) == (424, "NETWORK_ERROR", True)
|
||||
|
||||
|
||||
def test_a_bad_content_encoding_is_no_network_error() -> None:
|
||||
assert categorize_exception(rnet_error(BAD_DEFLATE)).error_code != APIErrorCode.NETWORK_ERROR
|
||||
|
||||
|
||||
def test_a_bare_rnet_error_reads_as_its_short_cause() -> None:
|
||||
err = categorize_exception(rnet_error(SHORT_BODY))
|
||||
assert err.message == "Network error occurred: DecodingError (IncompleteBody)"
|
||||
|
||||
|
||||
def test_categorize_preserves_context() -> None:
|
||||
api_err = categorize_exception(ValueError("bad"), context={"op": "search"})
|
||||
assert api_err.details["op"] == "search"
|
||||
|
||||
|
||||
def test_handle_api_exception_with_api_error_preserves_code() -> None:
|
||||
err = APIError(APIErrorCode.TRACK_NOT_FOUND, "no track")
|
||||
resp = handle_api_exception(err)
|
||||
body = _body(resp)
|
||||
assert body["error_code"] == "TRACK_NOT_FOUND"
|
||||
assert resp.status == 404
|
||||
|
||||
|
||||
def test_handle_api_exception_categorizes_generic() -> None:
|
||||
resp = handle_api_exception(ConnectionError("oops"))
|
||||
body = _body(resp)
|
||||
assert body["error_code"] == "NETWORK_ERROR"
|
||||
|
||||
|
||||
# Locks the FULL observable response (http status, error_code, retryable) that
|
||||
# a client sees for a generic (non-APIError) exception flowing through the
|
||||
# handle_api_exception funnel that every route's `except Exception` path calls.
|
||||
@@ -341,16 +296,6 @@ def test_an_error_code_that_is_no_api_code_falls_back_to_the_keywords() -> None:
|
||||
assert categorize_exception(exc).error_code == APIErrorCode.NETWORK_ERROR
|
||||
|
||||
|
||||
def test_a_system_exit_stays_a_service_error_whatever_its_cause_names() -> None:
|
||||
try:
|
||||
try:
|
||||
raise coded(ValueError("bad"), APIErrorCode.INVALID_PROXY)
|
||||
except ValueError as e:
|
||||
raise SystemExit(1) from e
|
||||
except SystemExit as exit_:
|
||||
assert categorize_exception(exit_).error_code == APIErrorCode.SERVICE_ERROR
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"error",
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user