"""This module contains the test cases for the ``questionnaires`` app"""

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


from ..factories import (
    ChoiceFactory,
    ChoicesQuestionFactory,
    ImageChoicesQuestionFactory,
    OpenQuestionFactory,
    QuizFactory,
)


class BaseQuestionnairesTestCase:
    """Base test case for the ``questionnaires`` app related tests.

    It provides some default test data useful in a lot of tests.

    Attributes
    ----------
    quiz: ``Quiz``
        A quiz instance

    """

    @classmethod
    def setUpTestData(cls):
        """Create some data to use in the ``questionnaires`` related tests."""

        super().setUpTestData()

        with cls.training.override_version_state(cls.training.VERSION_STATES.DRAFT):

            # Data related to the ``Quiz`` model
            cls.quiz = QuizFactory(training=cls.training)
            cls.choices_questions = ChoicesQuestionFactory.create_batch(
                4,
                questionnaire=cls.quiz
            )
            for question in cls.choices_questions:

                # For each question, 2 valid choices...
                ChoiceFactory.create_batch(2, question=question, is_valid=True)

                # ...and 3 invalid choices
                ChoiceFactory.create_batch(3, question=question, is_valid=False)

            cls.open_question = OpenQuestionFactory(questionnaire=cls.quiz)
            cls.image_question = ImageChoicesQuestionFactory(questionnaire=cls.quiz)
            # We need at least one choice on this image question
            ChoiceFactory(question=cls.image_question, is_valid=False)


class QuestionnairesTestCase(BaseQuestionnairesTestCase, MTPTestCase):
    """A test case based on ``BaseQuestionnairesTestCase`` and ``MTPTestCase``.

    Should be used in most cases.

    """

    pass
