Skip to content

Commit

Permalink
Merge pull request #33 from abelsm2/fix_default_values
Browse files Browse the repository at this point in the history
corrected check on default values of None
  • Loading branch information
jasondilworth56 authored Aug 24, 2024
2 parents 3a4ba52 + 5e485fd commit a7333d9
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/iracingdataapi/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ def result_season_results(
payload = {"season_id": season_id}
if event_type:
payload["event_type"] = event_type
if race_week_num:
if race_week_num is not None:
payload["race_week_num"] = race_week_num

return self._get_resource("/data/results/season_results", payload=payload)
Expand Down Expand Up @@ -1067,11 +1067,11 @@ def stats_season_driver_standings(
"""
payload = {"season_id": season_id, "car_class_id": car_class_id}
if race_week_num:
if race_week_num is not None:
payload["race_week_num"] = race_week_num
if club_id:
payload["club_id"] = club_id
if division:
if division is not None:
payload["division"] = division

resource = self._get_resource(
Expand Down Expand Up @@ -1102,11 +1102,11 @@ def stats_season_supersession_standings(
"""
payload = {"season_id": season_id, "car_class_id": car_class_id}
if race_week_num:
if race_week_num is not None:
payload["race_week_num"] = race_week_num
if club_id:
payload["club_id"] = club_id
if division:
if division is not None:
payload["division"] = division

resource = self._get_resource(
Expand All @@ -1122,14 +1122,14 @@ def stats_season_team_standings(
Args:
season_id (int): The iRacing season id.
car_class_id (int): the iRacing car class id.
race_week_num (int): the race week number (0-12). Default 0.
race_week_num (int): the race week number (0-12).
Returns:
dict: a dict containing the season team standings
"""
payload = {"season_id": season_id, "car_class_id": car_class_id}
if race_week_num:
if race_week_num is not None:
payload["race_week_num"] = race_week_num

resource = self._get_resource(
Expand All @@ -1150,7 +1150,7 @@ def stats_season_tt_standings(
Args:
season_id (int): The iRacing season id.
car_class_id (int): the iRacing car class id.
race_week_num (int): the race week number (0-12). Default 0.
race_week_num (int): the race week number (0-12).
club_id (int): the iRacing club id.
division (int): the iRacing division.
Expand All @@ -1159,11 +1159,11 @@ def stats_season_tt_standings(
"""
payload = {"season_id": season_id, "car_class_id": car_class_id}
if race_week_num:
if race_week_num is not None:
payload["race_week_num"] = race_week_num
if club_id:
payload["club_id"] = club_id
if division:
if division is not None:
payload["division"] = division

resource = self._get_resource(
Expand All @@ -1184,7 +1184,7 @@ def stats_season_tt_results(
Args:
season_id (int): The iRacing season id.
car_class_id (int): the iRacing car class id.
race_week_num (int): the race week number (0-12). Default 0.
race_week_num (int): the race week number (0-12).
club_id (int): the iRacing club id.
division (int): the iRacing division.
Expand All @@ -1199,7 +1199,7 @@ def stats_season_tt_results(
}
if club_id:
payload["club_id"] = club_id
if division:
if division is not None:
payload["division"] = division

resource = self._get_resource("/data/stats/season_tt_results", payload=payload)
Expand All @@ -1218,7 +1218,7 @@ def stats_season_qualify_results(
Args:
season_id (int): The iRacing season id.
car_class_id (int): the iRacing car class id.
race_week_num (int): the race week number (0-12). Default 0.
race_week_num (int): the race week number (0-12).
club_id (int): the iRacing club id.
division (int): the iRacing division.
Expand All @@ -1233,7 +1233,7 @@ def stats_season_qualify_results(
}
if club_id:
payload["club_id"] = club_id
if division:
if division is not None:
payload["division"] = division

resource = self._get_resource(
Expand Down
91 changes: 91 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,14 @@ def test_result_season_results(self, mock_get_resource):
)
self.assertEqual(result, mock_get_resource.return_value)

self.client.result_season_results(
season_id, event_type=event_type, race_week_num=0
)
expected_payload["race_week_num"] = 0
mock_get_resource.assert_called_with(
"/data/results/season_results", payload=expected_payload
)

@patch.object(irDataClient, "_get_resource")
@patch.object(irDataClient, "_get_resource_or_link")
def test_member_awards(self, mock_get_resource_or_link, mock_get_resource):
Expand Down Expand Up @@ -1307,6 +1315,20 @@ def test_stats_season_driver_standings(self, mock_get_chunks, mock_get_resource)
mock_get_chunks.assert_called_once()
self.assertEqual(result, mock_get_chunks.return_value)

# test for 0 inputs which used to remove the input
self.client.stats_season_driver_standings(
season_id=season_id, car_class_id=car_class_id, race_week_num=0, division=0
)
mock_get_resource.assert_called_with(
"/data/stats/season_driver_standings",
payload={
"season_id": season_id,
"car_class_id": car_class_id,
"race_week_num": 0,
"division": 0,
},
)

@patch.object(irDataClient, "_get_resource")
@patch.object(irDataClient, "_get_chunks")
def test_stats_season_supersession_standings(
Expand All @@ -1328,6 +1350,20 @@ def test_stats_season_supersession_standings(
mock_get_chunks.assert_called_once()
self.assertEqual(result, mock_get_chunks.return_value)

# test for 0 inputs which used to remove the input
self.client.stats_season_supersession_standings(
season_id=season_id, car_class_id=car_class_id, race_week_num=0, division=0
)
mock_get_resource.assert_called_with(
"/data/stats/season_supersession_standings",
payload={
"season_id": season_id,
"car_class_id": car_class_id,
"race_week_num": 0,
"division": 0,
},
)

@patch.object(irDataClient, "_get_resource")
@patch.object(irDataClient, "_get_chunks")
def test_stats_season_team_standings(self, mock_get_chunks, mock_get_resource):
Expand All @@ -1345,6 +1381,19 @@ def test_stats_season_team_standings(self, mock_get_chunks, mock_get_resource):
mock_get_chunks.assert_called_once()
self.assertEqual(result, mock_get_chunks.return_value)

self.client.stats_season_team_standings(
season_id, car_class_id, race_week_num=0
)

mock_get_resource.assert_called_with(
"/data/stats/season_team_standings",
payload={
"season_id": season_id,
"car_class_id": car_class_id,
"race_week_num": 0,
},
)

@patch.object(irDataClient, "_get_resource")
@patch.object(irDataClient, "_get_chunks")
def test_stats_season_tt_standings(self, mock_get_chunks, mock_get_resource):
Expand All @@ -1362,6 +1411,20 @@ def test_stats_season_tt_standings(self, mock_get_chunks, mock_get_resource):
mock_get_chunks.assert_called_once()
self.assertEqual(result, mock_get_chunks.return_value)

self.client.stats_season_tt_standings(
season_id, car_class_id, race_week_num=0, division=0
)

mock_get_resource.assert_called_with(
"/data/stats/season_tt_standings",
payload={
"season_id": season_id,
"car_class_id": car_class_id,
"race_week_num": 0,
"division": 0,
},
)

@patch.object(irDataClient, "_get_resource")
@patch.object(irDataClient, "_get_chunks")
def test_stats_season_tt_results(self, mock_get_chunks, mock_get_resource):
Expand All @@ -1386,6 +1449,20 @@ def test_stats_season_tt_results(self, mock_get_chunks, mock_get_resource):
mock_get_chunks.assert_called_once()
self.assertEqual(result, mock_get_chunks.return_value)

self.client.stats_season_tt_results(
season_id, car_class_id, race_week_num, division=0
)

mock_get_resource.assert_called_with(
"/data/stats/season_tt_results",
payload={
"season_id": season_id,
"car_class_id": car_class_id,
"race_week_num": race_week_num,
"division": 0,
},
)

@patch.object(irDataClient, "_get_resource")
@patch.object(irDataClient, "_get_chunks")
def test_stats_season_qualify_results(self, mock_get_chunks, mock_get_resource):
Expand All @@ -1410,6 +1487,20 @@ def test_stats_season_qualify_results(self, mock_get_chunks, mock_get_resource):
mock_get_chunks.assert_called_once()
self.assertEqual(result, mock_get_chunks.return_value)

self.client.stats_season_qualify_results(
season_id, car_class_id, race_week_num, division=0
)

mock_get_resource.assert_called_with(
"/data/stats/season_qualify_results",
payload={
"season_id": season_id,
"car_class_id": car_class_id,
"race_week_num": race_week_num,
"division": 0,
},
)

@patch.object(irDataClient, "_get_chunks")
@patch.object(irDataClient, "_get_resource")
def test_stats_world_records(self, mock_get_resource, mock_get_chunks):
Expand Down

0 comments on commit a7333d9

Please sign in to comment.