"""This module holds test cases for the ``reveal`` app."""

from mtp.apps.accounts.factories import TraineeFactory, TrainerFactory
from mtp.apps.common.tests.test_cases import MTPTestCase, WithMediaOnDisk
from mtp.apps.common.tests.test_utils import create_fake_image_file
from mtp.apps.themes.factories import ThemeFactory
from mtp.apps.trainings.factories import TrainingFactory, TrainingSessionFactory


class RevealTestCase(MTPTestCase, WithMediaOnDisk):
    """Base test in ``reveal`` app."""

    @classmethod
    def setUpTestData(cls):
        """Create data to test ``reveal`` app."""

        super().setUpTestData()

        # Using default theme
        cls.training_with_default_theme = TrainingFactory()
        cls.session_with_default_theme = TrainingSessionFactory(
            training=cls.training_with_default_theme
        )

        # Using a custom theme, with a custom logo
        cls.reveal_logo = create_fake_image_file()
        cls.custom_theme = ThemeFactory(reveal_logo=cls.reveal_logo)
        cls.training_with_custom_theme = TrainingFactory(theme=cls.custom_theme)
        cls.session_with_custom_theme = TrainingSessionFactory(
            training=cls.training_with_custom_theme
        )

        # Create session where each trainee have a photo
        # We have 3 trainees and 1 trainer, so 4 users, all with a photo
        cls.session_with_trainees_all_photos = TrainingSessionFactory()
        for trainee in cls.trainees:
            cls.session_with_trainees_all_photos.users.add(trainee)

        # Create session where some trainee does NOT have a photo
        # We have 4 trainees and 1 trainer, so 5 users, 2 without photo
        trainer_without_photo = TrainerFactory(photo=None)
        trainee_without_photo = TraineeFactory(photo=None)
        cls.session_with_trainees_no_photos = TrainingSessionFactory(
            trainer=trainer_without_photo
        )
        for trainee in cls.trainees:
            cls.session_with_trainees_no_photos.users.add(trainee)
        cls.session_with_trainees_no_photos.users.add(trainee_without_photo)

    def check_dict(self, dictionary, expected):
        """Use to test default values set in constants

        Parameters
        ----------
        dictionary: dict
            The dictionnary containing values to test.

        expected: dict
            The dictionnary containing values to compare.

        """

        for key, value in expected.items():
            if isinstance(value, dict):
                self.check_dict(dictionary[key], value)
            else:
                self.assertEqual(dictionary[key], value)
