Skip to content

Commit

Permalink
Show an alert when users cancel a job request
Browse files Browse the repository at this point in the history
  • Loading branch information
ghickman committed Sep 12, 2023
1 parent 3807c55 commit 6a6db35
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions jobserver/views/job_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ def post(self, request, *args, **kwargs):
job_request.cancelled_actions = actions
job_request.save()

messages.success(request, "The requested actions have been cancelled")

return redirect(job_request)


Expand Down
24 changes: 24 additions & 0 deletions tests/unit/jobserver/views/test_job_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ def test_jobrequestcancel_success(rf):
request = rf.post("/")
request.user = user

request.session = "session"
messages = FallbackStorage(request)
request._messages = messages

response = JobRequestCancel.as_view()(request, pk=job_request.pk)

assert response.status_code == 302
Expand All @@ -76,6 +80,10 @@ def test_jobrequestcancel_success(rf):
assert "test2" in job_request.cancelled_actions
assert "test3" in job_request.cancelled_actions

messages = list(messages)
assert len(messages) == 1
assert str(messages[0]) == "The requested actions have been cancelled"


def test_jobrequestcancel_partially_completed(rf):
job_request = JobRequestFactory(cancelled_actions=[])
Expand All @@ -93,6 +101,10 @@ def test_jobrequestcancel_partially_completed(rf):
request = rf.post("/")
request.user = user

request.session = "session"
messages = FallbackStorage(request)
request._messages = messages

response = JobRequestCancel.as_view()(request, pk=job_request.pk)

assert response.status_code == 302
Expand All @@ -101,6 +113,10 @@ def test_jobrequestcancel_partially_completed(rf):
job_request.refresh_from_db()
assert sorted(job_request.cancelled_actions) == ["test3", "test4"]

messages = list(messages)
assert len(messages) == 1
assert str(messages[0]) == "The requested actions have been cancelled"


def test_jobrequestcancel_with_job_request_creator(rf):
user = UserFactory()
Expand All @@ -110,6 +126,10 @@ def test_jobrequestcancel_with_job_request_creator(rf):
request = rf.post("/")
request.user = user

request.session = "session"
messages = FallbackStorage(request)
request._messages = messages

response = JobRequestCancel.as_view()(request, pk=job_request.pk)

assert response.status_code == 302
Expand All @@ -118,6 +138,10 @@ def test_jobrequestcancel_with_job_request_creator(rf):
job_request.refresh_from_db()
assert "test1" in job_request.cancelled_actions

messages = list(messages)
assert len(messages) == 1
assert str(messages[0]) == "The requested actions have been cancelled"


def test_jobrequestcancel_unauthorized(rf):
job_request = JobRequestFactory()
Expand Down

0 comments on commit 6a6db35

Please sign in to comment.