Coverage for tests/core_tests/test_email_handler.py: 100%
27 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-05 14:02 +0000
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-05 14:02 +0000
1"""Tests for email_handler.py"""
3from email.mime.text import MIMEText
4import os
5import sys
7import pytest
9# flake8: noqa: F811
11sys.path.append(
12 os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
13)
15from core.email_handler import generate_otp, send_otp, send_email
17os.environ["IS_TEST"] = "True"
20@pytest.fixture
21def app():
22 from app import app
24 app.config["TESTING"] = True
25 return app
28def test_generate_otp():
29 otp = generate_otp()
30 assert isinstance(otp, str)
31 assert len(otp) == 6
32 assert otp.isdigit()
35def test_send_otp(app):
36 """Test send_otp function"""
38 with app.app_context():
39 with app.test_request_context():
40 send_otp("test@example.com")
43def test_send_email(app):
44 """Test send_email function"""
45 msg = MIMEText("<body>Test</body>", "html")
46 recipients = ["test@example.com"]
47 with app.app_context():
48 with app.test_request_context():
49 send_email(msg, recipients)