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

Nicer handling of job not found on the job details view #295

Merged
merged 2 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Nicer handling of job not found on the job details view
  • Loading branch information
plars committed Jun 28, 2024
commit bb167b3e4b262b04fac4e83f82ed38c734348cc4
11 changes: 11 additions & 0 deletions server/src/templates/job_not_found.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends 'base.html' %}
{% set active_page = 'jobs' %}
{% block content %}
<div class="p-strip is-shallow">
<div class="row">
<h1 class="p-heading--3">
Job not found: {{ job_id }}
</h1>
</div>
</div>
{% endblock %}
6 changes: 6 additions & 0 deletions server/src/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ def jobs():
def job_detail(job_id):
"""Job detail view"""
job_data = mongo.db.jobs.find_one({"job_id": job_id})
if not job_data:
response = make_response(
render_template("job_not_found.html", job_id=job_id)
)
response.status_code = 404
plars marked this conversation as resolved.
Show resolved Hide resolved
return response
return render_template("job_detail.html", job=job_data)


Expand Down
16 changes: 15 additions & 1 deletion server/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import mongomock
from mock import patch
from src.views import queues_data, agent_detail
from src.views import job_detail, queues_data, agent_detail


def test_queues():
Expand Down Expand Up @@ -96,3 +96,17 @@ def test_agent_not_found(testapp):

assert "Agent not found: agent1" in str(response.data)
assert response.status_code == 404


def test_job_not_found(testapp):
"""
Test that the job_detail fails gracefully when a job is not found
"""

mongo = mongomock.MongoClient()
with patch("src.views.mongo", mongo):
with testapp.test_request_context():
response = job_detail("job1")

assert "Job not found: job1" in str(response.data)
assert response.status_code == 404