Skip to content

Commit c89ef8e

Browse files
committed
Updated arguments helper
1 parent 1dbf3d8 commit c89ef8e

2 files changed

Lines changed: 24 additions & 27 deletions

File tree

amazon_paapi/helpers/arguments.py

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from typing import List, Union
55

6-
from ..errors import AsinNotFound, InvalidArgument
6+
from ..errors import InvalidArgument
77
from ..tools import get_asin
88

99

@@ -20,27 +20,24 @@ def get_items_ids(items: Union[str, List[str]]) -> List[str]:
2020
else:
2121
items_ids = [get_asin(x.strip()) for x in items]
2222

23-
if items_ids:
24-
return items_ids
25-
26-
raise AsinNotFound("No ASIN codes have been found.")
23+
return items_ids
2724

2825

2926
def check_search_args(**kwargs):
30-
_check_search_mandatory_args(**kwargs)
31-
_check_search_pagination_args(**kwargs)
27+
check_search_mandatory_args(**kwargs)
28+
check_search_pagination_args(**kwargs)
3229

3330

34-
def _check_search_mandatory_args(**kwargs):
31+
def check_search_mandatory_args(**kwargs):
3532
mandatory_args = [
36-
kwargs["keywords"],
37-
kwargs["actor"],
38-
kwargs["artist"],
39-
kwargs["author"],
40-
kwargs["brand"],
41-
kwargs["title"],
42-
kwargs["browse_node_id"],
43-
kwargs["search_index"],
33+
kwargs.get("keywords"),
34+
kwargs.get("actor"),
35+
kwargs.get("artist"),
36+
kwargs.get("author"),
37+
kwargs.get("brand"),
38+
kwargs.get("title"),
39+
kwargs.get("browse_node_id"),
40+
kwargs.get("search_index"),
4441
]
4542
if all(arg is None for arg in mandatory_args):
4643
error_message = (
@@ -50,9 +47,9 @@ def _check_search_mandatory_args(**kwargs):
5047
raise InvalidArgument(error_message)
5148

5249

53-
def _check_search_pagination_args(**kwargs):
50+
def check_search_pagination_args(**kwargs):
5451
error_message = "Args item_count and item_page should be integers between 1 and 10."
55-
pagination_args = [kwargs["item_count"], kwargs["item_page"]]
52+
pagination_args = [kwargs.get("item_count"), kwargs.get("item_page")]
5653
pagination_args = [arg for arg in pagination_args if arg]
5754

5855
if not all(isinstance(arg, int) for arg in pagination_args):
@@ -66,7 +63,7 @@ def check_variations_args(**kwargs):
6663
error_message = (
6764
"Args variation_count and variation_page should be integers between 1 and 10."
6865
)
69-
variation_args = [kwargs["variation_count"], kwargs["variation_page"]]
66+
variation_args = [kwargs.get("variation_count"), kwargs.get("variation_page")]
7067
variation_args = [arg for arg in variation_args if arg]
7168

7269
if not all(isinstance(arg, int) for arg in variation_args):
@@ -77,6 +74,6 @@ def check_variations_args(**kwargs):
7774

7875

7976
def check_browse_nodes_args(**kwargs):
80-
if not isinstance(kwargs["browse_node_ids"], List):
77+
if not isinstance(kwargs.get("browse_node_ids"), List):
8178
error_message = "Argument browse_node_ids should be a List of strings."
8279
raise InvalidArgument(error_message)

tests/test_helpers_arguments.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
from amazon_paapi.errors import AsinNotFound, InvalidArgument
44
from amazon_paapi.helpers.arguments import (
5-
_check_search_mandatory_args,
6-
_check_search_pagination_args,
75
check_browse_nodes_args,
6+
check_search_mandatory_args,
7+
check_search_pagination_args,
88
check_variations_args,
99
get_items_ids,
1010
)
@@ -56,22 +56,22 @@ def test_get_items_ids_invalid_argument(self):
5656
get_items_ids(34)
5757

5858
def test_check_search_mandatory_args_correct(self):
59-
_check_search_mandatory_args(actor="John Doe")
59+
check_search_mandatory_args(actor="John Doe")
6060

6161
def test_check_search_mandatory_args_raises_exception(self):
6262
with self.assertRaises(InvalidArgument):
63-
_check_search_mandatory_args()
63+
check_search_mandatory_args()
6464

6565
def test_check_search_pagination_args_correct(self):
66-
_check_search_pagination_args(item_count=1, item_page=10)
66+
check_search_pagination_args(item_count=1, item_page=10)
6767

6868
def test_check_search_pagination_args_if_not_integers(self):
6969
with self.assertRaises(InvalidArgument):
70-
_check_search_pagination_args(item_count=True, item_page="test")
70+
check_search_pagination_args(item_count=True, item_page="test")
7171

7272
def test_check_search_pagination_args_if_not_between_1_10(self):
7373
with self.assertRaises(InvalidArgument):
74-
_check_search_pagination_args(item_count=0, item_page=11)
74+
check_search_pagination_args(item_count=0, item_page=11)
7575

7676
def test_check_check_variations_args_correct(self):
7777
check_variations_args(variation_count=1, variation_page=10)

0 commit comments

Comments
 (0)