예제 #1
0
 def setUp(self):
     self.serializer = SimpleSerializer()
예제 #2
0
class TestSerialization(unittest.TestCase):
    def setUp(self):
        self.serializer = SimpleSerializer()

    def test_serialize_int(self):
        data = 1

        serialized = self.serializer.serialize(data)

        self.assertEqual(serialized, data)

    def test_serialize_str(self):
        data = 'the str'

        serialized = self.serializer.serialize(data)

        self.assertEqual(serialized, data)

    def test_serialize_float(self):
        data = 1.23

        serialized = self.serializer.serialize(data)

        self.assertEqual(serialized, data)

    def test_serialize_none(self):
        data = None

        serialized = self.serializer.serialize(data)

        self.assertEqual(serialized, data)

    def test_serialization_of_simple_dict(self):
        data = {
            'key1': 'value1',
            'key2': 'value2',
            'key3': 'value3',
        }

        serialized = self.serializer.serialize(data)

        self.assertEqual(serialized, data)

    def test_serialization_of_simple_list(self):
        data = [1, 2, 3, 4, 5]

        serialized = self.serializer.serialize(data)

        self.assertEqual(serialized, data)

    def test_serialization_of_nested_list_in_dict(self):
        data = {
            'key1': [1, 2, 3, 4, 5],
            'key2': [1],
            'key3': [1, 2, 5],
        }

        serialized = self.serializer.serialize(data)

        self.assertEqual(serialized, data)

    def test_multi_level_serializations(self):
        data = [
            {
                'key1': [1, 2, 3, 4, 5]
            },
            {
                'key2': [1]
            },
            {
                'key3': [1, 2, 5]
            },
        ]

        serialized = self.serializer.serialize(data)

        self.assertEqual(serialized, data)

    def test_decimal_serialization(self):
        data = {'key': [Decimal('1.0'), Decimal('1.1'), Decimal('1.2')]}

        serialized = self.serializer.serialize(data)

        self.assertEqual(serialized, {'key': ['1.0', '1.1', '1.2']})

    def test_datetime_serialization(self):
        string_date = '2014-11-13T14:53:18.694072+00:00'

        data = [arrow.get(string_date).datetime]

        serialized = self.serializer.serialize(data)

        self.assertEqual(serialized, [string_date])
class TestSerialization(unittest.TestCase):
    def setUp(self):
        self.serializer = SimpleSerializer()

    def test_serialize_int(self):
        data = 1

        serialized = self.serializer.serialize(data)

        self.assertEqual(serialized, data)

    def test_serialize_str(self):
        data = "the str"

        serialized = self.serializer.serialize(data)

        self.assertEqual(serialized, data)

    def test_serialize_float(self):
        data = 1.23

        serialized = self.serializer.serialize(data)

        self.assertEqual(serialized, data)

    def test_serialize_none(self):
        data = None

        serialized = self.serializer.serialize(data)

        self.assertEqual(serialized, data)

    def test_serialization_of_simple_dict(self):
        data = {"key1": "value1", "key2": "value2", "key3": "value3"}

        serialized = self.serializer.serialize(data)

        self.assertEqual(serialized, data)

    def test_serialization_of_simple_list(self):
        data = [1, 2, 3, 4, 5]

        serialized = self.serializer.serialize(data)

        self.assertEqual(serialized, data)

    def test_serialization_of_nested_list_in_dict(self):
        data = {"key1": [1, 2, 3, 4, 5], "key2": [1], "key3": [1, 2, 5]}

        serialized = self.serializer.serialize(data)

        self.assertEqual(serialized, data)

    def test_multi_level_serializations(self):
        data = [{"key1": [1, 2, 3, 4, 5]}, {"key2": [1]}, {"key3": [1, 2, 5]}]

        serialized = self.serializer.serialize(data)

        self.assertEqual(serialized, data)

    def test_decimal_serialization(self):
        data = {"key": [Decimal("1.0"), Decimal("1.1"), Decimal("1.2")]}

        serialized = self.serializer.serialize(data)

        self.assertEqual(serialized, {"key": ["1.0", "1.1", "1.2"]})

    def test_datetime_serialization(self):
        string_date = "2014-11-13T14:53:18.694072+00:00"

        data = [arrow.get(string_date).datetime]

        serialized = self.serializer.serialize(data)

        self.assertEqual(serialized, [string_date])
 def setUp(self):
     self.serializer = SimpleSerializer()
class TestSerialization(unittest.TestCase):

    def setUp(self):
        self.serializer = SimpleSerializer()

    def test_serialize_int(self):
        data = 1

        serialized = self.serializer.serialize(data)

        self.assertEqual(serialized, data)

    def test_serialize_str(self):
        data = 'the str'

        serialized = self.serializer.serialize(data)

        self.assertEqual(serialized, data)

    def test_serialize_float(self):
        data = 1.23

        serialized = self.serializer.serialize(data)

        self.assertEqual(serialized, data)

    def test_serialize_none(self):
        data = None

        serialized = self.serializer.serialize(data)

        self.assertEqual(serialized, data)

    def test_serialization_of_simple_dict(self):
        data = {
            'key1': 'value1',
            'key2': 'value2',
            'key3': 'value3',
        }

        serialized = self.serializer.serialize(data)

        self.assertEqual(serialized, data)

    def test_serialization_of_simple_list(self):
        data = [1, 2, 3, 4, 5]

        serialized = self.serializer.serialize(data)

        self.assertEqual(serialized, data)

    def test_serialization_of_nested_list_in_dict(self):
        data = {
            'key1': [1, 2, 3, 4, 5],
            'key2': [1],
            'key3': [1, 2, 5],
        }

        serialized = self.serializer.serialize(data)

        self.assertEqual(serialized, data)

    def test_multi_level_serializations(self):
        data = [
            {'key1': [1, 2, 3, 4, 5]},
            {'key2': [1]},
            {'key3': [1, 2, 5]},
        ]

        serialized = self.serializer.serialize(data)

        self.assertEqual(serialized, data)

    def test_decimal_serialization(self):
        data = {
            'key': [Decimal('1.0'), Decimal('1.1'), Decimal('1.2')]
        }

        serialized = self.serializer.serialize(data)

        self.assertEqual(serialized, {'key': ['1.0', '1.1', '1.2']})

    def test_datetime_serialization(self):
        string_date = '2014-11-13T14:53:18.694072+00:00'

        data = [arrow.get(string_date).datetime]

        serialized = self.serializer.serialize(data)

        self.assertEqual(serialized, [string_date])