示例#1
0
    def test_uri_auth_adapter_with_related_manager_field(self):
        field = Mock(spec=IterableField, name='field')
        field.name = 'fieldName'
        field._resource_class.side_effect = self._passthrough_method
        field._compute_property.return_value = 'source_name'
        field.get_iterable.return_value = ['uri1', 'uri3', 'uri2']

        ctx = Mock(spec=['build_resource_uri'])
        ctx.build_resource_uri.side_effect = self._passthrough_method

        target_obj = Mock(spec=['fieldName'])
        target_obj.fieldName = Mock(spec=['all'])

        source_dict = {
            'source_name': [{
                'resourceUri': 'uri2'
            }, {
                'resourceUri': 'uri1'
            }]
        }

        name, source, target = uri_auth_adapter(field, ctx, source_dict,
                                                target_obj)
        self.assertEqual(name, 'source_name')
        self.assertEqual(source, ['uri1', 'uri2'])
        self.assertEqual(target, ['uri1', 'uri2', 'uri3'])
示例#2
0
    def test_uri_auth_adapter_with_uri_resource_field(self):
        field = Mock(spec=URIResourceField)
        field.name = 'fieldName'
        field._resource_class.side_effect = self._passthrough_method
        field._compute_property.return_value = 'source_name'

        ctx = Mock(spec=['build_resource_uri'])
        ctx.build_resource_uri.side_effect = self._passthrough_method

        target_obj = Mock(spec=['fieldName'])
        target_obj.fieldName = 'uri2'

        source_dict = {'source_name': 'uri1'}

        name, source, target = uri_auth_adapter(field, ctx, source_dict, target_obj)
        self.assertEqual(name, 'source_name')
        self.assertEqual(source, 'uri1')
        self.assertEqual(target, 'uri2')
示例#3
0
    def test_uri_auth_adapter_with_related_manager_field(self):
        field = Mock(spec=IterableField, name='field')
        field.name = 'fieldName'
        field._resource_class.side_effect = self._passthrough_method
        field._compute_property.return_value = 'source_name'
        field.get_iterable.return_value = ['uri1', 'uri3', 'uri2']

        ctx = Mock(spec=['build_resource_uri'])
        ctx.build_resource_uri.side_effect = self._passthrough_method

        target_obj = Mock(spec=['fieldName'])
        target_obj.fieldName = Mock(spec=['all'])

        source_dict = {'source_name': [{'resourceUri': 'uri2'}, {'resourceUri': 'uri1'}]}

        name, source, target = uri_auth_adapter(field, ctx, source_dict, target_obj)
        self.assertEqual(name, 'source_name')
        self.assertEqual(source, ['uri1', 'uri2'])
        self.assertEqual(target, ['uri1', 'uri2', 'uri3'])
示例#4
0
    def test_uri_auth_adapter_with_uri_resource_field(self):
        field = Mock(spec=URIResourceField)
        field.name = 'fieldName'
        field._resource_class.side_effect = self._passthrough_method
        field._compute_property.return_value = 'source_name'

        ctx = Mock(spec=['build_resource_uri'])
        ctx.build_resource_uri.side_effect = self._passthrough_method

        target_obj = Mock(spec=['fieldName'])
        target_obj.fieldName = 'uri2'

        source_dict = {'source_name': 'uri1'}

        name, source, target = uri_auth_adapter(field, ctx, source_dict,
                                                target_obj)
        self.assertEqual(name, 'source_name')
        self.assertEqual(source, 'uri1')
        self.assertEqual(target, 'uri2')