Skip to content

Commit

Permalink
Add view raising an exception
Browse files Browse the repository at this point in the history
  • Loading branch information
jrobichaud committed Nov 28, 2019
1 parent 2cb4207 commit b75056c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def uncaught_exception_view(request):
),
url(r"^failing_task$", views.enqueue_failing_task, name="enqueue_failing_task"),
url(r"^nesting_task$", views.enqueue_nesting_task, name="enqueue_nesting_task"),
url(r"^raise_exception", views.raise_exception, name="raise_exception"),
url(r"^api_view$", api_views.home_api_view, name="api_view"),
url(
r"^about/", TemplateView.as_view(template_name="pages/about.html"), name="about"
Expand Down
7 changes: 7 additions & 0 deletions django_structlog_demo_project/home/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,10 @@ class TestEnqueueNestingTask:
def test(self):
response = views.enqueue_nesting_task(None)
assert response.status_code == 201


class TestRaiseException:
def test(self):
with pytest.raises(Exception) as e:
views.raise_exception(None)
assert str(e.value) == "This is a view raising an exception."
4 changes: 4 additions & 0 deletions django_structlog_demo_project/home/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ def enqueue_nesting_task(request):
logger.info("Enqueuing nesting task")
nesting_task.delay()
return HttpResponse(status=201)


def raise_exception(request):
raise Exception("This is a view raising an exception.")
6 changes: 6 additions & 0 deletions django_structlog_demo_project/templates/pages/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
</form>
<button type="submit" form="form3" value="Submit">Enqueue nesting task</button>
</div>
<div>
<form action="{% url 'raise_exception' %}" method="post" id="form4">
{% csrf_token %}
</form>
<button type="submit" form="form4" value="Submit">Raise exception</button>
</div>

<div>
<a href="{% url 'api_view' %}">rest-framework API View</a>
Expand Down

0 comments on commit b75056c

Please sign in to comment.