"""This module holds the test cases for the managers of the ``media`` app"""

from django.test.testcases import TestCase

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

from ..factories import (
    PdfMediaFactory,
    PresentationFactory,
    PresentationMediaFactory,
)
from ..models import PresentationMedia


class DependencyPresentationMediaContentQuerySetTestCase(WithMediaOnDisk, TestCase):
    """Test case for the ``DependencyPresentationMediaContentsQuerySet`` QuerySet"""

    def test_get_media_for_presentation_should_return_the_media(self):
        """Test that the ``get_media_for_presentation`` should work correctly"""

        pdf_media = PdfMediaFactory()
        restricted_pdf_media = PdfMediaFactory()
        presentation = PresentationFactory()

        # The media is not yet associated with the presentation
        self.assertIsNone(
            PresentationMedia.objects.get_media_for_presentation(presentation)
        )

        PresentationMediaFactory(
            media=pdf_media,
            presentation=presentation
        )

        # Now we should be able to find the media
        self.assertEqual(
            PresentationMedia.objects.get_media_for_presentation(presentation),
            pdf_media
        )

        # No restricted media yet
        self.assertIsNone(
            PresentationMedia.objects.get_media_for_presentation(
                presentation,
                is_restricted=True
            )
        )

        PresentationMediaFactory(
            media=restricted_pdf_media,
            presentation=presentation,
            is_restricted=True
        )

        self.assertEqual(
            PresentationMedia.objects.get_media_for_presentation(
                presentation,
                is_restricted=True
            ),
            restricted_pdf_media
        )
