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

1"""Tests for email_handler.py""" 

2 

3from email.mime.text import MIMEText 

4import os 

5import sys 

6 

7import pytest 

8 

9# flake8: noqa: F811 

10 

11sys.path.append( 

12 os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) 

13) 

14 

15from core.email_handler import generate_otp, send_otp, send_email 

16 

17os.environ["IS_TEST"] = "True" 

18 

19 

20@pytest.fixture 

21def app(): 

22 from app import app 

23 

24 app.config["TESTING"] = True 

25 return app 

26 

27 

28def test_generate_otp(): 

29 otp = generate_otp() 

30 assert isinstance(otp, str) 

31 assert len(otp) == 6 

32 assert otp.isdigit() 

33 

34 

35def test_send_otp(app): 

36 """Test send_otp function""" 

37 

38 with app.app_context(): 

39 with app.test_request_context(): 

40 send_otp("test@example.com") 

41 

42 

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)