Skip to content

LTD-6169 add generated documents to caseworker docs tab #2472

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
65 changes: 61 additions & 4 deletions caseworker/f680/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
import uuid
import io

from django.http import StreamingHttpResponse
Expand Down Expand Up @@ -444,7 +445,7 @@ def supporting_document(data_f680_case):
def document_data(data_f680_case):
return [
{
"id": "a66ebfb3-72c8-4a63-82f6-0519830729ce", # /PS-IGNORE
"id": str(uuid.uuid4()), # /PS-IGNORE
"name": "sample_doc.pdf",
"s3_key": "sample_doc.pdf",
"description": "my item",
Expand All @@ -456,6 +457,22 @@ def document_data(data_f680_case):
]


@pytest.fixture
def generated_document_data(data_f680_case):
return [
{
"id": str(uuid.uuid4()), # /PS-IGNORE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this ID and the above document_data.id will be different values, I assume that ok right?

if not maybe another helper function to generate the uuid to keep it consistent would work

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They should be different documents in this case as one is an exporter uploaded doc and the other is an outcome letter generated by the caseworker.

"name": "application_letter.pdf",
"s3_key": "application_letter.pdf",
"description": "my item",
"size": 18,
"safe": True,
"document_type": None,
"application": data_f680_case["id"],
},
]


@pytest.fixture
def document_data_json(document_data):
return {
Expand All @@ -465,6 +482,13 @@ def document_data_json(document_data):
}


@pytest.fixture
def generated_document_data_json(generated_document_data):
return {
"documents": generated_document_data,
}


@pytest.fixture
def mock_get_supporting_documents(requests_mock, data_queue, f680_case_id):
url = client._build_absolute_uri(f"/queues/{data_queue}/cases/{f680_case_id}/f680/supporting-documents/")
Expand All @@ -483,6 +507,18 @@ def mock_f680_supporting_documents_get(requests_mock, f680_case_id, document_dat
return requests_mock.get(url=url, json=document_data_json)


@pytest.fixture
def mock_f680_generated_documents_get(requests_mock, f680_case_id, generated_document_data_json):
url = client._build_absolute_uri(f"/cases/{f680_case_id}/documents/")
return requests_mock.get(url=url, json=generated_document_data_json)


@pytest.fixture
def mock_f680_generated_documents_get_fail(requests_mock, f680_case_id):
url = client._build_absolute_uri(f"/cases/{f680_case_id}/documents/")
return requests_mock.get(url=url, status_code=400, json={})


@pytest.fixture
def mock_f680_supporting_documents_get_failure(requests_mock, f680_case_id, document_data_json):
url = client._build_absolute_uri(f"/caseworker/applications/{f680_case_id}/supporting-document/")
Expand Down Expand Up @@ -522,7 +558,9 @@ def test_GET_documents_for_case_success(
mock_get_supporting_documents,
mock_f680_case_with_submitted_by,
mock_f680_supporting_documents_get,
mock_f680_generated_documents_get,
document_data,
generated_document_data,
):

url = reverse("cases:f680:supporting_documents", kwargs={"queue_pk": data_queue["id"], "pk": f680_case_id})
Expand All @@ -532,7 +570,7 @@ def test_GET_documents_for_case_success(
response = authorized_client.get(url)

assert response.status_code == 200
assert response.context["supporting_documents"] == document_data
assert response.context["supporting_documents"] == document_data + generated_document_data

content = BeautifulSoup(response.content, "html.parser")

Expand All @@ -543,22 +581,41 @@ def test_GET_documents_for_case_success(
)
assert content.find(id="document-description").text.strip() == "my item"

def test_GET_documents_for_case_failure(
def test_GET_uploaded_supporting_documents_for_case_fail(
self,
authorized_client,
data_queue,
f680_case_id,
mock_get_supporting_documents_failure,
mock_f680_case_with_submitted_by,
mock_f680_supporting_documents_get_failure,
mock_f680_generated_documents_get,
):

url = reverse("cases:f680:supporting_documents", kwargs={"queue_pk": data_queue["id"], "pk": f680_case_id})

with pytest.raises(ServiceError) as error:
authorized_client.get(url)

assert str(error.value) == "Error retreiving uploaded supporting documents"

def test_GET_uploaded_generated_documents_for_case_fail(
self,
authorized_client,
data_queue,
f680_case_id,
mock_get_supporting_documents,
mock_f680_case_with_submitted_by,
mock_f680_supporting_documents_get,
mock_f680_generated_documents_get_fail,
):

url = reverse("cases:f680:supporting_documents", kwargs={"queue_pk": data_queue["id"], "pk": f680_case_id})

with pytest.raises(ServiceError) as error:
authorized_client.get(url)

assert str(error.value) == "Error retreiving supporting documents"
assert str(error.value) == "Error retreiving generated documents"

def test_GET_stream_document_for_case_success(
self,
Expand Down
22 changes: 16 additions & 6 deletions caseworker/f680/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from caseworker.cases.forms.queries import CloseQueryForm
from caseworker.cases.helpers.case import CaseworkerMixin
from caseworker.cases.helpers.ecju_queries import get_ecju_queries
from caseworker.cases.services import get_case, post_ecju_query, get_application_documents
from caseworker.cases.services import get_case, post_ecju_query, get_application_documents, get_case_documents
from caseworker.f680.forms import NewECJUQueryForm
from caseworker.cases.views.queries import CloseQueryMixin
from caseworker.core.constants import ALL_CASES_QUEUE_ID
Expand Down Expand Up @@ -197,16 +197,26 @@ class SupportingDocumentsView(LoginRequiredMixin, F680CaseworkerMixin, TemplateV

@expect_status(
HTTPStatus.OK,
"Error retreiving supporting documents",
"Unexpected error retreiving supporting documents",
"Error retreiving uploaded supporting documents",
"Unexpected error retreiving uploaded supporting documents",
)
def get_supporting_documents(self):
def get_exporter_uploaded_supporting_documents(self):
return get_application_documents(self.request, self.case_id)

@expect_status(
HTTPStatus.OK,
"Error retreiving generated documents",
"Unexpected error retreiving generated documents",
)
def get_caseworker_generated_documents(self):
return get_case_documents(self.request, self.case_id)

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
documents, _ = self.get_supporting_documents()
context["supporting_documents"] = documents["results"]
uploaded_documents, _ = self.get_exporter_uploaded_supporting_documents()
generated_documents, _ = self.get_caseworker_generated_documents()
documents = uploaded_documents["results"] + generated_documents["documents"]
context["supporting_documents"] = documents
return context


Expand Down