fix: invoke actual cog callback in test_error_handling_and_logging (#39) #54
No reviewers
Labels
No Label
ai-changes-requested
ai-failed
ai-pr-opened
ai-reviewed
ai-reviewing
ai-working
ai-working
bug
enhancement
feature
in-queue
performance
security
tech-debt
todo
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cal/paper-dynasty-discord#54
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "ai/paper-dynasty-discord-39"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Fixes #39 —
test_error_handling_and_logging(lines 500-524) was a no-op: it patchedapi_calls.db_getandpygsheets.authorize, called those mocks directly, caught the exceptions, and passed. The actual cog method was never invoked, so the test passed even when all cog code was deleted.Changes
tests/players_refactor/test_team_management.py@patch('logging.getLogger')decorator and no-op mock-only test body.pull_roster_command.callbackfrom the realTeamManagementcog instance (skips gracefully if the cog can't be imported).get_context_user,get_team_by_owner, andget_rostersat the correct module-level names (cogs.players_new.team_management.*).get_rostersto raise anException(simulating a Google Sheets connection error).cmd.callback(cog, ctx).ctx.sendwas called with'Could not retrieve rosters from your sheet.'— the exact error message in the cog's exception handler.This test now fails if the
pull_roster_commandmethod body is deleted or the exception-handling branch is removed.Notes
test_error_handling_and_loggingwas intentional; the rest is formatter-driven.mock_*_commandfunctions instead of calling real cog methods — the same pattern as the fixed test. Line 279 also referencessample_team_datawhich is undefined in that scope (pre-existing bug).AI Code Review
Files Reviewed
tests/players_refactor/test_team_management.py(modified)Findings
Correctness
test_error_handling_and_loggingis correct. The patch paths (cogs.players_new.team_management.get_context_user,get_team_by_owner,get_rosters) match the actual import-time bindings in the module.get_rostersis called synchronously in the cog (rosters = get_rosters(team, self.bot)); patching it withside_effect=Exception(...)(notAsyncMock) is correct.get_team_by_owneris awaited in the cog; patching withnew=AsyncMock(return_value=team_with_sheet)is correct.get_context_userreturnsmock_context.author(which has.id = 12345), so theget_team_by_ownercall receives the right argument.team_with_sheetfixture has"gsheet": "valid-sheet-id"— this correctly passes theif not team.get('gsheet') or team.get('gsheet') == 'None'guard in the cog, reaching theget_rosterscall.'Could not retrieve rosters from your sheet.'matches exactly what the cog sends at line 264 ofcogs/players_new/team_management.py.cmd.callback(cog, ctx)bypasses command decorators (legal_channel, role check) as intended — the test is scoped to business logic only.Security
Style & Conventions
test_error_handling_and_loggingno longer describes the test. It now specifically testspull_roster_command's exception path; a name liketest_pull_roster_command_get_rosters_exception_sends_errorwould be more discoverable. Minor — doesn't block merging.team_with_sheetis defined inline rather than using thesample_teamfixture from conftest.tests/CLAUDE.mdsays to use factory data when possible. The divergence is justified here — the existingsample_teamfixture has'gsheet': 'None'which would fail the gsheet guard and never reachget_rosters, so a custom value is necessary.Suggestions
test_error_handling_and_loggingto something that reflects the specific path being tested (e.g.test_pull_roster_command_exception_sends_error_message).team_with_sheetcould be derived from thesample_teamfixture:{**sample_team, "gsheet": "valid-sheet-id"}— slightly cleaner.Verdict: APPROVED
The core fix is sound. The old test was a genuine no-op (all paths caught their own exceptions and called
pass); the new test calls the real cog callback and asserts the actual error message. Patch paths, mock types, and the assertion string are all correct. Minor naming and fixture-style suggestions are non-blocking.Automated review by Claude PR Reviewer
4009be1e44to7b76b429a8