File size: 5,469 Bytes
065fee7 |
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# Tests for http_exceptions.py
import pickle
from aiohttp import http_exceptions
class TestHttpProcessingError:
def test_ctor(self) -> None:
err = http_exceptions.HttpProcessingError(
code=500, message="Internal error", headers={}
)
assert err.code == 500
assert err.message == "Internal error"
assert err.headers == {}
def test_pickle(self) -> None:
err = http_exceptions.HttpProcessingError(
code=500, message="Internal error", headers={}
)
err.foo = "bar"
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
pickled = pickle.dumps(err, proto)
err2 = pickle.loads(pickled)
assert err2.code == 500
assert err2.message == "Internal error"
assert err2.headers == {}
assert err2.foo == "bar"
def test_str(self) -> None:
err = http_exceptions.HttpProcessingError(
code=500, message="Internal error", headers={}
)
assert str(err) == "500, message:\n Internal error"
def test_repr(self) -> None:
err = http_exceptions.HttpProcessingError(
code=500, message="Internal error", headers={}
)
assert repr(err) == ("<HttpProcessingError: 500, message='Internal error'>")
class TestBadHttpMessage:
def test_ctor(self) -> None:
err = http_exceptions.BadHttpMessage("Bad HTTP message", headers={})
assert err.code == 400
assert err.message == "Bad HTTP message"
assert err.headers == {}
def test_pickle(self) -> None:
err = http_exceptions.BadHttpMessage(message="Bad HTTP message", headers={})
err.foo = "bar"
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
pickled = pickle.dumps(err, proto)
err2 = pickle.loads(pickled)
assert err2.code == 400
assert err2.message == "Bad HTTP message"
assert err2.headers == {}
assert err2.foo == "bar"
def test_str(self) -> None:
err = http_exceptions.BadHttpMessage(message="Bad HTTP message", headers={})
assert str(err) == "400, message:\n Bad HTTP message"
def test_repr(self) -> None:
err = http_exceptions.BadHttpMessage(message="Bad HTTP message", headers={})
assert repr(err) == "<BadHttpMessage: 400, message='Bad HTTP message'>"
class TestLineTooLong:
def test_ctor(self) -> None:
err = http_exceptions.LineTooLong("spam", "10", "12")
assert err.code == 400
assert err.message == "Got more than 10 bytes (12) when reading spam."
assert err.headers is None
def test_pickle(self) -> None:
err = http_exceptions.LineTooLong(line="spam", limit="10", actual_size="12")
err.foo = "bar"
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
pickled = pickle.dumps(err, proto)
err2 = pickle.loads(pickled)
assert err2.code == 400
assert err2.message == ("Got more than 10 bytes (12) " "when reading spam.")
assert err2.headers is None
assert err2.foo == "bar"
def test_str(self) -> None:
err = http_exceptions.LineTooLong(line="spam", limit="10", actual_size="12")
expected = "400, message:\n Got more than 10 bytes (12) when reading spam."
assert str(err) == expected
def test_repr(self) -> None:
err = http_exceptions.LineTooLong(line="spam", limit="10", actual_size="12")
assert repr(err) == (
"<LineTooLong: 400, message='Got more than "
"10 bytes (12) when reading spam.'>"
)
class TestInvalidHeader:
def test_ctor(self) -> None:
err = http_exceptions.InvalidHeader("X-Spam")
assert err.code == 400
assert err.message == "Invalid HTTP header: 'X-Spam'"
assert err.headers is None
def test_pickle(self) -> None:
err = http_exceptions.InvalidHeader(hdr="X-Spam")
err.foo = "bar"
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
pickled = pickle.dumps(err, proto)
err2 = pickle.loads(pickled)
assert err2.code == 400
assert err2.message == "Invalid HTTP header: 'X-Spam'"
assert err2.headers is None
assert err2.foo == "bar"
def test_str(self) -> None:
err = http_exceptions.InvalidHeader(hdr="X-Spam")
assert str(err) == "400, message:\n Invalid HTTP header: 'X-Spam'"
def test_repr(self) -> None:
err = http_exceptions.InvalidHeader(hdr="X-Spam")
expected = "<InvalidHeader: 400, message=\"Invalid HTTP header: 'X-Spam'\">"
assert repr(err) == expected
class TestBadStatusLine:
def test_ctor(self) -> None:
err = http_exceptions.BadStatusLine("Test")
assert err.line == "Test"
assert str(err) == "400, message:\n Bad status line 'Test'"
def test_ctor2(self) -> None:
err = http_exceptions.BadStatusLine(b"")
assert err.line == "b''"
assert str(err) == "400, message:\n Bad status line \"b''\""
def test_pickle(self) -> None:
err = http_exceptions.BadStatusLine("Test")
err.foo = "bar"
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
pickled = pickle.dumps(err, proto)
err2 = pickle.loads(pickled)
assert err2.line == "Test"
assert err2.foo == "bar"
|