"""Test the email notifications of the ``trainings`` app."""

from django.core import mail

from mtp.apps.common.tests.test_cases import MTPTestCase
from mtp.apps.common.tests.waffle_test_utils import override_switch


class TrainingsSessionNotificationsTestcase(MTPTestCase):
    """Test cases for the email notifications of the ``TrainingSession`` model."""

    @override_switch('enable_sessions_end_mail_for_trainees', active=True)
    def test_send_session_end_email_for_trainees(self):
        """Test that the mail for trainee is successfully sent."""

        self.training_session.send_end_mail()

        # We got one mail, for the trainee
        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(mail.outbox[0].to, [self.trainee.email])

    @override_switch('enable_sessions_end_mail_for_trainers', active=True)
    def test_send_session_end_email_for_trainer(self):
        """Test that the mail for trainer is successfully sent."""

        self.training_session.send_end_mail()

        # We got one mail, for the trainer
        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(mail.outbox[0].to, [self.trainer.email])

    @override_switch('enable_sessions_end_mail_for_trainers', active=True)
    @override_switch('enable_sessions_end_mail_for_trainees', active=True)
    def test_send_session_end_email_for_all(self):
        """Test that both the mails are successfully sent."""

        self.training_session.send_end_mail()

        # We got two mails, one for the trainee, one for the trainer
        self.assertEqual(len(mail.outbox), 2)
