|
6 | 6 | from io import BytesIO
|
7 | 7 | from zipfile import ZipFile
|
8 | 8 |
|
| 9 | +from django.conf import global_settings |
9 | 10 | from django.conf import settings
|
10 | 11 | from django.core import files
|
11 | 12 | from django.core.files import File as DjangoFile
|
12 | 13 | from django.core.files.base import ContentFile
|
13 | 14 | from django.core.files.storage import default_storage
|
14 | 15 | from django.core.files.temp import NamedTemporaryFile
|
15 | 16 | from django.core.management import call_command
|
| 17 | +from django.core.management.base import SystemCheckError |
16 | 18 | from django.db import models
|
17 | 19 | from django.test import TestCase, override_settings
|
18 | 20 |
|
@@ -420,3 +422,19 @@ def test_serve_file_from_database(self):
|
420 | 422 | self.assertEqual(content, b"1234567890")
|
421 | 423 | self.assertEqual(response["content-type"], "text/plain")
|
422 | 424 | self.assertEqual(response["content-length"], "10")
|
| 425 | + |
| 426 | + @override_settings( |
| 427 | + MEDIA_ROOT=global_settings.MEDIA_ROOT, |
| 428 | + DATABASE_FILES_URL_METHOD_NAME = "URL_METHOD_1", # default |
| 429 | + DB_FILES_AUTO_EXPORT_DB_TO_FS = True, # default |
| 430 | + ) |
| 431 | + def test_refuse_unset_media_root(self): |
| 432 | + # regression test for issue #65 where unset MEDIA_ROOT would result in serving the source code |
| 433 | + |
| 434 | + message_a = "(binary_database_files.E001) MEDIA_ROOT is not defined, yet you are using URL_METHOD_1 which serves media files from the filesystem" |
| 435 | + with self.assertRaisesMessage(SystemCheckError, message_a): |
| 436 | + call_command("check") |
| 437 | + |
| 438 | + message_b = "(binary_database_files.E002) MEDIA_ROOT is not defined, yet you are using DB_FILES_AUTO_EXPORT_DB_TO_FS which copies media files from the filesystem." |
| 439 | + with self.assertRaisesMessage(SystemCheckError, message_b): |
| 440 | + call_command("check") |
0 commit comments