-
Notifications
You must be signed in to change notification settings - Fork 24
Improve email template tests #4473
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
Conversation
- Add sent_emails fixture to capture SentEmail objects during tests - Remove EmailTemplate class mocking in favor of real template usage - Add assertions to verify correct template identifiers are used - Verify email templates belong to correct conferences - Verify emails are sent to correct recipients with correct placeholders - Updated key test files: submissions, grants, and API tests 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Marco Acierno <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4473 +/- ##
=======================================
Coverage 94.53% 94.53%
=======================================
Files 352 352
Lines 10131 10131
Branches 733 733
=======================================
Hits 9577 9577
Misses 461 461
Partials 93 93 🚀 New features to boost your workflow:
|
|
@claude update all places where EmailTemplate is mocked |
|
Claude finished @marcoacierno's task —— View job I've successfully updated all places where EmailTemplate is mocked across the codebase! ✅ Todo List:
Summary of ChangesUpdated EmailTemplate mocking in 4 test files with 14 total functions:
Changes Applied:
The changes follow the exact same pattern established in the existing PR improvements, ensuring consistency across all email template tests. All changes have been committed and pushed to the branch. Commit: |
- Replace @patch("..tasks.EmailTemplate") with sent_emails fixture - Add EmailTemplateFactory instances with correct identifiers - Replace mock assertions with sent_emails() assertions - Verify template identifier, conference, recipients, and placeholders This ensures tests use real EmailTemplate instances instead of mocks, improving test reliability and coverage. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Marco Acierno <[email protected]>
|
@claude tests are failing Check the enum "EmailTemplateIdentifier" to see what identifiers exist
|
|
Claude finished @marcoacierno's task —— View job I've successfully fixed all the failing tests by correcting the EmailTemplateIdentifier enum values! ✅ Todo List:
Changes Made:✅ Fixed
✅ Fixed
✅ Fixed
SummaryAll EmailTemplateIdentifier enum usage has been corrected to match the actual enum values defined in Commit: |
- Fix grant_reply_* identifiers to use correct grant_* names - Fix sponsor_brochure to sponsorship_brochure - Fix proposal_time_slot_changed to proposal_scheduled_time_changed Co-authored-by: Marco Acierno <[email protected]>
|
@claude do a code-review of this PR |
|
Claude finished @marcoacierno's task —— View job 📋 Code Review: Email Template Test ImprovementsThis PR successfully modernizes email template testing by removing brittle mocking and implementing comprehensive verification of actual email behavior. Here's my detailed analysis: ✅ Strengths1. Excellent Fixture DesignThe
2. Comprehensive Test CoverageTests now verify the complete email flow:
3. Consistent Implementation PatternAll modified files follow the same reliable pattern: def test_example(sent_emails):
# Setup data and EmailTemplate
EmailTemplateFactory(
conference=conference,
identifier=EmailTemplateIdentifier.some_template,
)
# Execute the function
some_email_task(param_id=obj.id)
# Verify results
emails_sent = sent_emails()
assert emails_sent.count() == 1
sent_email = emails_sent.first()
assert sent_email.email_template.identifier == EmailTemplateIdentifier.some_template
assert sent_email.recipient == expected_user
# ... additional assertions4. Thorough Placeholder TestingTests verify complex placeholder scenarios like:
5. Proper Error HandlingThe PR correctly handles EmailTemplateIdentifier enum fixes:
🔧 Areas for Consideration1. Test Data ConsistencySome tests use hardcoded test data that might be fragile: # backend/grants/tests/test_tasks.py:49-50
assert sent_email.placeholders["user_name"] == "Marco Acierno"
assert sent_email.placeholders["conference_name"] == grant.conference.name.localize("en")Suggestion: Consider using factory-generated data or making assertions more flexible. 2. Duplicate EmailTemplateFactory CallsSome tests create redundant templates: # backend/schedule/tests/test_tasks.py:58-62
EmailTemplateFactory(
conference=schedule_item.conference,
identifier=EmailTemplateIdentifier.proposal_scheduled,
)
EmailTemplateFactory(identifier=EmailTemplateIdentifier.proposal_scheduled) # Why both?3. Complex Placeholder AssertionsSome tests have very detailed placeholder checks that might be brittle: # backend/grants/tests/test_tasks.py:145-151
assert sent_email.placeholders["deadline_date_time"] == "1 February 2023 23:59 UTC"
assert sent_email.placeholders["start_date"] == "2 May"
assert sent_email.placeholders["end_date"] == "6 May"These could break if date formatting changes. 🎯 Technical QualityImport Organization: ✅ Good
Test Isolation: ✅ Excellent
Error Scenarios: ✅ Well Covered
📊 Impact AssessmentReliability: 🔼 Major Improvement
Maintainability: 🔼 Significant Improvement
Coverage: 🔼 Enhanced
🏆 Final AssessmentThis PR represents a substantial improvement to email template testing. The migration from mocking to integration testing using the Key Achievements:✅ Consistent testing pattern across all modules Recommendation: ✅ APPROVEThis PR successfully addresses issue #4082 and significantly improves the test suite's reliability and maintainability. The implementation is consistent, well-tested, and follows Django/pytest best practices. |
|
@claude |
|
Claude finished @marcoacierno's task —— View job I've successfully updated the Todo List:
Changes Made:Updated
The test now follows the exact same modernized pattern as all other email template tests in this PR, removing brittle mocking and verifying actual email behavior through the Commit: |
- Remove EmailTemplate mocking in favor of real template usage - Add sent_emails fixture parameter - Replace mock assertions with verification of actual email sending - Follow same pattern as other email template tests in PR Co-authored-by: Marco Acierno <[email protected]>
This PR addresses issue #4082 by improving email template tests:
Closes #4082
Generated with Claude Code