"""This module contains the apiv2-related test cases for the ``reveal`` app"""

from django.core.urlresolvers import reverse

from ..constants import REVEAL_CONFIGURATION_OPTIONS
from .test_cases import RevealTestCase


class RevealEndpointsTestCase(RevealTestCase):
    """Test case for the reveal related api endpoint"""

    def test_reveal_base_config_endpoint_work(self):
        """Test that the base reveal endpoint work"""

        reveal_base_config_url = reverse(
            'apiv2:reveal-base-config',
            kwargs={'session_uuid': self.session_with_custom_theme.pk}
        )

        response = self.client.get(reveal_base_config_url)
        self.assertEqual(response.status_code, 200)

        # Test overrided fields exist
        # and by the way, that's the good serializer is called
        self.assertIsNotNone(response.data['datas']['assets']['images']['final_logo_converge'])
        self.assertIsNotNone(response.data['datas']['assets']['images']['final_logo'])
        self.assertIsNotNone(response.data['datas']['images']['url'])

        # Test default fields
        self.check_dict(response.data, REVEAL_CONFIGURATION_OPTIONS)

    def test_reveal_photos_endpoint_work(self):
        """Test that the reveal "photos" endpoint work"""

        reveal_photos_config_url = reverse(
            'apiv2:reveal-photos',
            kwargs={'session_uuid': self.session_with_trainees_all_photos.pk}
        )

        response = self.client.get(reveal_photos_config_url)
        self.assertEqual(response.status_code, 200)

        # 4 users : 3 trainees, 1 trainer, all with photos
        self.assertEqual(
            len(response.data),
            4
        )

        # Test fields exist
        # and by the way, that's the good serializer is called
        self.assertIsNotNone(response.data[0]['url_128x128'])
        self.assertIsNotNone(response.data[0]['url'])
        self.assertIsNotNone(response.data[0]['url_text'])

    def test_reveal_photos_endpoint_will_not_all_users_with_photo(self):
        """Test that the reveal "photos" endpoint add only users with photo"""

        reveal_photos_config_url = reverse(
            'apiv2:reveal-photos',
            kwargs={'session_uuid': self.session_with_trainees_no_photos.pk}
        )

        response = self.client.get(reveal_photos_config_url)
        self.assertEqual(response.status_code, 200)

        # 5 users : 4 trainees, 1 trainer, 2 without photo
        self.assertEqual(
            len(response.data),
            3
        )
