import unittest

from yandex_checkout.domain.common.base_object import BaseObject


class TestBaseObject(BaseObject):
    __test = None
    __int_value = None
    __float_value = None
    __base_object = None
    __values_list = None
    __base_objects_list = None

    @property
    def test(self):
        return self.__test

    @test.setter
    def test(self, value):
        self.__test = value

    @property
    def int_value(self):
        return self.__int_value

    @int_value.setter
    def int_value(self, value):
        self.__int_value = value

    @property
    def float_value(self):
        return self.__float_value

    @float_value.setter
    def float_value(self, value):
        self.__float_value = value

    @property
    def base_object(self):
        return self.__base_object

    @base_object.setter
    def base_object(self, value):
        self.__base_object = TestBaseObject(value)

    @property
    def values_list(self):
        return self.__values_list

    @values_list.setter
    def values_list(self, value):
        self.__values_list = value

    @property
    def base_objects_list(self):
        return self.__base_objects_list

    @base_objects_list.setter
    def base_objects_list(self, value):
        self.__base_objects_list = [TestBaseObject(item) for item in value]


class BaseObjectTest(unittest.TestCase):
    def setUp(self):
        self.fixture_args = {
            'test': 'test',
            'int_value': 123,
            'float_value': 1.01,
            'base_object': {
                'test': 'test'
            },
            'values_list': [1, 2, 3],
            'base_objects_list': [{'test': 'test'}, {'test': 'test'}, {'test': 'test'}]
        }

    def test_cas_to_dict_args(self):
        base_object = TestBaseObject(self.fixture_args)
        self.assertIsInstance(base_object.base_object, TestBaseObject)
        for item in base_object.base_objects_list:
            self.assertIsInstance(item, TestBaseObject)
        self.assertEqual(self.fixture_args, dict(base_object))

    def test_cas_to_dict_kwargs(self):
        base_object = TestBaseObject(**self.fixture_args)
        self.assertIsInstance(base_object.base_object, TestBaseObject)
        for item in base_object.base_objects_list:
            self.assertIsInstance(item, TestBaseObject)
        self.assertEqual(self.fixture_args, dict(base_object))