Add tests

This commit is contained in:
taoufik07
2019-02-22 00:01:49 +01:00
parent 4ecfef0ddf
commit acd1561b1b
2 changed files with 27 additions and 3 deletions
+1 -3
View File
@@ -257,9 +257,7 @@ class Response:
"mimetype",
]
text = content_setter(
"text/plain"
) #: A unicode representation of the response body.
text = content_setter("text/plain")
html = content_setter("text/html")
def __init__(self, req, *, formats):
+26
View File
@@ -680,3 +680,29 @@ def test_staticfiles_custom_route(tmpdir):
# Not found on dir listing
r = session.get(f"{static_route}")
assert r.status_code == api.status_codes.HTTP_404
def test_response_html_property(api):
@api.route("/")
def view(req, resp):
resp.html = "<h1>Hello !</h1>"
assert resp.content == "<h1>Hello !</h1>"
assert resp.mimetype == "text/html"
r = api.requests.get(api.url_for(view))
assert r.content == b"<h1>Hello !</h1>"
assert r.headers["Content-Type"] == "text/html"
def test_response_text_property(api):
@api.route("/")
def view(req, resp):
resp.text = "<h1>Hello !</h1>"
assert resp.content == "<h1>Hello !</h1>"
assert resp.mimetype == "text/plain"
r = api.requests.get(api.url_for(view))
assert r.content == b"<h1>Hello !</h1>"
assert r.headers["Content-Type"] == "text/plain"