Skip to content

Commit

Permalink
fix: invalid certificate uuid should raise 404 (#1575)
Browse files Browse the repository at this point in the history
* fix: changed 500 to 404

* fix: black errors

* fix: black issues

* fix: some issues

* fix: code quality issues

* fix: black issues

* fix: some issues

* fix: some issues

* fix: black issues

* fix: black issues
  • Loading branch information
Anas12091101 authored Jul 15, 2024
1 parent 93dc1eb commit 14ffd37
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cms/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ def can_create_at(cls, parent):
and not parent.get_children().type(cls).exists()
)

@route(r"^([A-Fa-f0-9-]+)/?$")
@route(r"^([A-Fa-f0-9-]{36})/?$")
def bootcamp_certificate(
self, request, uuid, *args, **kwargs
): # pylint: disable=unused-argument
Expand Down
31 changes: 29 additions & 2 deletions cms/models_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,20 +345,27 @@ def test_certificate_for_bootcamp_run_page():


@override_settings(**{"FEATURES": {"ENABLE_CERTIFICATE_USER_VIEW": True}})
def test_certificate_index_page(rf):
def test_certificate_index_page(rf, user_client):
"""
test for certificate index page
"""
home_page = HomePageFactory()
assert models.CertificateIndexPage.can_create_at(home_page)

certifcate_index_page = CertificateIndexPageFactory.create(parent=home_page)
certifcate_index_page = CertificateIndexPageFactory.create(
parent=home_page, slug="certificate"
)
request = rf.get(certifcate_index_page.get_url())
bootcamp_run_page = BootcampRunPageFactory.create()
certificate = BootcampRunCertificateFactory.create(
bootcamp_run=bootcamp_run_page.bootcamp_run
)
certificate_page = CertificatePageFactory.create(parent=bootcamp_run_page)

# Test that certificate request is successful for bootcamp certificates.
resp = user_client.get(f"/certificate/{certificate.uuid}/")
assert resp.status_code == 200

request = rf.get(certificate_page.get_url())
assert (
certifcate_index_page.bootcamp_certificate(
Expand All @@ -380,3 +387,23 @@ def test_certificate_index_page(rf):

with pytest.raises(Http404):
certifcate_index_page.index_route(request)


@override_settings(**{"FEATURES": {"ENABLE_CERTIFICATE_USER_VIEW": True}})
@pytest.mark.parametrize(
"uuid_string",
[
"",
"1bebd843-ebf0-40c0-850e",
"1bebd843-ebf0-40c0-850e-fe73baa31b944444",
"1bebd843-ebf0-40c0-850e-fe73baa31b94-4ab4",
],
)
def test_certificate_request_with_invalid_uuid(user_client, uuid_string):
"""Test that bootcamp certificate request returns a 404 for invalid uuids."""
home_page = HomePageFactory()
CertificateIndexPageFactory.create(parent=home_page, slug="certificate")
bootcamp_run_page = BootcampRunPageFactory.create()
CertificatePageFactory.create(parent=bootcamp_run_page)
course_certificate_resp = user_client.get(f"/certificate/{uuid_string}/")
assert course_certificate_resp.status_code == 404

0 comments on commit 14ffd37

Please sign in to comment.