Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def __init__(self):
# API call settings
self.default_limit = 100
self.start = 0
self.start_badge = 1 # Badge related calls start counting at 1
self.start_badge = 1 # Badge, challenge and goal calls start counting at 1

# Activity settings
self.activityfile = "test_data/*.gpx" # Supported file types: .fit .gpx .tcx
Expand Down Expand Up @@ -4942,26 +4942,26 @@ def execute_api_call(api: Garmin, key: str) -> None:
"get_active_goals": lambda: call_and_display(
api.get_goals,
status="active",
start=config.start,
start=config.start_badge,
limit=config.default_limit,
method_name="get_goals",
api_call_desc=f"api.get_goals(status='active', start={config.start}, limit={config.default_limit})",
api_call_desc=f"api.get_goals(status='active', start={config.start_badge},limit={config.default_limit})",
),
"get_future_goals": lambda: call_and_display(
api.get_goals,
status="future",
start=config.start,
start=config.start_badge,
limit=config.default_limit,
method_name="get_goals",
api_call_desc=f"api.get_goals(status='future', start={config.start}, limit={config.default_limit})",
api_call_desc=f"api.get_goals(status='future', start={config.start_badge},limit={config.default_limit})",
),
"get_past_goals": lambda: call_and_display(
api.get_goals,
status="past",
start=config.start,
start=config.start_badge,
limit=config.default_limit,
method_name="get_goals",
api_call_desc=f"api.get_goals(status='past', start={config.start}, limit={config.default_limit})",
api_call_desc=f"api.get_goals(status='past', start={config.start_badge},limit={config.default_limit})",
),
"get_badge_challenges": lambda: call_and_display(
api.get_badge_challenges,
Expand Down
6 changes: 3 additions & 3 deletions garminconnect/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2036,7 +2036,7 @@ def get_adhoc_challenges(self, start: int, limit: int) -> dict[str, Any]:

def get_badge_challenges(self, start: int, limit: int) -> dict[str, Any]:
"""Return badge challenges for the current user."""
start = _validate_non_negative_integer(start, "start")
start = _validate_positive_integer(start, "start")
limit = _validate_positive_integer(limit, "limit")
url = self.garmin_connect_badge_challenges_url
params = {"start": str(start), "limit": str(limit)}
Expand All @@ -2046,7 +2046,7 @@ def get_badge_challenges(self, start: int, limit: int) -> dict[str, Any]:

def get_available_badge_challenges(self, start: int, limit: int) -> dict[str, Any]:
"""Return available badge challenges."""
start = _validate_non_negative_integer(start, "start")
start = _validate_positive_integer(start, "start")
limit = _validate_positive_integer(limit, "limit")
url = self.garmin_connect_available_badge_challenges_url
params = {"start": str(start), "limit": str(limit)}
Expand All @@ -2058,7 +2058,7 @@ def get_non_completed_badge_challenges(
self, start: int, limit: int
) -> dict[str, Any]:
"""Return badge non-completed challenges for current user."""
start = _validate_non_negative_integer(start, "start")
start = _validate_positive_integer(start, "start")
limit = _validate_positive_integer(limit, "limit")
url = self.garmin_connect_non_completed_badge_challenges_url
params = {"start": str(start), "limit": str(limit)}
Expand Down
15 changes: 15 additions & 0 deletions tests/test_garmin_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1902,6 +1902,21 @@ def test_get_goals_rejects_zero_start(self, garmin: garminconnect.Garmin):
with pytest.raises(ValueError, match="positive integer"):
garmin.get_goals(start=0)

@pytest.mark.parametrize(
"method",
[
"get_badge_challenges",
"get_available_badge_challenges",
"get_non_completed_badge_challenges",
"get_inprogress_virtual_challenges",
],
)
def test_badge_challenges_reject_zero_start(
self, garmin: garminconnect.Garmin, method: str
):
with pytest.raises(ValueError, match="positive integer"):
getattr(garmin, method)(0, 10)

def test_get_goals_sends_sec_fetch_site_header(self, garmin: garminconnect.Garmin):
"""goal-service silently returns [] without this header (#431)."""
with patch.object(garmin, "connectapi", return_value=[]) as mock:
Expand Down
Loading