"""This module holds the test cases for the v2 api serializers of the ``workshops`` app"""

from django.core.urlresolvers import reverse

from rest_framework import status
from rest_framework.test import APITestCase

from mtp.apps.workshops.tests.test_cases import WorkshopTestCase


class WorkshopViewSetTestCase(WorkshopTestCase, APITestCase):
    """Test case for the ``WorkshopViewSet``"""

    def test_detail_view_is_working(self):
        """Test that the detail view is working correctly"""

        self.login_as_trainer()

        response = self.client.get(
            reverse('apiv2:workshop-detail', kwargs={'pk': self.workshop.id})
        )

        self.assertEqual(response.status_code, 200)


class WorkshopTraineeDetailedScoreViewTestCase(WorkshopTestCase, APITestCase):
    """Test cases for the ``WorkshopTraineeDetailedScoreView``"""

    @classmethod
    def setUpTestData(cls):
        """Store the url of the view"""

        super().setUpTestData()

        cls.workshop_results_url = reverse(
            'apiv2:workshop_detailed_results',
            kwargs={
                'session_uuid': cls.training_session.pk,
                'workshop_uuid': cls.workshop.pk,
                'user_uuid': cls.trainee.pk
            }
        )

    def test_view_should_return_the_workshop_results(self):
        """Test that the view correctly return the workshop results

        See Also
        --------
        ``WorkshopTraineeDetailedScoreSerializerTestCase`` containing the serializers tests.

        """

        self.login_as_trainee()

        response = self.client.get(self.workshop_results_url)

        # The route is working
        self.assertEqual(response.status_code, status.HTTP_200_OK)


class WorkshopTraineeScoreViewTestCase(WorkshopTestCase, APITestCase):
    """Test cases for the ``WorkshopTraineeScoreView``"""

    @classmethod
    def setUpTestData(cls):
        """Store the url of the view"""

        super().setUpTestData()

        cls.workshop_results_url = reverse(
            'apiv2:workshop_results',
            kwargs={
                'session_uuid': cls.training_session.pk,
                'workshop_uuid': cls.workshop.pk,
                'user_uuid': cls.trainee.pk
            }
        )

    def test_view_should_return_the_workshop_results(self):
        """Test that the view correctly return the workshop results

        See Also
        --------
        ``WorkshopTraineeDeScoreSerializerTestCase`` containing the serializers tests.

        """

        self.login_as_trainee()

        response = self.client.get(self.workshop_results_url)

        # The route is working
        self.assertEqual(response.status_code, status.HTTP_200_OK)
