feat: Implement email sending utilities and templates for job notifications
Some checks failed
CI/CD Pipeline / test (push) Failing after 4m9s
Some checks failed
CI/CD Pipeline / test (push) Failing after 4m9s
- Added email_service.py for sending emails with SMTP configuration. - Introduced email_templates.py to render job alert email subjects and bodies. - Enhanced scraper.py to extract contact information from job listings. - Updated settings.js to handle negative keyword input validation. - Created email.html and email_templates.html for managing email subscriptions and templates in the admin interface. - Modified base.html to include links for email alerts and templates. - Expanded user settings.html to allow management of negative keywords. - Updated utils.py to include functions for retrieving negative keywords and email settings. - Enhanced job filtering logic to exclude jobs containing negative keywords.
This commit is contained in:
40
tests/test_email_templates.py
Normal file
40
tests/test_email_templates.py
Normal file
@@ -0,0 +1,40 @@
|
||||
from datetime import datetime
|
||||
|
||||
from web.email_templates import render_job_alert_email
|
||||
|
||||
|
||||
def test_render_job_alert_email_with_jobs():
|
||||
jobs = [
|
||||
{
|
||||
"title": "Python Developer",
|
||||
"company": "Acme",
|
||||
"location": "Remote",
|
||||
"url": "https://example.com/jobs/1",
|
||||
},
|
||||
{
|
||||
"title": "Data Engineer",
|
||||
"company": "Globex",
|
||||
"location": "NYC",
|
||||
"url": "https://example.com/jobs/2",
|
||||
},
|
||||
]
|
||||
ts = datetime(2025, 11, 3, 12, 0)
|
||||
rendered = render_job_alert_email(
|
||||
jobs, region="sfbay", keyword="python", generated_at=ts)
|
||||
|
||||
assert rendered["subject"] == "2 new jobs (region: sfbay, keyword: python)"
|
||||
assert "1. Python Developer" in rendered["body"]
|
||||
assert "Generated at 2025-11-03 12:00 UTC." in rendered["body"]
|
||||
assert rendered["context"]["count"] == 2
|
||||
assert rendered["context"]["jobs_section"].startswith(
|
||||
"\n1. Python Developer")
|
||||
|
||||
|
||||
def test_render_job_alert_email_empty():
|
||||
ts = datetime(2025, 11, 3, 12, 0)
|
||||
rendered = render_job_alert_email([], generated_at=ts)
|
||||
|
||||
assert rendered["subject"] == "No new jobs"
|
||||
assert "No jobs matched this alert." in rendered["body"]
|
||||
assert rendered["body"].count("Generated at") == 1
|
||||
assert rendered["context"]["count"] == 0
|
||||
Reference in New Issue
Block a user