Skip to content

Commit 9e292f1

Browse files
committed
fixes
1 parent 55ec043 commit 9e292f1

5 files changed

Lines changed: 18 additions & 24 deletions

File tree

tests/providers/test_ridewithgps.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def test_update_activity_multiple_fields():
105105

106106

107107
def test_update_activity_api_failure():
108-
"""Test handling of API failure during update."""
108+
"""Test that API failure during update raises the exception."""
109109
provider = RideWithGPSProvider()
110110

111111
# Mock API failure
@@ -114,18 +114,16 @@ def test_update_activity_api_failure():
114114
# Test data
115115
activity_data = {"ridewithgps_id": "12345", "name": "Updated Name"}
116116

117-
# Call update_activity and expect it to handle the exception
118-
result = provider.update_activity(activity_data)
119-
120-
# Verify the result is False due to the exception
121-
assert result is False
117+
# update_activity should raise so callers get the real error message
118+
with pytest.raises(Exception, match="API Error"):
119+
provider.update_activity(activity_data)
122120

123121
# Verify the API was called
124122
provider.client.patch.assert_called_once()
125123

126124

127125
def test_update_activity_api_error_response():
128-
"""Test handling of API error response during update."""
126+
"""Test that an API error response during update raises a RuntimeError."""
129127
provider = RideWithGPSProvider()
130128

131129
# Mock API response with error
@@ -135,11 +133,9 @@ def test_update_activity_api_error_response():
135133
# Test data
136134
activity_data = {"ridewithgps_id": "12345", "name": "Updated Name"}
137135

138-
# Call update_activity
139-
result = provider.update_activity(activity_data)
140-
141-
# Verify the result is False due to the error response
142-
assert result is False
136+
# update_activity should raise so callers get the real error message
137+
with pytest.raises(RuntimeError, match="Some API error"):
138+
provider.update_activity(activity_data)
143139

144140

145141
def test_update_activity_removes_provider_id():

tests/providers/test_strava.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def test_update_activity_multiple_fields(self):
7575
)
7676

7777
def test_update_activity_api_failure(self):
78-
"""Test handling of API failure during update."""
78+
"""Test that API failure during update raises the exception."""
7979
# Mock the stravalib client to raise an exception
8080
mock_client = Mock()
8181
mock_client.update_activity = Mock(side_effect=Exception("API Error"))
@@ -87,11 +87,9 @@ def test_update_activity_api_failure(self):
8787
# Test data
8888
activity_data = {"strava_id": "12345", "name": "Updated Name"}
8989

90-
# Call update_activity and expect it to handle the exception
91-
result = provider.update_activity(activity_data)
92-
93-
# Verify the result is False due to the exception
94-
assert result is False
90+
# update_activity should raise so callers get the real error message
91+
with pytest.raises(Exception, match="API Error"):
92+
provider.update_activity(activity_data)
9593

9694
# Verify the API was called
9795
mock_client.update_activity.assert_called_once()

tracekit/providers/ridewithgps/ridewithgps_provider.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,13 @@ def update_activity(self, activity_data: dict) -> bool:
143143

144144
# Check if there's an error in the response
145145
if hasattr(response, "error"):
146-
print(f"API returned error: {response.error}")
147-
return False
146+
raise RuntimeError(f"RideWithGPS API error: {response.error}")
148147

149148
return True
150149

151150
except Exception as e:
152151
print(f"Error updating RideWithGPS trip {provider_id}: {e}")
153-
return False
152+
raise
154153

155154
def get_all_gear(self) -> dict[str, str]:
156155
"""Get gear from RideWithGPS user info."""

tracekit/providers/strava/strava_provider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ def update_activity(self, activity_data: dict[str, Any]) -> bool:
283283

284284
except Exception as e:
285285
print(f"Error updating Strava activity {provider_id}: {e}")
286-
return False
286+
raise
287287

288288
def get_all_gear(self) -> dict[str, str]:
289289
"""Get all gear from Strava athlete profile."""

tracekit/worker.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,14 @@ def apply_sync_change(self, change_dict: dict, year_month: str):
195195
create_notification(f"Sync change failed: {msg}", category="error")
196196
except Exception:
197197
pass
198-
raise RuntimeError(msg)
198+
return {"success": False, "message": msg}
199199

200200
except Exception as exc:
201+
msg = str(exc)
201202
try:
202203
from tracekit.notification import create_notification
203204

204-
create_notification(f"Sync change error for {year_month}: {exc}", category="error")
205+
create_notification(f"Sync change error for {year_month}: {msg}", category="error")
205206
except Exception:
206207
pass
207208
raise

0 commit comments

Comments
 (0)