def test_serialize_date_as_key(self): s = serialization.OpalSerializer() data = { datetime.date(1959, 3, 2): [ "So What" ] } serialised = s.default(data) expected = { '02/03/1959': ['So What'] } self.assertEqual(expected, serialised)
def test_binaries_become_utf_8(self): s = serialization.OpalSerializer() binary = six.b('Hello beautiful world. I am a binary.') serialized = s.default(binary) self.assertIsInstance(serialized, six.text_type)
def test_serializer_default_will_super(self): s = serialization.OpalSerializer() with self.assertRaises(TypeError): s.default(None)
def test_serialize_date_in_list(self): s = serialization.OpalSerializer() data = [datetime.date(1959, 4, 22), 11, 33] expected = ['22/04/1959', 11, 33] serialised = s.default(data) self.assertEqual(expected, serialised)
def test_time_serialisation(self): s = serialization.OpalSerializer() serialised = s.default(datetime.time(20)) self.assertEqual(serialised, "20:00:00")
def test_decimal_serialization(self): data = decimal.Decimal("12.00") serializer = serialization.OpalSerializer() serialised = serializer.default(data) self.assertEqual("12.00", serialised)