mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-12-03 17:58:41 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a563bd15a7 |
No files matched your search
@@ -1,8 +1,10 @@
|
|||||||
import json
|
import json
|
||||||
|
import os
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
from django.core.files.uploadedfile import SimpleUploadedFile
|
from django.core.files.uploadedfile import SimpleUploadedFile
|
||||||
from django.test import override_settings
|
from django.test import override_settings
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
@@ -507,6 +509,39 @@ class TestApiAppConfig(DirectoriesMixin, APITestCase):
|
|||||||
|
|
||||||
self.assertEqual(stored_text, {})
|
self.assertEqual(stored_text, {})
|
||||||
|
|
||||||
|
def test_api_accepts_a_logo_too_large_to_hold_in_memory(self) -> None:
|
||||||
|
"""
|
||||||
|
GIVEN:
|
||||||
|
- A PNG logo larger than Django's in memory upload limit, which is
|
||||||
|
stored in a temporary file while it is received
|
||||||
|
WHEN:
|
||||||
|
- Uploaded via PATCH to app config
|
||||||
|
THEN:
|
||||||
|
- The upload is accepted and the stored logo is a valid image
|
||||||
|
"""
|
||||||
|
# Random pixels do not compress, so this is a few megabytes as a PNG
|
||||||
|
image = Image.frombytes("RGB", (1100, 1100), os.urandom(1100 * 1100 * 3))
|
||||||
|
logo = BytesIO()
|
||||||
|
image.save(logo, format="PNG")
|
||||||
|
assert logo.getbuffer().nbytes > settings.FILE_UPLOAD_MAX_MEMORY_SIZE
|
||||||
|
|
||||||
|
response = self.client.patch(
|
||||||
|
f"{self.ENDPOINT}1/",
|
||||||
|
{
|
||||||
|
"app_logo": SimpleUploadedFile(
|
||||||
|
name="large-logo.png",
|
||||||
|
content=logo.getvalue(),
|
||||||
|
content_type="image/png",
|
||||||
|
),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
config = ApplicationConfiguration.objects.first()
|
||||||
|
assert config is not None
|
||||||
|
with Image.open(config.app_logo.path) as stored_logo:
|
||||||
|
self.assertEqual(stored_logo.size, (1100, 1100))
|
||||||
|
|
||||||
def test_api_accepts_valid_gif_logo(self) -> None:
|
def test_api_accepts_valid_gif_logo(self) -> None:
|
||||||
"""
|
"""
|
||||||
GIVEN:
|
GIVEN:
|
||||||
|
|||||||
@@ -303,7 +303,9 @@ class ApplicationConfigurationSerializer(
|
|||||||
|
|
||||||
return InMemoryUploadedFile(
|
return InMemoryUploadedFile(
|
||||||
file=data,
|
file=data,
|
||||||
field_name=file.field_name,
|
# An upload past the in memory limit is a temporary file, which has no
|
||||||
|
# field name of its own
|
||||||
|
field_name="app_logo",
|
||||||
name=file.name,
|
name=file.name,
|
||||||
content_type=file.content_type,
|
content_type=file.content_type,
|
||||||
size=data.getbuffer().nbytes,
|
size=data.getbuffer().nbytes,
|
||||||
|
|||||||
Reference in new issue
Block a user