Skip to content

Commit

Permalink
#239 FileAlreadyUploaded -> DuplicateFileError
Browse files Browse the repository at this point in the history
  • Loading branch information
evgkirov committed Jun 23, 2023
1 parent c955db7 commit e8fdd98
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions pyuploadcare/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
)
from pyuploadcare.exceptions import (
APIError,
FileAlreadyUploaded,
DuplicateFileError,
InvalidRequestError,
WebhookIsNotUnique,
)
Expand Down Expand Up @@ -393,7 +393,7 @@ def upload_from_url(
if "token" not in response:
if check_duplicates and response["type"] == "file_info":
file_id = response["file_id"]
raise FileAlreadyUploaded(
raise DuplicateFileError(
f"The file is a duplicate of a previously uploaded file ({file_id})",
file_id=file_id,
)
Expand Down
6 changes: 3 additions & 3 deletions pyuploadcare/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from pyuploadcare.api.auth import UploadcareAuth
from pyuploadcare.api.client import Client
from pyuploadcare.api.entities import ProjectInfo, Webhook
from pyuploadcare.exceptions import FileAlreadyUploaded, InvalidParamError
from pyuploadcare.exceptions import DuplicateFileError, InvalidParamError
from pyuploadcare.helpers import (
extracts_uuids,
get_file_size,
Expand Down Expand Up @@ -474,7 +474,7 @@ def upload_from_url(
or source URL. Defaults to None.
- check_duplicates (Optional[bool]): Enables duplicate uploads
prevention. If a file with the same source URL has been
previously uploaded this method will raise FileAlreadyUploaded.
previously uploaded this method will raise DuplicateFileError.
- save_duplicates (Optional[bool]): Indicates if the URL should be
stored by Uploadcare future check_duplicates usages.
Expand Down Expand Up @@ -565,7 +565,7 @@ def upload_from_url_sync(
until_ready=until_ready,
callback=callback,
)
except FileAlreadyUploaded as e:
except DuplicateFileError as e:
return self.file(e.file_id)

def _extract_uuids(
Expand Down
2 changes: 1 addition & 1 deletion pyuploadcare/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class UploadError(UploadcareException):
"""


class FileAlreadyUploaded(UploadError):
class DuplicateFileError(UploadError):
"""Raised within UploadAPI.upload_from_url if check_duplicates is True and file was already been uploaded before)"""

file_id: str
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/test_api_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from pyuploadcare import File, FileGroup, conf
from pyuploadcare.exceptions import (
FileAlreadyUploaded,
DuplicateFileError,
InvalidParamError,
InvalidRequestError,
)
Expand Down Expand Up @@ -139,9 +139,9 @@ def test_successful_upload_from_url_check_duplicates(uploadcare):
url, check_duplicates=True, store=False, interval=1
)
assert isinstance(first_file, File)
with pytest.raises(FileAlreadyUploaded) as e:
with pytest.raises(DuplicateFileError) as e:
uploadcare.upload_from_url(url, check_duplicates=True, store=False)
assert isinstance(e, FileAlreadyUploaded)
assert isinstance(e, DuplicateFileError)
assert first_file.uuid == e.file_id


Expand Down

0 comments on commit e8fdd98

Please sign in to comment.