def test_get_category_for_success(self):
        '''
        Tests if a mixin can be created.
        '''

        # disabling 'Method could be func' pylint check (pyunit fault :-))
        # pylint: disable=R0201

        # mixin check...
        tmp = 'foo; scheme="http://example.com#"; location="/foo_bar/"'
        parser.get_category(tmp, self.registry.get_categories(), is_mixin=True)
    def test_get_category_for_success(self):
        '''
        Tests if a mixin can be created.
        '''

        # disabling 'Method could be func' pylint check (pyunit fault :-))
        # pylint: disable=R0201

        # mixin check...
        tmp = 'foo; scheme="http://example.com#"; location="/foo_bar/"'
        parser.get_category(tmp, self.registry.get_categories(), is_mixin=True)
 def test_get_category_for_sanity(self):
     '''
     Simple sanity check...
     '''
     res = parser.get_category(parser.get_category_str(self.compute),
                               self.registry.get_categories())
     self.assertEqual(res, self.compute)
 def test_get_category_for_sanity(self):
     '''
     Simple sanity check...
     '''
     res = parser.get_category(parser.get_category_str(self.compute),
                       self.registry.get_categories())
     self.assertEqual(res, self.compute)
Example #5
0
def _to_action(data, registry):
    """
    Create an action from an HTTP data object.

    data -- the HTTP data.
    registry -- The registry used for this call.
    """
    action = parser.get_category(data.categories[0].strip(), registry.get_categories())

    return action
Example #6
0
def _to_action(data, registry):
    '''
    Create an action from an HTTP data object.

    data -- the HTTP data.
    registry -- The registry used for this call.
    '''
    action = parser.get_category(data.categories[0].strip(),
                                 registry.get_categories())

    return action
Example #7
0
def _to_mixins(data, registry):
    """
    Create a Mixin from an HTTP data object.

    data -- the HTTP data.
    registry -- The registry used for this call.
    """
    result = []
    for cat_str in data.categories:
        result.append(parser.get_category(cat_str, registry.get_categories(), is_mixin=True))

    return result
Example #8
0
def _to_mixins(data, registry):
    '''
    Create a Mixin from an HTTP data object.

    data -- the HTTP data.
    registry -- The registry used for this call.
    '''
    result = []
    for cat_str in data.categories:
        result.append(
            parser.get_category(cat_str,
                                registry.get_categories(),
                                is_mixin=True))

    return result
Example #9
0
def _get_filter(data, registry):
    '''
    Parse categories and attributes from the request.

    data -- the HTTP data.
    registry -- The registry used for this call.
    '''
    categories = []
    attributes = {}

    for cat in data.categories:
        categories.append(parser.get_category(cat, registry.get_categories()))

    for attr in data.attributes:
        key, value = parser.get_attributes(attr)
        attributes[key] = value

    return categories, attributes
Example #10
0
def _get_filter(data, registry):
    """
    Parse categories and attributes from the request.

    data -- the HTTP data.
    registry -- The registry used for this call.
    """
    categories = []
    attributes = {}

    for cat in data.categories:
        categories.append(parser.get_category(cat, registry.get_categories()))

    for attr in data.attributes:
        key, value = parser.get_attributes(attr)
        attributes[key] = value

    return categories, attributes
Example #11
0
def _to_entity(data, def_kind, registry):
    '''
    Extract an entity from the HTTP data object.

    kind -- The kind definition.
    registry -- The registry.
    '''

    # disable 'Too many local vars' pylint check (It's a bit ugly but will do)
    # disable 'Too many branches' pylint check (Needs to be improved)
    # pylint: disable=R0914,R0912

    kind = None
    mixins = []

    # first kind & mixins
    kind_found = False
    for category_string in data.categories:
        category = parser.get_category(category_string.strip(),
                                       registry.get_categories())
        if repr(category) == 'kind' and not kind_found:
            kind = category
            kind_found = True
        else:
            mixins.append(category)

    # the attributes
    attributes = {}
    for attr_string in data.attributes:
        key, value = parser.get_attributes(attr_string)
        attributes[key] = value

    # now create the entity
    if kind_found is False and def_kind is None:
        raise AttributeError('Could not find a valid kind.')
    elif def_kind is not None:
        kind = def_kind

    if Resource.kind in kind.related:
        # links
        entity = Resource(None, kind, mixins, [])
        for link_string in data.links:
            entity.links.append(
                parser.get_link(link_string.strip(), entity, registry))
    elif Link.kind in kind.related:
        try:
            source_attr = attributes['occi.core.source']
            target_attr = attributes['occi.core.target']

            if source_attr.find(registry.get_hostname()) == 0:
                source_attr = source_attr.replace(registry.get_hostname(), '')
            if target_attr.find(registry.get_hostname()) == 0:
                target_attr = target_attr.replace(registry.get_hostname(), '')

            source = registry.get_resource(source_attr)
            target = registry.get_resource(target_attr)
        except KeyError:
            raise AttributeError('Both occi.core.[source, target]' +
                                 ' attributes need to be resources.')
        entity = Link(None, kind, mixins, source, target)
    else:
        raise AttributeError('This kind seems not to be related to either' +
                             ' resource or link.')

    entity.attributes = attributes
    return entity
Example #12
0
def _to_entity(data, def_kind, registry):
    """
    Extract an entity from the HTTP data object.

    kind -- The kind definition.
    registry -- The registry.
    """

    # disable 'Too many local vars' pylint check (It's a bit ugly but will do)
    # disable 'Too many branches' pylint check (Needs to be improved)
    # pylint: disable=R0914,R0912

    kind = None
    mixins = []

    # first kind & mixins
    kind_found = False
    for category_string in data.categories:
        category = parser.get_category(category_string.strip(), registry.get_categories())
        if repr(category) == "kind" and not kind_found:
            kind = category
            kind_found = True
        else:
            mixins.append(category)

    # the attributes
    attributes = {}
    for attr_string in data.attributes:
        key, value = parser.get_attributes(attr_string)
        attributes[key] = value

    # now create the entity
    if kind_found is False and def_kind is None:
        raise AttributeError("Could not find a valid kind.")
    elif def_kind is not None:
        kind = def_kind

    if Resource.kind in kind.related:
        # links
        entity = Resource(None, kind, mixins, [])
        for link_string in data.links:
            entity.links.append(parser.get_link(link_string.strip(), entity, registry))
    elif Link.kind in kind.related:
        try:
            source_attr = attributes["occi.core.source"]
            target_attr = attributes["occi.core.target"]

            if source_attr.find(registry.get_hostname()) == 0:
                source_attr = source_attr.replace(registry.get_hostname(), "")
            if target_attr.find(registry.get_hostname()) == 0:
                target_attr = target_attr.replace(registry.get_hostname(), "")

            source = registry.get_resource(source_attr)
            target = registry.get_resource(target_attr)
        except KeyError:
            raise AttributeError("Both occi.core.[source, target]" + " attributes need to be resources.")
        entity = Link(None, kind, mixins, source, target)
    else:
        raise AttributeError("This kind seems not to be related to either" + " resource or link.")

    entity.attributes = attributes
    return entity