Skip to content

Commit

Permalink
fix: Assume page_id is numeric (#51)
Browse files Browse the repository at this point in the history
* fix: Assume page_id is numeric

* WIP

* Fix formatting
  • Loading branch information
adinhodovic committed Aug 30, 2021
1 parent c8431c4 commit a7037f0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "wagtail-resume"
authors = ["Adin Hodovic <hodovicadin@gmail.com>"]
license = "MIT"
version = "1.3.1"
version = "1.3.2"
readme = "README.md"
homepage = "https://github.com/adinhodovic/wagtail-resume"
repository = "https://github.com/adinhodovic/wagtail-resume"
Expand Down
14 changes: 14 additions & 0 deletions tests/test_weasyprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,20 @@ def test_weasyprint_with_no_page_id(client, mocker):
assert res.status_code == 400


def test_weasyprint_with_no_number(client, mocker):
mocker.patch("wagtail_resume.views.HTML")
site = Site.objects.first()
resume = CustomResumePage(
title="Resume", full_name="Adin Hodovic", role="Software engineer", font="lato"
)
site.root_page.add_child(instance=resume)
# Test random page pdf generation
url = f"{reverse('generate_resume_pdf')}?page_id={resume.id}'"
res = client.get(url)
assert b"Page id is not a number" in res.content
assert res.status_code == 400


def test_weasyprint_no_resume(client, mocker):
mocker.patch("wagtail_resume.views.HTML")
site = Site.objects.first()
Expand Down
3 changes: 3 additions & 0 deletions wagtail_resume/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ def resume_pdf(request):
page_id = request.GET.get("page_id")
if not page_id:
return HttpResponseBadRequest("Missing page id for resume generation")
if not page_id.isnumeric():
return HttpResponseBadRequest("Page id is not a number")

response = HttpResponse(content_type="application/pdf")
resume = Page.objects.filter(id=page_id).first()

Expand Down

0 comments on commit a7037f0

Please sign in to comment.