def test_provides_resource(self): coll = create_collection() mb = next(iter(coll)) self.assert_true(provides_member_resource(type(mb))) self.assert_true(provides_member_resource(mb)) self.assert_false(provides_member_resource(coll)) self.assert_true(provides_resource(type(mb))) self.assert_true(provides_resource(mb)) self.assert_true(provides_collection_resource(type(coll))) self.assert_true(provides_collection_resource(coll)) self.assert_false(provides_collection_resource(mb)) self.assert_true(provides_resource(type(coll))) self.assert_true(provides_resource(coll)) self.assert_false(provides_resource(mb.get_entity()))
def test_provides_resource(self): coll = create_collection() mb = iter(coll).next() self.assert_true(provides_member_resource(type(mb))) self.assert_true(provides_member_resource(mb)) self.assert_false(provides_member_resource(coll)) self.assert_true(provides_resource(type(mb))) self.assert_true(provides_resource(mb)) self.assert_true(provides_collection_resource(type(coll))) self.assert_true(provides_collection_resource(coll)) self.assert_false(provides_collection_resource(mb)) self.assert_true(provides_resource(type(coll))) self.assert_true(provides_resource(coll)) self.assert_false(provides_resource(mb.get_entity()))
def create_from_resource(cls, resource): if provides_member_resource(resource): kind = ResourceKinds.MEMBER elif provides_collection_resource(resource): kind = ResourceKinds.COLLECTION else: raise ValueError('"%s" is not a resource.' % resource) return cls.create(resource_to_url(resource), kind, relation=resource.relation, title=resource.title)
def create_from_resource(cls, resource): if provides_member_resource(resource): kind = RESOURCE_KINDS.MEMBER opts = dict(id=resource.id) elif provides_collection_resource(resource): kind = RESOURCE_KINDS.COLLECTION opts = {} else: raise ValueError('"%s" is not a resource.' % resource) return cls.create(resource_to_url(resource), kind, relation=resource.relation, title=resource.title, **opts)
def __init__(self, mapping_registry, mapped_class, data_element_class, configuration): """ :param configuration: mapping configuration object. """ self.__mp_reg = mapping_registry self.__mapped_cls = mapped_class self.__is_collection_mapping = \ provides_collection_resource(mapped_class) self.__de_cls = data_element_class self.__configuration = configuration # self.__mapped_attr_cache = {}
def __init__(self, mapping_registry, mapped_class, data_element_class, configuration): """ :param configuration: Mapping configuration object. """ self.__mp_reg = mapping_registry self.__mapped_cls = mapped_class self.__is_collection_mapping = \ provides_collection_resource(mapped_class) self.__de_cls = data_element_class # List of configurations; the last one added is the active one. self.__configurations = [configuration] # self.__mapped_attr_cache = {}