"""This module contains the test cases for the utils of the ``licences`` app"""

from django.test.testcases import TestCase

from constance.test import override_config

from ..constants import LICENCES, LICENCE_CHOICES
from ..utils import current_licence_flags


class UtilsTestCase(TestCase):
    """Test case for the utils of the ``licences`` app"""

    def test_current_licence_flags_should_return_the_current_licence_values(self):
        """Test that the ``current_licence_flags`` should return the licences values"""

        # Per default we should get the values for the "ESSENTIAL" licence
        self.assertEqual(
            current_licence_flags(),
            LICENCES[LICENCE_CHOICES.ESSENTIAL]
        )

        # We can also read the values off the "CURRENT_LICENCE"
        self.assertEqual(
            current_licence_flags()['DISABLED_ACTIVITIES'],
            ['evaluation', 'race']
        )

        # Change the licence type to "ENTERPRISE"
        with override_config(LICENCE=LICENCE_CHOICES.ENTERPRISE):
            self.assertEqual(
                current_licence_flags(),
                LICENCES[LICENCE_CHOICES.ENTERPRISE]
            )

            # We can also read the values off the "CURRENT_LICENCE"
            self.assertEqual(
                current_licence_flags()['DISABLED_ACTIVITIES'],
                []
            )

    def test_current_licence_flags_should_return_the_max_media_storage(self):
        """Test that the ``current_licence_flags`` should return the max media storage"""

        # Default `MAX_MEDIA_STORAGE` (1 licence)
        self.assertEqual(
            current_licence_flags()['MAX_MEDIA_STORAGE'],
            524288000
        )

        # Change the number of licences
        with override_config(NBR_LICENCE=2):
            # The max media storage should be changed
            self.assertEqual(
                current_licence_flags()['MAX_MEDIA_STORAGE'],
                524288000 * 2
            )
