def delete(request: Request) -> None: """Delete an URL.""" url = object_or_404( Url.by_slug(request.openapi_validated.parameters["path"]["slug"], db=request.db)) request.db.delete(url) return None
def update(request: Request) -> Url: """Update an URL.""" body = request.openapi_validated.body url = object_or_404( Url.by_slug(request.openapi_validated.parameters["path"]["slug"], db=request.db)) if getattr(body, "title", None): url.title = body.title if getattr(body, "description", None): url.description = body.description if getattr(body, "href", None): url.href = body.href return url
def redirect(request: Request) -> None: """Redirect to target.""" slug = request.matchdict["slug"] url = object_or_404(Url.by_slug(slug, db=request.db)) raise HTTPFound(url.href)
def url(request: Request) -> Url: """Get an URL.""" url = object_or_404( Url.by_slug(request.openapi_validated.parameters["path"]["slug"], db=request.db)) return url
def test_object_or_404() -> None: """Test the help guard that stops view code execution.""" with pytest.raises(HTTPNotFound): object_or_404(None) assert object_or_404("foo") == "foo"