Skip to content

Commit

Permalink
Add unit tests for bulk approval option
Browse files Browse the repository at this point in the history
  • Loading branch information
saruniitr committed Jan 9, 2025
1 parent 1f6797e commit 13cdb46
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 0 deletions.
102 changes: 102 additions & 0 deletions unit_tests/caseworker/advice/views/test_bulk_approval.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import pytest

from bs4 import BeautifulSoup
from pytest_django.asserts import assertTemplateUsed
from urllib import parse

from django.urls import reverse

from caseworker.queues.rules import BULK_APPROVE_ALLOWED_QUEUES
from core import client


@pytest.fixture
def mod_queue_id():
return BULK_APPROVE_ALLOWED_QUEUES["MOD_CAPPROT"]


@pytest.fixture
def fcdo_queue_id():
return "12346bed-fd45-4293-95b8-eda9468aa254"


@pytest.fixture
def mod_bulk_approval_url(request, mod_queue_id):
return reverse(f"queues:bulk_approval", kwargs={"pk": mod_queue_id})


@pytest.fixture
def mock_post_mod_bulk_approval_recommendation(requests_mock, mod_queue_id):
url = client._build_absolute_uri(f"/caseworker/queues/{mod_queue_id}/bulk-approval/")
yield requests_mock.post(url=url, json={}, status_code=201)


@pytest.fixture
def fcdo_queue_view(request, fcdo_queue_id):
return reverse(f"queues:cases", kwargs={"queue_pk": fcdo_queue_id})


@pytest.fixture
def mock_get_fcdo_queue_cases(requests_mock, fcdo_queue_id):
url = client._build_absolute_uri(f"/queues/{fcdo_queue_id}/")
yield requests_mock.get(url=url, json={})


@pytest.fixture
def mock_fcdo_queue_detail(requests_mock, fcdo_queue_id):
url = client._build_absolute_uri(f"/queues/{fcdo_queue_id}/")
yield requests_mock.get(url=url, json={"id": fcdo_queue_id})


@pytest.fixture
def mock_fcdo_queue_search_data(requests_mock, fcdo_queue_id):
query_params = {"queue_id": fcdo_queue_id, "page": 1, "selected_tab": "all_cases", "hidden": False}
url = client._build_absolute_uri(f"/cases/")
url = f"{url}?{parse.urlencode(query_params, doseq=True)}"
yield requests_mock.get(url=url, json={"results": {"cases": [], "filters": {"gov_users": []}}})


def test_user_bulk_approval_success(
authorized_client,
requests_mock,
MOD_team1_user,
mod_bulk_approval_url,
mock_gov_mod_capprot_user,
mock_post_mod_bulk_approval_recommendation,
):
data = {
"cases": ["54725d74-e900-43b1-b2cb-2af44ae9182d", "2468bc19-979d-4ba3-a57c-b0ce253c6237"],
"advice": {
"text": "Approved using bulk approval",
"proviso": "",
"note": "",
"footnote_required": False,
"footnote": "",
"team": str(MOD_team1_user["team"]["id"]),
},
}
response = authorized_client.post(mod_bulk_approval_url, data=data)
assert response.status_code == 302

bulk_approval_request = requests_mock.request_history.pop()
assert bulk_approval_request.method == "POST"
assert bulk_approval_request.json() == data


def test_bulk_approval_missing_for_nonpermitted_users(
authorized_client,
fcdo_queue_view,
mock_get_fcdo_queue_cases,
mock_fcdo_queue_search_data,
mock_cases_search_head,
mock_control_list_entries,
mock_regime_entries,
mock_countries,
mock_queues_list,
mock_fcdo_queue_detail,
mock_bookmarks,
):
response = authorized_client.get(fcdo_queue_view)
assertTemplateUsed(response, "queues/cases.html")
soup = BeautifulSoup(response.content, "html.parser")
assert soup.find("button", {"id": "bulk-approve-button"}) is None
9 changes: 9 additions & 0 deletions unit_tests/caseworker/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,15 @@ def mock_gov_fcdo_user(requests_mock, mock_notifications, mock_case_statuses, mo
requests_mock.get(url=re.compile(f"{url}{gov_uk_user_id}/"), json=mock_gov_user)


@pytest.fixture
def mock_gov_mod_capprot_user(requests_mock, mock_notifications, mock_case_statuses, mock_gov_user, MOD_team1_user):
mock_gov_user["user"]["team"] = MOD_team1_user["team"]

url = client._build_absolute_uri("/gov-users/")
requests_mock.get(url=f"{url}me/", json=mock_gov_user)
requests_mock.get(url=re.compile(f"{url}{gov_uk_user_id}/"), json=mock_gov_user)


@pytest.fixture
def mock_gov_desnz_nuclear_user(requests_mock, mock_notifications, mock_case_statuses, mock_gov_user):
mock_gov_user["user"]["team"] = {
Expand Down
18 changes: 18 additions & 0 deletions unit_tests/caseworker/queues/test_rules.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import pytest

from caseworker.queues import rules as caseworker_rules
from caseworker.queues.rules import BULK_APPROVE_ALLOWED_QUEUES


@pytest.mark.parametrize(
"queue, expected_result",
(
({"id": BULK_APPROVE_ALLOWED_QUEUES["MOD_CAPPROT"]}, True),
({"id": BULK_APPROVE_ALLOWED_QUEUES["MOD_DI_INDIRECT"]}, True),
({"id": BULK_APPROVE_ALLOWED_QUEUES["MOD_DSR"]}, True),
({"id": BULK_APPROVE_ALLOWED_QUEUES["MOD_DSTL"]}, True),
({"id": "fake_queue"}, False),
),
)
def test_can_user_bulk_approve_cases(get_mock_request_user, queue, expected_result):
assert caseworker_rules.can_user_bulk_approve_cases(get_mock_request_user(None), queue) is expected_result

0 comments on commit 13cdb46

Please sign in to comment.