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

import unittest

from django.core import mail

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


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

    @unittest.skip('The view to download the trainee content dont exist anymore')
    def test_send_session_end_email(self):
        """Test that the mails sent in the ``send_end_mail`` method
        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)

        # We add a new trainee to the session's users
        self.training_session.users.add(self.trainees[1])

        # Empty the outbox
        mail.outbox = []

        self.training_session.send_end_mail()
        # We got three mails, two for the trainees, one for the trainer
        self.assertEqual(len(mail.outbox), 3)

        # The mail subject for the trainee is correct
        self.assertEqual(
            mail.outbox[0].subject,
            "[%s] Your new training content is online." % self.training.name
        )

        # The mail subject for the trainer is correct
        self.assertEqual(
            mail.outbox[2].subject,
            "[%s] Your training session content is online." % self.training.name
        )
