Skip to content

Commit

Permalink
Merge pull request #62 from saritasa-nest/feature/improve-coverage
Browse files Browse the repository at this point in the history
Prepare test for widgets and split tests for admin
  • Loading branch information
Eg0ra authored Nov 5, 2024
2 parents 14cbd12 + 7217961 commit 07e58d9
Show file tree
Hide file tree
Showing 14 changed files with 1,221 additions and 1,094 deletions.
9 changes: 5 additions & 4 deletions import_export_extensions/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from django.core.files import File
from django.core.files.storage import default_storage
from django.db.models import Model, Q, QuerySet
from django.db.models.fields.files import FieldFile
from django.forms import ValidationError
from django.utils.encoding import smart_str

Expand Down Expand Up @@ -294,7 +295,7 @@ def __init__(self, filename: str):

def render(
self,
value: Model | None,
value: FieldFile | None,
obj=None,
**kwargs,
) -> str | None:
Expand All @@ -320,12 +321,12 @@ def clean(
internal_url = utils.url_to_internal_value(urlparse(value).path)

if not internal_url:
raise ValidationError("Invalid image path")
raise ValidationError("Invalid file path")

try:
if default_storage.exists(internal_url):
return internal_url
except SuspiciousFileOperation:
except SuspiciousFileOperation: # pragma: no cover
pass

return self._get_file(value)
Expand All @@ -350,4 +351,4 @@ def _get_default_storage(self) -> str:
"""
if hasattr(settings, "STORAGES"):
return settings.STORAGES["default"]["BACKEND"]
return settings.DEFAULT_FILE_STORAGE
return settings.DEFAULT_FILE_STORAGE # pragma: no cover
Loading

0 comments on commit 07e58d9

Please sign in to comment.