Пример #1
0
    def test_incoming_push_pop(self):
        Resource = Mock(name="resource")
        ctx = mock_context()

        field = SubObjectResourceField(attribute="foo", resource_class=Resource)

        source_dict = {"foo": {"bar": 20}}

        target_object = Mock()
        field.handle_incoming(ctx, source_dict, target_object)

        ctx.assert_has_calls([mock.call.push(target_object), mock.call.pop()])
Пример #2
0
    def test_handle_incoming_pre_save_optional(self):
        ctx = mock_context()
        ctx.resolve_resource_uri = Mock(name="resolve_resource_uri")
        sub_resource = ctx.resolve_resource_uri.return_value
        Resource = Mock(name="resource")

        source_dict = {"foo": {"resourceUri": "foo"}}
        target_obj = Mock(["save", "pre_save"], name="target_obj")
        field = SubObjectResourceField("foo", Resource)

        field.handle_incoming(ctx, source_dict, target_obj)

        self.assertEqual(sub_resource.model, target_obj.foo)
Пример #3
0
    def test_incoming_push_pop(self):
        Resource = Mock(name='resource')
        ctx = mock_context()

        field = SubObjectResourceField(attribute='foo', resource_class=Resource)

        source_dict = {
            'foo': {'bar': 20},
        }

        target_object = Mock()
        field.handle_incoming(ctx, source_dict, target_object)

        ctx.assert_has_calls([
            mock.call.push(target_object),
            mock.call.pop(),
        ])
Пример #4
0
    def test_handle_incoming_pre_save_optional(self):
        ctx = mock_context()
        ctx.resolve_resource_uri = Mock(name='resolve_resource_uri')
        sub_resource = ctx.resolve_resource_uri.return_value
        Resource = Mock(name='resource')

        source_dict = {
            'foo': {
                'resourceUri': 'foo'
            },
        }
        target_obj = Mock(['save', 'pre_save'], name='target_obj',)
        field = SubObjectResourceField('foo', Resource)

        field.handle_incoming(ctx, source_dict, target_obj)

        self.assertEqual(sub_resource.model, target_obj.foo)