Exemple #1
0
    def test_incoming_read_only(self):

        class Resource(ModelResource):
            model_class = Mock()
            pass

        field = URIResourceField(
            attribute='foo',
            resource_class=Resource,
            read_only=True,
        )

        source_dict = {
            'foo': 'uri://resources/2'
        }
        target_object = Mock([])

        related_model = mock_orm.Model(pk=2)

        ctx = mock_context()
        ctx.resolve_resource_uri = Mock(return_value=Resource(related_model))

        field.handle_incoming(ctx, source_dict, target_object)

        self.assertFalse(ctx.resolve_resource_uri.called)
        self.assertFalse(hasattr(target_object, 'foo'))
    def test_incoming(self):
        class Resource(ModelResource):
            model_class = Mock()
            pass

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

        source_dict = {'foo': 'uri://resources/2'}
        target_object = Mock()

        related_model = mock_orm.Model(pk=2)

        ctx = mock_context()
        ctx.resolve_resource_uri = Mock(return_value=Resource(related_model))

        field.handle_incoming(ctx, source_dict, target_object)

        ctx.resolve_resource_uri.assert_called_with('uri://resources/2')
        self.assertEqual(target_object.foo, related_model)
Exemple #3
0
    def test_incoming(self):

        class Resource(ModelResource):
            model_class = Mock()
            pass

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

        source_dict = {
            'foo': 'uri://resources/2'
        }
        target_object = Mock()

        related_model = mock_orm.Model(pk=2)

        ctx = mock_context()
        ctx.resolve_resource_uri = Mock(return_value=Resource(related_model))

        field.handle_incoming(ctx, source_dict, target_object)

        ctx.resolve_resource_uri.assert_called_with('uri://resources/2')
        self.assertEqual(target_object.foo, related_model)
    def test_incoming_read_only(self):
        class Resource(ModelResource):
            model_class = Mock()
            pass

        field = URIResourceField(
            attribute='foo',
            resource_class=Resource,
            read_only=True,
        )

        source_dict = {'foo': 'uri://resources/2'}
        target_object = Mock([])

        related_model = mock_orm.Model(pk=2)

        ctx = mock_context()
        ctx.resolve_resource_uri = Mock(return_value=Resource(related_model))

        field.handle_incoming(ctx, source_dict, target_object)

        self.assertFalse(ctx.resolve_resource_uri.called)
        self.assertFalse(hasattr(target_object, 'foo'))