"""This module holds the test for the views of the ``evaluations`` app."""

from django.core.urlresolvers import reverse

from .test_cases import EvaluationTestCase


class EvaluationEditViewsTestCase(EvaluationTestCase):
    """Test the edit views of the evaluation"""

    @classmethod
    def setUpTestData(cls):
        """Setup the test data"""

        super().setUpTestData()

        cls.urls_to_test = [
            cls.evaluation.get_absolute_url(),
            cls.evaluation.get_detail_url(),
            cls.evaluation.get_edit_url(),
            cls.evaluation.get_exercise_create_url(),
            cls.evaluation.get_exercises_sort_url(),
            cls.evaluation.get_create_url(training=cls.training),
        ]

    def test_all_routes_should_work_as_the_owner(self):
        """Test the response_code of all the evaluations routes, as the owner"""

        self.login_as_trainer()

        for url in self.urls_to_test:
            response = self.client.get(url)
            self.assertEqual(response.status_code, 200)

    def test_all_routes_should_be_404_as_the_non_owner(self):
        """Test the response_code of all the evaluations routes, as a non-owner"""

        self.login_as_admin()

        for url in self.urls_to_test:
            response = self.client.get(url)
            self.assertEqual(response.status_code, 404, url)


class XLSEvaluationImportViewTestCase(EvaluationTestCase):
    """Test the ``XLSEvaluationImportView`` view."""

    def test_template_example_file(self):
        """Test the ``template_example_file`` variable exists."""

        self.login_as_trainer()
        response = self.client.get(reverse('evaluations:evaluation-import-xls', kwargs={
            'training_uuid': self.training.id,
        }))

        self.assertIn('template_example_file', response.context)
        self.assertIsNotNone(response.context['template_example_file'])
