"""This module holds the tests for the redis models of the ``saba`` discrete_app"""

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

from ..factories import CertificationProgramUserStatusDjangoTaskFactory


class SabaLimpydTaskTestCase(MTPTestCase):
    """Test case for ``SabaLimpydTask`` linked to ``CertificationProgramUserStatusDjangoTask``"""

    @classmethod
    def setUpTestData(cls):
        """Set up our test task"""

        super().setUpTestData()

        cls.task = CertificationProgramUserStatusDjangoTaskFactory()

    def setUp(self):
        """Refresh our task between runs"""

        super().setUp()

        self.task.refresh_from_db()

    def test_saba_lympid_task_data_get_set(self):
        """Test the ``results`` accessors"""

        test_dict = {
            'bar': 1,
            'baz': {
                'foo': 'bar',
            },
        }

        self.task.redis_instance.results = test_dict

        self.task.refresh_from_db()

        self.assertEqual(self.task.redis_instance.results, test_dict)

    def test_saba_lympid_task_results_set_wrong_type(self):
        """The the ``results`` setter enforces dict type"""

        with self.assertRaises(TypeError):
            self.task.redis_instance.results = 'one_string'
