예제 #1
0
    def test_document_metas_from_data_with_multiple_metadata_claims(self):
        """
        It should create one DocumentMeta for each metadata claim.

        If document_data contains multiple metadata claims it should init one
        DocumentMeta for each claim.

        """
        claimant = 'http://example/claimant'
        document_data = {
            'title': 'the title',
            'description': 'the description',
            'site_title': 'the site title'
        }

        document_metas = parse_document_claims.document_metas_from_data(
            document_data, claimant)

        assert len(document_metas) == len(document_data.items())
        for key, value in document_data.items():
            assert {
                'type': key,
                'value': [value],
                'claimant': claimant,
                } in document_metas
예제 #2
0
파일: schemas.py 프로젝트: Cinemacloud/h
    def validate(self, data):
        appstruct = self.structure.validate(data)

        new_appstruct = {}

        # Some fields are not to be set by the user, ignore them.
        for field in PROTECTED_FIELDS:
            appstruct.pop(field, None)

        new_appstruct['userid'] = self.request.authenticated_userid

        new_appstruct['target_uri'] = appstruct.pop('uri', u'')
        new_appstruct['text'] = appstruct.pop('text', u'')
        new_appstruct['tags'] = appstruct.pop('tags', [])

        # Replace the client's complex permissions object with a simple shared
        # boolean.
        if appstruct.pop('permissions')['read'] == [new_appstruct['userid']]:
            new_appstruct['shared'] = False
        else:
            new_appstruct['shared'] = True

        # The 'target' dict that the client sends is replaced with a single
        # annotation.target_selectors whose value is the first selector in
        # the client'ss target.selectors list.
        # Anything else in the target dict, and any selectors after the first,
        # are discarded.
        target = appstruct.pop('target', [])
        if target:  # Replies and page notes don't have 'target'.
            target = target[0]  # Multiple targets are ignored.
            new_appstruct['target_selectors'] = target['selector']

        new_appstruct['groupid'] = appstruct.pop('group', u'__world__')

        new_appstruct['references'] = appstruct.pop('references', [])

        # Replies always get the same groupid as their parent. The parent's
        # groupid is added to the reply annotation later by the storage code.
        # Here we just delete any group sent by the client from replies.
        if new_appstruct['references'] and 'groupid' in new_appstruct:
            del new_appstruct['groupid']

        new_appstruct['extra'] = appstruct

        # Transform the "document" dict that the client posts into a convenient
        # format for creating DocumentURI and DocumentMeta objects later.
        document_data = appstruct.pop('document', {})
        document_uri_dicts = parse_document_claims.document_uris_from_data(
            copy.deepcopy(document_data),
            claimant=new_appstruct['target_uri'])
        document_meta_dicts = parse_document_claims.document_metas_from_data(
            copy.deepcopy(document_data),
            claimant=new_appstruct['target_uri'])
        new_appstruct['document'] = {
            'document_uri_dicts': document_uri_dicts,
            'document_meta_dicts': document_meta_dicts
        }

        return new_appstruct
예제 #3
0
파일: schemas.py 프로젝트: Cinemacloud/h
    def validate(self, data):
        appstruct = self.structure.validate(data)

        new_appstruct = {}

        # Some fields are not to be set by the user, ignore them.
        for field in PROTECTED_FIELDS:
            appstruct.pop(field, None)

        new_appstruct['userid'] = self.request.authenticated_userid

        new_appstruct['target_uri'] = appstruct.pop('uri', u'')
        new_appstruct['text'] = appstruct.pop('text', u'')
        new_appstruct['tags'] = appstruct.pop('tags', [])

        # Replace the client's complex permissions object with a simple shared
        # boolean.
        if appstruct.pop('permissions')['read'] == [new_appstruct['userid']]:
            new_appstruct['shared'] = False
        else:
            new_appstruct['shared'] = True

        # The 'target' dict that the client sends is replaced with a single
        # annotation.target_selectors whose value is the first selector in
        # the client'ss target.selectors list.
        # Anything else in the target dict, and any selectors after the first,
        # are discarded.
        target = appstruct.pop('target', [])
        if target:  # Replies and page notes don't have 'target'.
            target = target[0]  # Multiple targets are ignored.
            new_appstruct['target_selectors'] = target['selector']

        new_appstruct['groupid'] = appstruct.pop('group', u'__world__')

        new_appstruct['references'] = appstruct.pop('references', [])

        # Replies always get the same groupid as their parent. The parent's
        # groupid is added to the reply annotation later by the storage code.
        # Here we just delete any group sent by the client from replies.
        if new_appstruct['references'] and 'groupid' in new_appstruct:
            del new_appstruct['groupid']

        new_appstruct['extra'] = appstruct

        # Transform the "document" dict that the client posts into a convenient
        # format for creating DocumentURI and DocumentMeta objects later.
        document_data = appstruct.pop('document', {})
        document_uri_dicts = parse_document_claims.document_uris_from_data(
            copy.deepcopy(document_data), claimant=new_appstruct['target_uri'])
        document_meta_dicts = parse_document_claims.document_metas_from_data(
            copy.deepcopy(document_data), claimant=new_appstruct['target_uri'])
        new_appstruct['document'] = {
            'document_uri_dicts': document_uri_dicts,
            'document_meta_dicts': document_meta_dicts
        }

        return new_appstruct
예제 #4
0
    def test_document_metas_from_data(self, input_, output):
        claimant = 'http://example.com/claimant/'

        document_metas = parse_document_claims.document_metas_from_data(
            document_data=input_, claimant=claimant)

        assert document_metas == [{
            'type': output['type'],
            'value': output['value'],
            'claimant': claimant,
        }]
예제 #5
0
    def test_document_metas_from_data_ignores_links_list(self):
        """It should ignore the "link" list in the document_data."""
        document_data = {
            'link': [
                {'href': 'http://example.com/link'},
            ]
        }

        document_metas = parse_document_claims.document_metas_from_data(
            document_data, 'http://example/claimant')

        assert document_metas == []
예제 #6
0
    def test_document_metas_from_data(self, input_, output):
        claimant = 'http://example.com/claimant/'

        document_metas = parse_document_claims.document_metas_from_data(
            document_data=input_,
            claimant=claimant)

        assert document_metas == [{
            'type': output['type'],
            'value': output['value'],
            'claimant': claimant,
        }]
예제 #7
0
def _document(document, claimant):
    """
    Return document meta and document URI data from the given document dict.

    Transforms the "document" dict that the client posts into a convenient
    format for creating DocumentURI and DocumentMeta objects later.

    """
    document = document or {}
    document_uri_dicts = parse_document_claims.document_uris_from_data(
        copy.deepcopy(document), claimant=claimant)
    document_meta_dicts = parse_document_claims.document_metas_from_data(
        copy.deepcopy(document), claimant=claimant)
    return {
        'document_uri_dicts': document_uri_dicts,
        'document_meta_dicts': document_meta_dicts
    }
예제 #8
0
파일: schemas.py 프로젝트: bZichett/h
def _document(document, claimant):
    """
    Return document meta and document URI data from the given document dict.

    Transforms the "document" dict that the client posts into a convenient
    format for creating DocumentURI and DocumentMeta objects later.

    """
    document = document or {}
    document_uri_dicts = parse_document_claims.document_uris_from_data(
        copy.deepcopy(document),
        claimant=claimant)
    document_meta_dicts = parse_document_claims.document_metas_from_data(
        copy.deepcopy(document),
        claimant=claimant)
    return {
        'document_uri_dicts': document_uri_dicts,
        'document_meta_dicts': document_meta_dicts
    }