import httpx import os import tempfile # HTML def test_html(): html = httpx.HTML("
Hello, world") stream = html.encode() content_type = html.content_type() assert stream.read() == b'Hello, world' assert content_type == "text/html; charset='utf-8'" # Text def test_text(): text = httpx.Text("Hello, world") stream = text.encode() content_type = text.content_type() assert stream.read() == b'Hello, world' assert content_type == "text/plain; charset='utf-8'" # JSON def test_json(): data = httpx.JSON({'data': 123}) stream = data.encode() content_type = data.content_type() assert stream.read() == b'{"data":123}' assert content_type == "application/json" # Form def test_form(): f = httpx.Form("a=123&a=456&b=789") assert str(f) == "a=123&a=456&b=789" assert repr(f) == "