]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Increase test coverage
authorTom Christie <tom@tomchristie.com>
Wed, 8 May 2019 12:52:26 +0000 (13:52 +0100)
committerTom Christie <tom@tomchristie.com>
Wed, 8 May 2019 12:52:26 +0000 (13:52 +0100)
tests/models/test_requests.py
tests/models/test_responses.py

index 77baa774256c2aba3906f5b2aa97b6e13b0f3a6d..98eea510dce422295561054bbd16ea427a89c178 100644 (file)
@@ -3,6 +3,11 @@ import pytest
 import httpcore
 
 
+def test_request_repr():
+    request = httpcore.Request("GET", "http://example.org")
+    assert repr(request) == "<Request('GET', 'http://example.org')>"
+
+
 def test_host_header():
     request = httpcore.Request("GET", "http://example.org")
     request.prepare()
index bfe8c113d77d8bcfb6cd574cec927ac680652f2d..8ecd37ab5c4aee4be5475f5331a14fa3f62a5ee2 100644 (file)
@@ -15,6 +15,11 @@ def test_response():
     assert response.text == "Hello, world!"
 
 
+def test_response_repr():
+    response = httpcore.Response(200, content=b"Hello, world!")
+    assert repr(response) == "<Response(200, 'OK')>"
+
+
 def test_response_content_type_encoding():
     """
     Use the charset encoding in the Content-Type header if possible.
@@ -47,7 +52,7 @@ def test_response_fallback_to_autodetect():
     assert response.encoding == "EUC-JP"
 
 
-def test_response():
+def test_response_default_text_encoding():
     """
     A media type of 'text/*' with no charset should default to ISO-8859-1.
     See: https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7.1
@@ -69,6 +74,16 @@ def test_response_default_encoding():
     assert response.encoding == "utf-8"
 
 
+def test_response_non_text_encoding():
+    """
+    Default to apparent encoding for non-text content-type headers.
+    """
+    headers = {"Content-Type": "image/png"}
+    response = httpcore.Response(200, content=b"xyz", headers=headers)
+    assert response.text == "xyz"
+    assert response.encoding == "ascii"
+
+
 def test_response_set_explicit_encoding():
     headers = {
         "Content-Type": "text-plain; charset=utf-8"