forked from aio-libs/aiohttp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_payload.py
More file actions
65 lines (45 loc) · 1.61 KB
/
Copy pathtest_payload.py
File metadata and controls
65 lines (45 loc) · 1.61 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
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
from io import StringIO
import pytest
from aiohttp import payload
@pytest.fixture
def registry():
old = payload.PAYLOAD_REGISTRY
reg = payload.PAYLOAD_REGISTRY = payload.PayloadRegistry()
yield reg
payload.PAYLOAD_REGISTRY = old
class Payload(payload.Payload):
async def write(self, writer):
pass
def test_register_type(registry):
class TestProvider:
pass
payload.register_payload(Payload, TestProvider)
p = payload.get_payload(TestProvider())
assert isinstance(p, Payload)
def test_payload_ctor():
p = Payload('test', encoding='utf-8', filename='test.txt')
assert p._value == 'test'
assert p._encoding == 'utf-8'
assert p.size is None
assert p.filename == 'test.txt'
assert p.content_type == 'text/plain'
def test_payload_content_type():
p = Payload('test', headers={'content-type': 'application/json'})
assert p.content_type == 'application/json'
def test_string_payload():
p = payload.StringPayload('test')
assert p.encoding == 'utf-8'
assert p.content_type == 'text/plain; charset=utf-8'
p = payload.StringPayload('test', encoding='koi8-r')
assert p.encoding == 'koi8-r'
assert p.content_type == 'text/plain; charset=koi8-r'
p = payload.StringPayload(
'test', content_type='text/plain; charset=koi8-r')
assert p.encoding == 'koi8-r'
assert p.content_type == 'text/plain; charset=koi8-r'
def test_string_io_payload():
s = StringIO('ű' * 5000)
p = payload.StringIOPayload(s)
assert p.encoding == 'utf-8'
assert p.content_type == 'text/plain; charset=utf-8'
assert p.size == 10000