diff --git a/src/documents/tests/test_api_status.py b/src/documents/tests/test_api_status.py index 96e639c35..5e1c5a0bd 100644 --- a/src/documents/tests/test_api_status.py +++ b/src/documents/tests/test_api_status.py @@ -243,21 +243,29 @@ class TestSystemStatus(APITestCase): THEN: - The response contains an ERROR classifier status """ - does_exist = tempfile.NamedTemporaryFile( - dir="/tmp", - delete=False, - ) - with override_settings(MODEL_FILE=does_exist): + with ( + tempfile.NamedTemporaryFile( + dir="/tmp", + delete=False, + ) as does_exist, + override_settings(MODEL_FILE=does_exist), + ): with mock.patch("documents.classifier.load_classifier") as mock_load: mock_load.side_effect = ClassifierModelCorruptError() Document.objects.create( 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) response = self.client.get(self.ENDPOINT) 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"]) def test_system_status_classifier_ok_no_objects(self): diff --git a/src/documents/views.py b/src/documents/views.py index 10b2d0cbd..2d0c030f4 100644 --- a/src/documents/views.py +++ b/src/documents/views.py @@ -1499,7 +1499,7 @@ class BulkDownloadView(GenericAPIView): follow_filename_format = serializer.validated_data.get("follow_formatting") settings.SCRATCH_DIR.mkdir(parents=True, exist_ok=True) - temp = tempfile.NamedTemporaryFile( + temp = tempfile.NamedTemporaryFile( # noqa: SIM115 dir=settings.SCRATCH_DIR, suffix="-compressed-archive", delete=False, @@ -1517,6 +1517,7 @@ class BulkDownloadView(GenericAPIView): for document in Document.objects.filter(pk__in=ids): strategy.add_document(document) + # TODO(stumpylog): Investigate using FileResponse here with open(temp.name, "rb") as f: response = HttpResponse(f, content_type="application/zip") response["Content-Disposition"] = '{}; filename="{}"'.format(