minor linting

This commit is contained in:
Trenton H 2024-11-01 17:23:24 -07:00 committed by Trenton Holmes
parent 0428d1f88d
commit 24d394ffcc
2 changed files with 17 additions and 8 deletions

View File

@ -243,21 +243,29 @@ class TestSystemStatus(APITestCase):
THEN: THEN:
- The response contains an ERROR classifier status - The response contains an ERROR classifier status
""" """
does_exist = tempfile.NamedTemporaryFile( with (
tempfile.NamedTemporaryFile(
dir="/tmp", dir="/tmp",
delete=False, delete=False,
) ) as does_exist,
with override_settings(MODEL_FILE=does_exist): override_settings(MODEL_FILE=does_exist),
):
with mock.patch("documents.classifier.load_classifier") as mock_load: with mock.patch("documents.classifier.load_classifier") as mock_load:
mock_load.side_effect = ClassifierModelCorruptError() mock_load.side_effect = ClassifierModelCorruptError()
Document.objects.create( Document.objects.create(
title="Test Document", title="Test Document",
) )
Tag.objects.create(name="Test Tag", matching_algorithm=Tag.MATCH_AUTO) Tag.objects.create(
name="Test Tag",
matching_algorithm=Tag.MATCH_AUTO,
)
self.client.force_login(self.user) self.client.force_login(self.user)
response = self.client.get(self.ENDPOINT) response = self.client.get(self.ENDPOINT)
self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data["tasks"]["classifier_status"], "ERROR") self.assertEqual(
response.data["tasks"]["classifier_status"],
"ERROR",
)
self.assertIsNotNone(response.data["tasks"]["classifier_error"]) self.assertIsNotNone(response.data["tasks"]["classifier_error"])
def test_system_status_classifier_ok_no_objects(self): def test_system_status_classifier_ok_no_objects(self):

View File

@ -1499,7 +1499,7 @@ class BulkDownloadView(GenericAPIView):
follow_filename_format = serializer.validated_data.get("follow_formatting") follow_filename_format = serializer.validated_data.get("follow_formatting")
settings.SCRATCH_DIR.mkdir(parents=True, exist_ok=True) settings.SCRATCH_DIR.mkdir(parents=True, exist_ok=True)
temp = tempfile.NamedTemporaryFile( temp = tempfile.NamedTemporaryFile( # noqa: SIM115
dir=settings.SCRATCH_DIR, dir=settings.SCRATCH_DIR,
suffix="-compressed-archive", suffix="-compressed-archive",
delete=False, delete=False,
@ -1517,6 +1517,7 @@ class BulkDownloadView(GenericAPIView):
for document in Document.objects.filter(pk__in=ids): for document in Document.objects.filter(pk__in=ids):
strategy.add_document(document) strategy.add_document(document)
# TODO(stumpylog): Investigate using FileResponse here
with open(temp.name, "rb") as f: with open(temp.name, "rb") as f:
response = HttpResponse(f, content_type="application/zip") response = HttpResponse(f, content_type="application/zip")
response["Content-Disposition"] = '{}; filename="{}"'.format( response["Content-Disposition"] = '{}; filename="{}"'.format(