Skip to content

Commit

Permalink
Validated parameters in set media
Browse files Browse the repository at this point in the history
  • Loading branch information
bakeable committed Jun 4, 2024
1 parent c14efb2 commit 054a3a7
Showing 2 changed files with 17 additions and 2 deletions.
6 changes: 4 additions & 2 deletions akeneo_connector/akeneo_product.py
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@

from akeneo_connector.akeneo_connector import AkeneoConnector
from akeneo_connector.akeneo_units import format_value
from akeneo_connector.decorators import validate_parameters

class Value(TypedDict):
locale: Optional[str]
@@ -366,12 +367,13 @@ def get_media(self, media_attribute: str, locale: str | None = None, scope: str
return self.connector.get_media_file(media_url)
return None

@validate_parameters
def set_media(
self,
attribute: str,
file_path: str,
locale: str | None = None,
scope: str | None = None
locale: str,
scope: str
):
"""
Sets a media file for the given attribute.
13 changes: 13 additions & 0 deletions akeneo_connector/decorators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from functools import wraps

def validate_parameters(func):
@wraps(func)
def wrapper(*args, **kwargs):
for arg in args:
if arg is None or (isinstance(arg, str) and not arg):
raise ValueError("None or empty string parameter found")
for key, value in kwargs.items():
if value is None or (isinstance(value, str) and not value):
raise ValueError("None or empty string parameter found")
return func(*args, **kwargs)
return wrapper

0 comments on commit 054a3a7

Please sign in to comment.