Skip to content

Commit ee6dbdf

Browse files
committed
Fix bugs in activity.py return types and test collection warning
- Change Dict[Never, Never] return types to None for create_favorite_activity and delete_activity_log - Fix pytest collection warning by refactoring TestResource to be created by a factory function
1 parent 1d51869 commit ee6dbdf

File tree

2 files changed

+29
-24
lines changed

2 files changed

+29
-24
lines changed

fitbit_client/resources/activity.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def get_activity_log_list(
281281

282282
def create_favorite_activity(
283283
self, activity_id: int, user_id: str = "-", debug: bool = False
284-
) -> Dict[Never, Never]:
284+
) -> None:
285285
"""Adds an activity to the user's list of favorite activities.
286286
287287
Favorite activities appear in a special section of the Fitbit app and website,
@@ -295,7 +295,7 @@ def create_favorite_activity(
295295
debug: If True, prints a curl command to stdout to help with debugging (default: False)
296296
297297
Returns:
298-
Dict[Never, Never]: Empty dictionary on success, with HTTP 201 status code
298+
None: Returns None on success, with HTTP 201 status code
299299
300300
Raises:
301301
fitbit_client.exceptions.InvalidRequestException: If activity_id is invalid
@@ -314,11 +314,11 @@ def create_favorite_activity(
314314
http_method="POST",
315315
debug=debug,
316316
)
317-
return cast(Dict[Never, Never], result)
317+
return cast(None, result)
318318

319319
def delete_activity_log(
320320
self, activity_log_id: int, user_id: str = "-", debug: bool = False
321-
) -> Dict[Never, Never]:
321+
) -> None:
322322
"""Deletes a specific activity log entry from the user's activity history.
323323
324324
This endpoint permanently removes an activity from the user's activity history.
@@ -333,7 +333,7 @@ def delete_activity_log(
333333
debug: If True, prints a curl command to stdout to help with debugging (default: False)
334334
335335
Returns:
336-
Dict[Never, Never]: Empty dictionary on success, with HTTP 204 status code
336+
None: Returns None on success, with HTTP 204 status code
337337
338338
Raises:
339339
fitbit_client.exceptions.InvalidRequestException: If activity_log_id is invalid
@@ -351,7 +351,7 @@ def delete_activity_log(
351351
result = self._make_request(
352352
f"activities/{activity_log_id}.json", user_id=user_id, http_method="DELETE", debug=debug
353353
)
354-
return cast(Dict[Never, Never], result)
354+
return cast(None, result)
355355

356356
def delete_favorite_activity(
357357
self, activity_id: int, user_id: str = "-", debug: bool = False

tests/utils/test_curl_debug_mixin.py

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,31 @@
1414

1515

1616
# Create a test class that uses the mixin for debug testing
17-
class TestResource(CurlDebugMixin):
18-
"""Test class that uses CurlDebugMixin"""
17+
# Using a function to create the test class to avoid pytest collection warning
18+
def create_test_resource_class():
19+
class TestResource(CurlDebugMixin):
20+
"""Test class that uses CurlDebugMixin"""
1921

20-
def __init__(self):
21-
self.oauth = Mock()
22-
self.oauth.token = {"access_token": "test_token"}
22+
def __init__(self):
23+
self.oauth = Mock()
24+
self.oauth.token = {"access_token": "test_token"}
2325

24-
def make_debug_request(self, debug=False):
25-
"""Test method that simulates _make_request with debug mode"""
26-
url = "https://api.fitbit.com/1/user/-/test/endpoint"
26+
def make_debug_request(self, debug=False):
27+
"""Test method that simulates _make_request with debug mode"""
28+
url = "https://api.fitbit.com/1/user/-/test/endpoint"
2729

28-
if debug:
29-
curl_command = self._build_curl_command(
30-
url=url, http_method="GET", params={"param1": "value1"}
31-
)
32-
print(f"\n# Debug curl command:")
33-
print(curl_command)
34-
print()
35-
return None
30+
if debug:
31+
curl_command = self._build_curl_command(
32+
url=url, http_method="GET", params={"param1": "value1"}
33+
)
34+
print(f"\n# Debug curl command:")
35+
print(curl_command)
36+
print()
37+
return None
3638

37-
return {"success": True}
39+
return {"success": True}
40+
41+
return TestResource
3842

3943

4044
@fixture
@@ -101,7 +105,8 @@ def test_build_curl_command_with_delete(curl_debug_mixin):
101105

102106
def test_debug_mode_integration(capsys):
103107
"""Test debug mode integration with a resource class"""
104-
# Create test resource
108+
# Create test resource class and instance
109+
TestResource = create_test_resource_class()
105110
resource = TestResource()
106111

107112
# Call make_debug_request with debug=True

0 commit comments

Comments
 (0)