Ejemplo n.º 1
0
 def test_eq_with_different_fields(self):
     data_container_1 = data_container_module.DataContainer(
         field1='a',
         field2='b',
     )
     data_container_2 = data_container_module.DataContainer(
         field1='a',
         field2='a',
     )
     self.assertNotEqual(data_container_1, data_container_2)
 def test_serialize_data_without_permission_for_subclass(self):
     json_serialization.DataContainerObjectRenderer.set_safe_constructors(
         data_container.DataContainer, )
     original = data_container.DataContainer()
     encoded = self.encoder.Encode(original)
     decoded = self.decoder.Decode(encoded)
     self.assertEqual(decoded, original)
 def test_serialize_data_without_permission(self):
     json_serialization.DataContainerObjectRenderer.set_safe_constructors(
         self.MockSubclass, )
     original = data_container.DataContainer()
     encoded = self.encoder.Encode(original)
     with self.assertRaises(KeyError):
         self.decoder.Decode(encoded)
Ejemplo n.º 4
0
 def test_getattr_with_fields(self):
     data_container = data_container_module.DataContainer(
         field1='value1',
         field2=42,
     )
     self.assertEqual(data_container.field1, 'value1')
     self.assertEqual(data_container.field2, 42)
Ejemplo n.º 5
0
 def test_setattr_and_getattr_with_existing_field(self):
     data_container = data_container_module.DataContainer(
         field1='value1',
         field2=42,
     )
     data_container.field2 = 33
     self.assertEqual(data_container.field1, 'value1')
     self.assertEqual(data_container.field2, 33)
Ejemplo n.º 6
0
 def test_str_with_fields(self):
     data_container = data_container_module.DataContainer(
         field1='a',
         field2='b',
     )
     actual = str(data_container)
     expected1 = 'DataContainer{field1: a, field2: b}'
     expected2 = 'DataContainer{field2: b, field1: a}'
     self.assertTrue(actual == expected1 or actual == expected2)
Ejemplo n.º 7
0
 def test_getattr_with_state(self):
     data_container = data_container_module.DataContainer(
         field1='value1',
         field2=42,
     )
     expected = {
         'field1': 'value1',
         'field2': 42,
     }
     self.assertEqual(data_container.state, expected)
Ejemplo n.º 8
0
 def test_setattr_and_getattr_state_with_existing_field(self):
     data_container = data_container_module.DataContainer(
         field1='value1',
         field2=42,
     )
     data_container.field2 = 33
     expected = {
         'field1': 'value1',
         'field2': 33,
     }
     self.assertEqual(data_container.state, expected)
 def test_serialize_mock_subclass_with_nested_data(self):
     data1 = data_container.DataContainer()
     original = self.MockSubclass(data1, 33, field3=24)
     encoded = self.encoder.Encode(original)
     decoded = self.decoder.Decode(encoded)
     self.assertEqual(decoded, original)
Ejemplo n.º 10
0
 def test_serialize_data(self):
     original = data_container.DataContainer()
     encoded = self.encoder.Encode(original)
     decoded = self.decoder.Decode(encoded)
     self.assertEqual(decoded, original)
Ejemplo n.º 11
0
 def test_eq_with_empty_objects(self):
     data_container_1 = data_container_module.DataContainer()
     data_container_2 = data_container_module.DataContainer()
     self.assertEqual(data_container_1, data_container_2)
Ejemplo n.º 12
0
 def test_repr_with_empty_object(self):
     data_container = data_container_module.DataContainer()
     actual = str(data_container)
     expected = 'DataContainer{}'
     self.assertEquals(actual, expected)