From 7db05c9cd7a1111aa779de35db2822e7022959e7 Mon Sep 17 00:00:00 2001 From: Ondrej Tuma Date: Tue, 17 Sep 2024 21:20:31 +0200 Subject: [PATCH] Some new tests --- examples/simple.py | 6 ++++++ poorwsgi/results.py | 4 ++-- tests/test_responses.py | 4 ++++ tests_integrity/test_simple.py | 7 +++++-- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/examples/simple.py b/examples/simple.py index 6b0830d..1ab9c65 100644 --- a/examples/simple.py +++ b/examples/simple.py @@ -680,6 +680,12 @@ def forbidden(req): raise HTTPException(state.HTTP_FORBIDDEN) +@app.route('/not-modified') +def not_modified_result(_): + """Test for raise not NotModifiedResponse""" + raise HTTPException(NotModifiedResponse(etag="012")) + + @app.route('/not-implemented') def not_implemented(req): """Test not implemented exception""" diff --git a/poorwsgi/results.py b/poorwsgi/results.py index cfecdbc..0c526e6 100644 --- a/poorwsgi/results.py +++ b/poorwsgi/results.py @@ -347,7 +347,7 @@ def method_not_allowed(req, error=None): # enddef -def not_implemented(req, code=None, error=None): +def not_implemented(req, code: int | None = None, error=None): """ 501 Not Implemented server error handler. """ if error: log.error("501 - Not Implemented: %s", error) @@ -372,7 +372,7 @@ def not_implemented(req, code=None, error=None): content += ( "

Your reqeuest %s returned not implemented\n" " status code %s.

\n" % (req.uri, code)) - log.error('Your reqeuest %s returned not implemented status code %d', + log.error('Your reqeuest %s returned not implemented status code %s', req.uri, code) else: content += ( diff --git a/tests/test_responses.py b/tests/test_responses.py index eab32cf..0c0b71b 100644 --- a/tests/test_responses.py +++ b/tests/test_responses.py @@ -564,6 +564,10 @@ def test_date_datetime(self): date=datetime.fromtimestamp(0, timezone.utc)) assert res.headers.get('Date') == "Thu, 01 Jan 1970 00:00:00 GMT" + def test_etag_only(self): + res = NotModifiedResponse(etag='W/"cd04a47544"') + assert res.headers.get("ETag") == 'W/"cd04a47544"' + def test_date_empty_string(self): res = NotModifiedResponse(date="") assert res.headers.get('Date') is None diff --git a/tests_integrity/test_simple.py b/tests_integrity/test_simple.py index ae2ab9a..b72da9a 100644 --- a/tests_integrity/test_simple.py +++ b/tests_integrity/test_simple.py @@ -2,10 +2,10 @@ from os import environ from os.path import dirname, join, pardir -from requests import Session from pytest import fixture +from requests import Session -from . support import start_server, check_url +from .support import check_url, start_server # pylint: disable=inconsistent-return-statements # pylint: disable=missing-function-docstring @@ -55,6 +55,9 @@ def test_static_not_modified(self, url): check_url(url+"/test/static", status_code=304, headers={'ETag': res.headers.get('ETag')}) + def test_exception_not_modified(self, url): + check_url(url+"/not-modified", status_code=304) + def test_variable_int(self, url): check_url(url+"/test/123")