Exemplo n.º 1
0
 class RelationshipResource(ResourceBase):
     _relationships = [
         Relationship('first_link', relation='RelatedResource'),
         Relationship('second_link',
                      relation='RelatedResource',
                      embedded=True)
     ]
Exemplo n.º 2
0
        class ItemSelection(Hierarchy, restmixins.CreateRetrieve):
            """
            The link between an Item object and the shopping basket
            'The item is selected to be in this basket'

            Retrieve: Collection of selection items in basket

            """
            manager = BasketManager
            resource_name = 'basket'
            pks = (
                'basket_key',
                'relation_key',
            )
            # Forced to use property map, otherwise the url is not properly built as the attribute is removed from
            # the list of attributes before the url is built.
            # The following does not work:
            # _relationships = (Relationship('basketid', relation='Basket'),)

            _relationships = (
                Relationship('basket_relation',
                             relation='Basket',
                             property_map=dict(basket_key='basket_key')),
                # Relationship('item_relation', relation='Item')
            )

            append_slash = False  # For clarity - this is the default
Exemplo n.º 3
0
        class BasketFails(restmixins.Retrieve, restmixins.Create):
            manager = Manager
            resource_name = 'basket'
            pks = ('basketid', )

            _relationships = (Relationship('basketid', relation='Item'), )
            append_slash = False  # Just for testing, so as not to get hit by the other issue
Exemplo n.º 4
0
        class MyResource(restmixins.Create):
            manager = Manager
            resource_name = 'myresource'
            pks = ('basketid', )

            _relationships = (Relationship('value_1',
                                           relation='SomethingElse'), )
Exemplo n.º 5
0
        class MyResource(restmixins.Create):
            manager = Manager
            resource_name = 'myresource'
            pks = ('basketid', )

            _relationships = (Relationship(
                'get_another_object',
                relation='SomethingElse',
                property_map=dict(value_1='value_1_translated')), )
Exemplo n.º 6
0
        class BasketWorks(restmixins.Retrieve, restmixins.Create):
            manager = Manager
            resource_name = 'basket'
            pks = ('basketid', )

            _relationships = (Relationship(
                'basket_relation',
                relation='Item',
                property_map=dict(basket_relation='basketid')), )
            append_slash = True  # Just for testing, so as not to get hit by the other issue
Exemplo n.º 7
0
    def test_generate_links(self):
        """
        Tests the private _generate_links staticmethod
        """
        class Related(ResourceBase):
            _pks = ['id']

        rel_list = [Relationship(name='first', relation='Related')]
        props = dict(first=dict(id=1, other_value='something'))
        resource_list = ResourceBase._generate_links(rel_list, props.copy())
        resource, name, embedded = resource_list[0]
        self.assertFalse(embedded)
        self.assertEqual(props['first'], resource.properties)
Exemplo n.º 8
0
        class Basket(restmixins.Retrieve, restmixins.Create):
            """
            The shopping basket which will contain the items

            Retrieve: Collection of baskets
            Create: New selection into existing or new basket
            """
            manager = Manager
            resource_name = 'basket'
            pks = ('basketid', )
            append_slash = True

            _relationships = (Relationship('basket_relation',
                                           relation='ItemSelection',
                                           property_map=dict(
                                               basketid='basketid',
                                               itemid='itemid')), )
Exemplo n.º 9
0
 class MyResource(ResourceBase):
     pks = ('id', )
     _links = (Relationship('my_resource',
                            relation='MyResource',
                            templated=True,
                            embedded=True), )
Exemplo n.º 10
0
 class ItemSelection(restmixins.Retrieve):
     manager = Manager
     resource_name = 'basket'
     _relationships = (Relationship('testtesttest',
                                    relation='MissingObject'), )
Exemplo n.º 11
0
 class LinkResource(ResourceBase):
     _links = [Relationship('first_link', relation='RelatedResource')]
Exemplo n.º 12
0
 class LinkListResource(ResourceBase):
     _resource_name = 'link_list_resource'
     _links = {
         'link': Relationship('linked_list', relation='Related')
     }
Exemplo n.º 13
0
 class RelationshipResource(ResourceBase):
     _resource_name = 'relationship_resource'
     _relationships = {
         'relationship': Relationship(property_map=dict(id='id'), relation='Related')
     }
Exemplo n.º 14
0
 class Resource2(ResourceBase):
     _pks = ['id']
     _relationships = [Relationship('resource1', relation='Resource1')]
Exemplo n.º 15
0
 class Resource(ResourceBase):
     _pks = ['id']
     _relationships = [
         Relationship('child', relation='Resource', embedded=True),
         Relationship('parent', relation='Resource')
     ]