Skip to content

Commit

Permalink
Some new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ondratu committed Sep 17, 2024
1 parent f14ca59 commit 7db05c9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
6 changes: 6 additions & 0 deletions examples/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
4 changes: 2 additions & 2 deletions poorwsgi/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -372,7 +372,7 @@ def not_implemented(req, code=None, error=None):
content += (
" <p>Your reqeuest <code>%s</code> returned not implemented\n"
" status code <code>%s</code>.</p>\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 += (
Expand Down
4 changes: 4 additions & 0 deletions tests/test_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 5 additions & 2 deletions tests_integrity/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")

Expand Down

0 comments on commit 7db05c9

Please sign in to comment.