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:
84
tests/test_admin_email.py
Normal file
84
tests/test_admin_email.py
Normal file
@@ -0,0 +1,84 @@
|
||||
import pytest
|
||||
from sqlalchemy import text
|
||||
|
||||
from web.app import app
|
||||
from web.db import (
|
||||
db_init,
|
||||
create_or_update_user,
|
||||
subscribe_email,
|
||||
list_email_subscriptions,
|
||||
_ensure_session,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope="function", autouse=True)
|
||||
def initialize_app():
|
||||
app.config.update(TESTING=True, WTF_CSRF_ENABLED=False)
|
||||
with app.app_context():
|
||||
db_init()
|
||||
create_or_update_user("admin", password="secret",
|
||||
is_admin=True, is_active=True)
|
||||
# Clear subscriptions before and after each test to avoid leakage
|
||||
with _ensure_session() as session:
|
||||
session.execute(text("DELETE FROM email_subscriptions"))
|
||||
session.commit()
|
||||
yield
|
||||
with _ensure_session() as session:
|
||||
session.execute(text("DELETE FROM email_subscriptions"))
|
||||
session.commit()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
with app.test_client() as test_client:
|
||||
with test_client.session_transaction() as sess:
|
||||
sess["username"] = "admin"
|
||||
yield test_client
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def anon_client():
|
||||
with app.test_client() as test_client:
|
||||
# Ensure no admin session present
|
||||
with test_client.session_transaction() as sess:
|
||||
sess.pop("username", None)
|
||||
yield test_client
|
||||
|
||||
|
||||
def test_admin_emails_requires_admin(anon_client):
|
||||
response = anon_client.get("/admin/emails")
|
||||
assert response.status_code == 302
|
||||
assert "/login" in response.headers.get("Location", "")
|
||||
|
||||
|
||||
def test_admin_emails_lists_subscriptions(client):
|
||||
subscribe_email("alice@example.com")
|
||||
response = client.get("/admin/emails")
|
||||
assert response.status_code == 200
|
||||
assert b"alice@example.com" in response.data
|
||||
|
||||
|
||||
def test_admin_emails_can_subscribe(client):
|
||||
response = client.post(
|
||||
"/admin/emails",
|
||||
data={"action": "subscribe", "email": "bob@example.com"},
|
||||
follow_redirects=False,
|
||||
)
|
||||
assert response.status_code == 302
|
||||
emails = list_email_subscriptions()
|
||||
assert any(sub["email"] == "bob@example.com" and sub["is_active"]
|
||||
for sub in emails)
|
||||
|
||||
|
||||
def test_admin_emails_can_unsubscribe(client):
|
||||
subscribe_email("carol@example.com")
|
||||
response = client.post(
|
||||
"/admin/emails",
|
||||
data={"action": "unsubscribe", "email": "carol@example.com"},
|
||||
follow_redirects=False,
|
||||
)
|
||||
assert response.status_code == 302
|
||||
emails = list_email_subscriptions()
|
||||
matching = [sub for sub in emails if sub["email"] == "carol@example.com"]
|
||||
assert matching
|
||||
assert matching[0]["is_active"] is False
|
||||
Reference in New Issue
Block a user