def test_simple_missing_incoming(self): source_dict = {} target_object = Mock(name='target') field = AttributeField(attribute='foo', type=int) with self.assertRaises(ValidationError): field.handle_incoming(mock_context(), source_dict, target_object)
def test_simple_incoming(self): source_dict = {'foo': 20} target_object = Mock(name='target') field = AttributeField(attribute='foo', type=int) field.handle_incoming(mock_context(), source_dict, target_object) self.assertEqual(target_object.foo, 20)
def test_incoming_read_only(self): source_dict = {'foo': 20} target_object = Mock(name='target', spec=[]) field = AttributeField(attribute='foo', type=int, read_only=True) field.handle_incoming(mock_context(), source_dict, target_object) self.assertFalse(hasattr(target_object, 'foo'))
def test_multilevel_incoming(self): source_dict = {'bar': 20} field = AttributeField(attribute='foo.bar', type=int) target_object = Mock(name='target') field.handle_incoming(mock_context(), source_dict, target_object) self.assertEqual(target_object.foo.bar, 20)
def test_simple_incoming(self): source_dict = { 'foo': 20 } target_object = Mock(name='target') field = AttributeField(attribute='foo', type=int) field.handle_incoming(mock_context(), source_dict, target_object) self.assertEqual(target_object.foo, 20)
def test_incoming_read_only(self): source_dict = { 'foo': 20 } target_object = Mock(name='target', spec=[]) field = AttributeField(attribute='foo', type=int, read_only=True) field.handle_incoming(mock_context(), source_dict, target_object) self.assertFalse(hasattr(target_object, 'foo'))
def test_multilevel_incoming(self): source_dict = { 'bar': 20 } field = AttributeField(attribute='foo.bar', type=int) target_object = Mock(name='target') field.handle_incoming(mock_context(), source_dict, target_object) self.assertEqual(target_object.foo.bar, 20)
def test_alternate_name_incoming(self): source_dict = { 'foo': 20 } field = AttributeField(attribute='foo.bar', type=int, published_property='foo') target_object = Mock(name='target') field.handle_incoming(mock_context(), source_dict, target_object) self.assertEqual(target_object.foo.bar, 20)
def test_alternate_name_incoming(self): source_dict = {'foo': 20} field = AttributeField(attribute='foo.bar', type=int, published_property='foo') target_object = Mock(name='target') field.handle_incoming(mock_context(), source_dict, target_object) self.assertEqual(target_object.foo.bar, 20)
def test_incoming_pushes_and_pops(self): source_dict = {'foo': 20} ctx = mock_context() target_object = Mock(name='target') field = AttributeField(attribute='foo', type=int) field.handle_incoming(ctx, source_dict, target_object) ctx.assert_has_calls([ mock.call.push(target_object), mock.call.pop(), ])
def test_incoming_pushes_and_pops(self): source_dict = { 'foo': 20 } ctx = mock_context() target_object = Mock(name='target') field = AttributeField(attribute='foo', type=int) field.handle_incoming(ctx, source_dict, target_object) ctx.assert_has_calls([ mock.call.push(target_object), mock.call.pop(), ])