from django.test import TestCase
from django.core import mail 
from django.contrib.sites.models import Site

from apps.accounts.models import User
from apps.accounts.utils import send_activation_email, send_password_reset_email

class SendEmailTest(TestCase):
    def setUp(self):
        self.user = User.objects.create_user(
            first_name='brahim',
            last_name='bellahcen',
            email='brahimbellahcen@outlook.com',
            password='brahimbellahcen123',
        )
        self.user.save()
        self.current_site = Site.objects.get_current()

    def test_send_activation_email(self):
        """ Test that activation email is sent to the user """
        # call the function to send the activation email
        send_activation_email(self.user, self.current_site)

        # check if email was sent
        self.assertEqual(len(mail.outbox), 1)

        # check if email subject and recipient are correct
        self.assertEqual(mail.outbox[0].subject, 'UseVoice. | Account Confirmation')
        self.assertEqual(mail.outbox[0].to, [self.user.email])

        # check if email body contains the correct information
        self.assertIn(self.current_site.domain, mail.outbox[0].body)
        # self.assertIn(self.user.first_name, mail.outbox[0].body)

    def test_send_password_reset_email(self):
        """ Test that password reset email is sent to the user """
        # call the function to send the activation email
        send_password_reset_email(self.user, self.current_site)

        # check if email was sent
        self.assertEqual(len(mail.outbox), 1)

        # check if email subject and recipient are correct
        self.assertEqual(mail.outbox[0].subject, 'UseVoice. | Password Reset')
        self.assertEqual(mail.outbox[0].to, [self.user.email])

        # check if email body contains the correct information
        self.assertIn(self.current_site.domain, mail.outbox[0].body)
        # self.assertIn(self.user.first_name, mail.outbox[0].body)