Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#73 405 method not allowed on put/post/delete request methods #74

Merged
merged 3 commits into from
Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tests/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ def test_redirect(self, app):
res = app.get("/foobar/18", status=303)
assert res.status == "303 See Other"

def test_redirect_not_allowed(self, app):
res = app.post("/foobar/18", status=405)
assert res.status == "405 Method Not Allowed"

def test_redirect_no_match(self, app):
res = app.get("/test", status=404)
assert res.status == "404 Not Found"
Expand Down
8 changes: 7 additions & 1 deletion urihandler/views.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from pyramid.httpexceptions import HTTPBadRequest
from pyramid.httpexceptions import HTTPMethodNotAllowed
from pyramid.httpexceptions import HTTPNotFound
from pyramid.httpexceptions import HTTPSeeOther
from pyramid.view import view_config

from urihandler.utils import create_version_hash


@view_config(route_name="redirect")
@view_config(route_name="redirect", request_method=("GET", "HEAD", "OPTIONS"))
def redirect(request):
uri = request.host_url + "/" + request.matchdict["uri"]
redirect = request.uri_handler.handle(uri, request)
Expand All @@ -15,6 +16,11 @@ def redirect(request):
return HTTPSeeOther(redirect)


@view_config(route_name="redirect")
def redirect_not_allowed(request):
raise HTTPMethodNotAllowed()


@view_config(route_name="handle")
def handle(request):
uri = request.params.get("uri", None)
Expand Down