File: test_errors.py

package info (click to toggle)
aiohttp-wsgi 0.10.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 236 kB
  • sloc: python: 790; makefile: 19; sh: 8
file content (22 lines) | stat: -rw-r--r-- 738 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import sys
from typing import Iterable
from tests.base import AsyncTestCase
from aiohttp_wsgi.wsgi import WSGIEnviron, WSGIStartResponse


def error_handling_application(environ: WSGIEnviron, start_response: WSGIStartResponse) -> Iterable[bytes]:
    try:
        start_response("200 OK", [])
        raise Exception("Boom!")
    except Exception:
        start_response("509 Boom", [], sys.exc_info())  # type: ignore
        return [b"Boom!"]


class ErrorsTest(AsyncTestCase):

    def testErrorHandling(self) -> None:
        with self.run_server(error_handling_application) as client:
            response = client.request()
            self.assertEqual(response.status, 509)
            self.assertEqual(response.content, b"Boom!")