Skip to content

Commit

Permalink
added tests on content body
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurprioli committed Jan 8, 2025
1 parent 03bb7c0 commit 8fdf4aa
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/test_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,45 @@ def on_post(self, req, resp):
assert result.text == response


@pytest.mark.skipif(not msgpack, reason='msgpack not installed')
@pytest.mark.parametrize(
'value',
(
'd\xff\xff\x00',
'quick fox jumps over the lazy dog',
'{"hello": "WORLD!"}',
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praese',
'{"hello": "WORLD!", "greetings": "fellow traveller"}',
'\xe9\xe8',
),
)
def test_simulate_request_msgpack_different_bodies(value):
value = bytes(value, 'UTF-8')

resource = testing.SimpleTestResource(body=value)

app = App()
app.add_route('/', resource)

result = testing.simulate_post(app, '/', msgpack={})
captured_resp = resource.captured_resp
content = captured_resp.text

if len(value) > 40:
content = value[:20] + b'...' + value[-20:]
else:
content = value

args = [
captured_resp.status,
captured_resp.headers['content-type'],
str(content),
]

expected_content = 'Result<{}>'.format(' '.join(filter(None, args)))
assert str(result) == expected_content


@pytest.mark.parametrize('mode', ['wsgi', 'asgi', 'asgi-stream'])
def test_content_type(util, mode):
class Responder:
Expand Down

0 comments on commit 8fdf4aa

Please sign in to comment.