-
Notifications
You must be signed in to change notification settings - Fork 3
(Feat): Add Unit Test Suite for RecommendationService / Recommendation Use Case Interactor #184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
a9af77d
added mock use case helpers for recommendation test
raymond367 aea74bb
added helpers to set up testing for mocking use case helpers
raymond367 f37e0b4
created minimal mock player repository
raymond367 fb393d1
helper methods for test setup for player repository
raymond367 61ecdc1
added mock rooster repository
raymond367 fe404b2
helper methods for test setup for mock rooster repostiory
raymond367 49ccb19
helper functoin to create mock data for test
raymond367 7d79b17
feat(recommendatoin-testing) added pytest fixtures for reusasble pyth…
raymond367 4089ba3
feat(recommendatoin-testing) added input validation error on recommen…
raymond367 6c0277c
feat(recommendation-testing) added test for case less than 9 saved ba…
raymond367 64cd000
feat(recommendation-testing) added test for correct input and checkin…
raymond367 630e74c
feat(recommendation-testing) edit test for recommended players with c…
raymond367 121910a
chore: update commit message for previous from ssr to srp
raymond367 d800c76
feat(recommendation-testing) added unit test to check if validate pla…
raymond367 15cce2a
feat(recommendation-testing) added unit test to query error when play…
raymond367 ae05656
feat(recommendation-testing) remove logger from recommendation service
raymond367 fdb4015
feat(recommendation-testing) clean up recommendation service
raymond367 4363a82
feat(recommendation-testing) further cleanup of recommendation service
raymond367 c26f4d1
feat(recommendation-testing) finish player position unit test
raymond367 3781554
feat (recomendation-testing) removed boiler plate methods and functoi…
raymond367 1aaae1d
feat (recommendation-testing) edited integrations test with sending a…
raymond367 178206a
feat (recommendation-testing) remove the start time in recommendation…
raymond367 221bc5b
feat (recommendation-testing) removed duplicate of player id in integ…
raymond367 9173dba
feat(recommendation-testing) very minor clean up on recommendation us…
raymond367 6873141
feat (recommendation-testing) added 2 additional unit test which chec…
raymond367 ad845c5
feat (recommendation-testing) re-clarify the algorithm and its specif…
raymond367 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| from repositories.player_repository import PlayerRepository | ||
| from typing import Dict, List, Optional | ||
| from unittest.mock import AsyncMock, Mock | ||
| from repositories.roster_avg_repository import RosterRepository | ||
|
|
||
| class MockRosterRepository(RosterRepository): | ||
| """Mock implementation of RosterRepository for testing""" | ||
|
|
||
| def __init__(self): | ||
| self._players_seasons_data: Dict[int, Dict] = {} | ||
| self._league_avg: Dict[str, float] = {} | ||
| self._league_std: Dict[str, float] = {} | ||
|
|
||
| async def get_players_seasons_data(self, player_ids: List[int]) -> Dict[int, Dict]: | ||
| """Get seasons data for multiple players.""" | ||
| result = {} | ||
| for pid in player_ids: | ||
| if pid in self._players_seasons_data: | ||
| result[pid] = self._players_seasons_data[pid] | ||
| return result | ||
|
|
||
| async def get_league_unweighted_average(self) -> Dict[str, float]: | ||
| """Fetch league-wide unweighted average stats.""" | ||
| return self._league_avg.copy() | ||
|
|
||
| async def get_league_unweighted_std(self) -> Dict[str, float]: | ||
| """Fetch league-wide unweighted standard deviations.""" | ||
| return self._league_std.copy() | ||
|
|
||
| async def get_league_weighted_std(self) -> Dict[str, float]: | ||
| pass | ||
|
|
||
| def fetch_team_roster(self, team_id: int, season: int) -> Dict[str, any]: | ||
| pass | ||
|
raymond367 marked this conversation as resolved.
|
||
|
|
||
| # Helper methods for test setup and edge case creation for use case interactor unit testing | ||
| def set_players_seasons_data(self, player_id: int, seasons: Dict): | ||
| """Set season data for a player.""" | ||
| self._players_seasons_data[player_id] = seasons | ||
|
|
||
| def set_league_avg(self, league_avg: Dict[str, float]): | ||
| """Set league average stats.""" | ||
| self._league_avg = league_avg.copy() | ||
|
|
||
| def set_league_std(self, league_std: Dict[str, float]): | ||
| """Set league standard deviations.""" | ||
| self._league_std = league_std.copy() | ||
|
|
||
| class MockPlayerRepository(PlayerRepository): | ||
| """Mock implementation of PlayerRepository for testing.""" | ||
|
|
||
| def __init__(self): | ||
| self._players: List[Dict] = [] | ||
| self._player_by_id: Dict[int, Dict] = {} | ||
|
|
||
| async def get_all_players(self) -> List[Dict]: | ||
| """Get all players from database.""" | ||
| return self._players.copy() | ||
|
|
||
| async def get_player_by_id(self, player_id: int) -> Optional[Dict]: | ||
| """Get a specific player by ID.""" | ||
| return self._player_by_id.get(player_id) | ||
|
|
||
| def upload_team(self, team, team_name, final_players): | ||
| pass | ||
|
|
||
| def bulk_upsert_players(self, players: List[Dict[str, any]]) -> None: | ||
| pass | ||
|
|
||
| def set_league_averages(self, league_doc: Dict[str, any]) -> None: | ||
| pass | ||
|
raymond367 marked this conversation as resolved.
|
||
| def build_player_image_url(self, player_id: int) -> str: | ||
| """Return a player headshot URL.""" | ||
| return f"https://example.com/players/{player_id}.jpg" | ||
|
|
||
| # heelper methods for test setup to add to in memory database | ||
| def add_player(self, player: Dict): | ||
| """Add a player to the mock repository.""" | ||
| mlbam_id = player.get("mlbam_id") | ||
| if mlbam_id: | ||
| self._player_by_id[mlbam_id] = player | ||
| self._players.append(player) | ||
|
|
||
| def set_player(self, player_id: int, player: Dict): | ||
| """Set a specific player by ID.""" | ||
| self._player_by_id[player_id] = player | ||
|
|
||
|
raymond367 marked this conversation as resolved.
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.