Skip to content

Commit

Permalink
Fix error on approval form submission
Browse files Browse the repository at this point in the history
  • Loading branch information
currycoder committed Nov 29, 2024
1 parent c363c43 commit 8c6fede
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion caseworker/advice/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ def get_success_url(self):
return reverse("cases:view_my_advice", kwargs=self.kwargs)

@expect_status(
HTTPStatus.OK,
HTTPStatus.CREATED,
"Error adding approval advice",
"Unexpected error adding approval advice",
)
Expand Down
7 changes: 7 additions & 0 deletions unit_tests/caseworker/advice/views/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import pytest


@pytest.fixture
def mock_post_advice(requests_mock, data_standard_case):
user_advice_create_url = f"/cases/{data_standard_case['case']['id']}/user-advice/"
return requests_mock.post(user_advice_create_url, json={}, status_code=201)
10 changes: 4 additions & 6 deletions unit_tests/caseworker/advice/views/test_edit_advice.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,11 @@ def test_DESNZ_give_approval_advice_post_valid(
mock_approval_reason,
mock_proviso,
mock_footnote_details,
mock_post_advice,
standard_case_with_advice,
post_to_step,
beautiful_soup,
):
user_advice_create_url = f"/cases/{data_standard_case['case']['id']}/user-advice/"
requests_mock.post(user_advice_create_url, json={})
case_data = deepcopy(data_standard_case)
case_data["case"]["data"]["goods"] = standard_case_with_advice["data"]["goods"]
case_data["case"]["advice"] = standard_case_with_advice["advice"]
Expand Down Expand Up @@ -264,7 +263,7 @@ def test_DESNZ_give_approval_advice_post_valid(
{"approval_reasons": "reason updated", "add_licence_conditions": False},
)
assert response.status_code == 302
history = [item for item in requests_mock.request_history if user_advice_create_url in item.url]
history = mock_post_advice.request_history
assert len(history) == 1
history = history[0]
assert history.method == "POST"
Expand Down Expand Up @@ -342,12 +341,11 @@ def test_DESNZ_give_approval_advice_post_valid_add_conditional(
mock_approval_reason,
mock_proviso,
mock_footnote_details,
mock_post_advice,
standard_case_with_advice,
post_to_step,
beautiful_soup,
):
user_advice_create_url = f"/cases/{data_standard_case['case']['id']}/user-advice/"
requests_mock.post(user_advice_create_url, json={})
case_data = deepcopy(data_standard_case)
case_data["case"]["data"]["goods"] = standard_case_with_advice["data"]["goods"]
case_data["case"]["advice"] = standard_case_with_advice["advice"]
Expand Down Expand Up @@ -396,7 +394,7 @@ def test_DESNZ_give_approval_advice_post_valid_add_conditional(
{"instructions_to_exporter": "instructions updated", "footnote_details": "footnotes updated"},
)
assert add_instructions_response.status_code == 302
history = [item for item in requests_mock.request_history if user_advice_create_url in item.url]
history = mock_post_advice.request_history
assert len(history) == 1
history = history[0]
assert history.method == "POST"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ def post_to_step(post_to_step_factory, url_desnz):
def test_DESNZ_give_approval_advice_post_valid(
mock_get_gov_user,
authorized_client,
requests_mock,
data_standard_case,
url,
mock_approval_reason,
mock_proviso,
mock_footnote_details,
mock_post_advice,
post_to_step,
beautiful_soup,
):
Expand All @@ -152,7 +152,6 @@ def test_DESNZ_give_approval_advice_post_valid(
},
None,
)
requests_mock.post(f"/cases/{data_standard_case['case']['id']}/user-advice/", json={})

response = post_to_step(
AdviceView.RECOMMEND_APPROVAL,
Expand All @@ -165,12 +164,12 @@ def test_DESNZ_give_approval_advice_post_valid(
def test_DESNZ_give_approval_advice_post_valid_add_conditional(
mock_get_gov_user,
authorized_client,
requests_mock,
data_standard_case,
url,
mock_approval_reason,
mock_proviso,
mock_footnote_details,
mock_post_advice,
post_to_step,
beautiful_soup,
):
Expand All @@ -186,8 +185,6 @@ def test_DESNZ_give_approval_advice_post_valid_add_conditional(
},
None,
)
requests_mock.post(f"/cases/{data_standard_case['case']['id']}/user-advice/", json={})

response = post_to_step(
AdviceView.RECOMMEND_APPROVAL,
{"approval_reasons": "reason", "add_licence_conditions": True},
Expand Down Expand Up @@ -219,12 +216,12 @@ def test_DESNZ_give_approval_advice_post_valid_add_conditional(
def test_DESNZ_give_approval_advice_post_valid_add_conditional_optional(
mock_get_gov_user,
authorized_client,
requests_mock,
data_standard_case,
url,
mock_approval_reason,
mock_proviso,
mock_footnote_details,
mock_post_advice,
post_to_step,
beautiful_soup,
):
Expand All @@ -240,7 +237,6 @@ def test_DESNZ_give_approval_advice_post_valid_add_conditional_optional(
},
None,
)
requests_mock.post(f"/cases/{data_standard_case['case']['id']}/user-advice/", json={})

response = post_to_step(
AdviceView.RECOMMEND_APPROVAL,
Expand Down

0 comments on commit 8c6fede

Please sign in to comment.