Merge pull request #668 from spapas/fix-base-dir-path

Make sure BASE_DIR is a Path - fixesd #687
This commit is contained in:
Emil Stenström 2024-09-12 09:56:27 +02:00 committed by GitHub
commit fa556d281c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 1 deletions

View file

@ -1,5 +1,6 @@
import re
from enum import Enum
from pathlib import Path
from typing import TYPE_CHECKING, Dict, List, Tuple, Union
from django.conf import settings
@ -101,7 +102,8 @@ class AppSettings:
@property
def DIRS(self) -> List[Union[str, Tuple[str, str]]]:
return self.settings.get("dirs", [settings.BASE_DIR / "components"])
base_dir_path = Path(settings.BASE_DIR)
return self.settings.get("dirs", [base_dir_path / "components"])
@property
def APP_DIRS(self) -> List[str]:

View file

@ -1,3 +1,5 @@
from pathlib import Path
from django.test import override_settings
from django_components.app_settings import app_settings
@ -17,3 +19,11 @@ class SettingsTestCase(BaseTestCase):
def test_raises_on_invalid_context_behavior(self):
with self.assertRaises(ValueError):
app_settings.CONTEXT_BEHAVIOR
@override_settings(BASE_DIR="base_dir")
def test_works_when_base_dir_is_string(self):
self.assertEqual(app_settings.DIRS, [Path("base_dir/components")])
@override_settings(BASE_DIR=Path("base_dir"))
def test_works_when_base_dir_is_path(self):
self.assertEqual(app_settings.DIRS, [Path("base_dir/components")])