当前位置: 首页>>代码示例>>Python>>正文


Python util.IDObfuscator类代码示例

本文整理汇总了Python中share.util.IDObfuscator的典型用法代码示例。如果您正苦于以下问题:Python IDObfuscator类的具体用法?Python IDObfuscator怎么用?Python IDObfuscator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了IDObfuscator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_update_dependencies_accept

    def test_update_dependencies_accept(self, john_doe, normalized_data_id):
        graph = ChangeGraph([{
            '@id': IDObfuscator.encode(john_doe),
            '@type': 'person',
            'given_name': 'Jane',
        }, {
            '@id': '_:456',
            '@type': 'Creator',
            'agent': {'@id': IDObfuscator.encode(john_doe), '@type': 'person'},
            'creative_work': {'@id': '_:789', '@type': 'preprint'},
        }, {
            '@id': '_:789',
            '@type': 'preprint',
            'title': 'All About Cats',
        }])

        change_set = models.ChangeSet.objects.from_graph(graph, normalized_data_id)

        change_set.accept()

        john_doe.refresh_from_db()

        assert john_doe.given_name == 'Jane'
        assert models.Preprint.objects.filter(agent_relations__agent=john_doe).count() == 1
        assert models.Preprint.objects.filter(agent_relations__agent=john_doe).first().title == 'All About Cats'
开发者ID:Stevenholloway,项目名称:SHARE,代码行数:25,代码来源:test_change.py

示例2: test_no_icon

    def test_no_icon(self):
        x = factories.AbstractCreativeWorkFactory()
        source = factories.SourceFactory(icon='')
        x.sources.add(source.user)

        # Have to use % formats because of {}s everywhere
        result = schema.execute('''
            query {
                creativeWork(id: "%s") {
                    id,
                    title,
                    description,
                    sources {
                        title
                    }
                }
            }
        ''' % (IDObfuscator.encode(x), ))

        assert not result.errors

        assert result.data == OrderedDict([
            ('creativeWork', OrderedDict([
                ('id', IDObfuscator.encode(x)),
                ('title', x.title),
                ('description', x.description),
                ('sources', [])
            ]))
        ])
开发者ID:leb2dg,项目名称:SHARE,代码行数:29,代码来源:test_graphql.py

示例3: test_by_id

    def test_by_id(self, client):
        source = Source.objects.first()
        resp = client.get('{}{}/'.format(self.endpoint, IDObfuscator.encode(source)))

        assert resp.status_code == 200
        assert IDObfuscator.load(resp.json()['data']['id']) == source
        assert resp.json()['data']['type'] == 'Source'
        assert resp.json()['data']['attributes'] == {
            'name': source.name,
            'icon': 'http://testserver{}'.format(source.icon.url),
            'homePage': source.home_page,
            'longTitle': source.long_title,
        }
开发者ID:CenterForOpenScience,项目名称:SHARE,代码行数:13,代码来源:test_sources_endpoint.py

示例4: get_object

    def get_object(self):
        queryset = self.filter_queryset(self.get_queryset())

        # Perform the lookup filtering.
        lookup_url_kwarg = self.lookup_url_kwarg or self.lookup_field

        assert lookup_url_kwarg in self.kwargs, (
            'Expected view %s to be called with a URL keyword argument '
            'named "%s". Fix your URL conf, or set the `.lookup_field` '
            'attribute on the view correctly.' %
            (self.__class__.__name__, lookup_url_kwarg)
        )

        try:
            (model, decoded_pk) = IDObfuscator.decode(self.kwargs[lookup_url_kwarg])
            concrete_model = self.serializer_class.Meta.model._meta.concrete_model
            if model is not concrete_model:
                raise serializers.ValidationError('The specified ID refers to an {}. Expected {}'.format(model._meta.model_name, concrete_model._meta.model_name))
        except InvalidID:
            raise serializers.ValidationError('Invalid ID')

        filter_kwargs = {self.lookup_field: decoded_pk}
        obj = get_object_or_404(queryset, **filter_kwargs)

        # May raise a permission denied
        self.check_object_permissions(self.request, obj)

        return obj
开发者ID:leb2dg,项目名称:SHARE,代码行数:28,代码来源:share.py

示例5: test_get_record

 def test_get_record(self, post, all_about_anteaters):
     ant_id = 'oai:share.osf.io:{}'.format(IDObfuscator.encode(all_about_anteaters))
     parsed = oai_request({'verb': 'GetRecord', 'metadataPrefix': 'oai_dc', 'identifier': ant_id}, post)
     records = parsed.xpath('//ns0:GetRecord/ns0:record', namespaces=NAMESPACES)
     assert len(records) == 1
     assert all_about_anteaters.title == records[0].xpath('ns0:metadata/oai_dc:dc/dc:title', namespaces=NAMESPACES)[0].text
     assert ant_id == records[0].xpath('ns0:header/ns0:identifier', namespaces=NAMESPACES)[0].text
开发者ID:CenterForOpenScience,项目名称:SHARE,代码行数:7,代码来源:test_oaipmh.py

示例6: test_list_with_items

 def test_list_with_items(self, client):
     user = ShareUserFactory()
     banner = SiteBanner.objects.create(
         title='Why wasnt I there',
         description='I could have saved them',
         created_by=user,
         last_modified_by=user,
     )
     resp = client.get('/api/v2/site_banners/')
     assert resp.status_code == 200
     assert resp.json() == {
         'data': [{
             'id': IDObfuscator.encode(banner),
             'type': 'SiteBanner',
             'attributes': {
                 'color': 'info',
                 'icon': 'exclamation',
                 'title': 'Why wasnt I there',
                 'description': 'I could have saved them',
             }
         }],
         'links': {
             'first': 'http://testserver/api/v2/site_banners/?page=1',
             'last': 'http://testserver/api/v2/site_banners/?page=1',
             'next': None,
             'prev': None,
         },
         'meta': {
             'pagination': {'count': 1, 'pages': 1, 'page': 1},
         }
     }
开发者ID:CenterForOpenScience,项目名称:SHARE,代码行数:31,代码来源:test_sitebanners.py

示例7: test_update_dependencies_accept

    def test_update_dependencies_accept(self, john_doe, normalized_data):
        john_doe_id = IDObfuscator.encode(john_doe)
        graph = MutableGraph.from_jsonld([{
            '@id': john_doe_id,
            '@type': 'person',
            'given_name': 'Jane',
        }, {
            '@id': '_:456',
            '@type': 'Creator',
            'agent': {'@id': john_doe_id, '@type': 'person'},
            'creative_work': {'@id': '_:789', '@type': 'preprint'},
        }, {
            '@id': '_:789',
            '@type': 'preprint',
            'title': 'All About Cats',
        }])

        change_set = ChangeSetBuilder(graph, normalized_data, matches={
            john_doe_id: john_doe,
        }).build_change_set()

        change_set.accept()

        john_doe.refresh_from_db()

        assert john_doe.given_name == 'Jane'
        assert models.Preprint.objects.filter(agent_relations__agent=john_doe).count() == 1
        assert models.Preprint.objects.filter(agent_relations__agent=john_doe).first().title == 'All About Cats'
开发者ID:CenterForOpenScience,项目名称:SHARE,代码行数:28,代码来源:test_change.py

示例8: refs

 def refs(n):
     if isinstance(n, list):
         return [refs(node) for node in n]
     instance = self._get_match(n)
     return {
         '@id': IDObfuscator.encode(instance) if instance else n.id,
         '@type': n.type,
     }
开发者ID:CenterForOpenScience,项目名称:SHARE,代码行数:8,代码来源:change_builder.py

示例9: test_list_records

 def test_list_records(self, post, all_about_anteaters, django_assert_num_queries):
     with django_assert_num_queries(2):
         parsed = oai_request({'verb': 'ListRecords', 'metadataPrefix': 'oai_dc'}, post)
     records = parsed.xpath('//ns0:ListRecords/ns0:record', namespaces=NAMESPACES)
     assert len(records) == 1
     assert all_about_anteaters.title == records[0].xpath('ns0:metadata/oai_dc:dc/dc:title', namespaces=NAMESPACES)[0].text
     ant_id = 'oai:share.osf.io:{}'.format(IDObfuscator.encode(all_about_anteaters))
     assert ant_id == records[0].xpath('ns0:header/ns0:identifier', namespaces=NAMESPACES)[0].text
开发者ID:CenterForOpenScience,项目名称:SHARE,代码行数:8,代码来源:test_oaipmh.py

示例10: resolve_oai_identifier

 def resolve_oai_identifier(self, identifier):
     try:
         splid = identifier.split(self.IDENTIFER_DELIMITER)
         if len(splid) != 3 or splid[:2] != ['oai', self.REPOSITORY_IDENTIFIER]:
             raise InvalidID(identifier)
         return IDObfuscator.resolve(splid[-1])
     except (AbstractCreativeWork.DoesNotExist, InvalidID):
         self.errors.append(oai_errors.BadRecordID(identifier))
         return None
开发者ID:CenterForOpenScience,项目名称:SHARE,代码行数:9,代码来源:repository.py

示例11: initial_pass

 def initial_pass(self, nodes):
     for node in nodes:
         if str(node.id).startswith('_:'):
             continue
         try:
             match = IDObfuscator.resolve(node.id)
             self.add_match(node, match)
         except InvalidID:
             pass
开发者ID:CenterForOpenScience,项目名称:SHARE,代码行数:9,代码来源:database.py

示例12: test_ignore_generic_work_type

    def test_ignore_generic_work_type(self, change_factory, all_about_anteaters):
        cs = change_factory.from_graph({
            '@graph': [{
                '@id': IDObfuscator.encode(all_about_anteaters),
                '@type': 'creativework'
            }]
        }, disambiguate=True)

        assert cs is None
开发者ID:Stevenholloway,项目名称:SHARE,代码行数:9,代码来源:test_change.py

示例13: assert_indexed

 def assert_indexed(self):
     encoded_id = IDObfuscator.encode(self.work)
     doc = self.elastic.es_client.get(
         index=self.elastic.es_index,
         doc_type='creativeworks',
         id=encoded_id
     )
     assert doc['found'] is True
     assert doc['_id'] == encoded_id
     return doc
开发者ID:CenterForOpenScience,项目名称:SHARE,代码行数:10,代码来源:test_elastic.py

示例14: get_raws

def get_raws(obj):
    if isinstance(obj, str):
        model, id = IDObfuscator.decode(obj)
    else:
        model = obj._meta.model
        id = obj.id
    return RawData.objects.filter(
        normalizeddata__changeset__changes__target_id=id,
        normalizeddata__changeset__changes__target_type=ContentType.objects.get_for_model(model, for_concrete_model=True)
    )
开发者ID:Stevenholloway,项目名称:SHARE,代码行数:10,代码来源:shell_util.py

示例15: populate_types

def populate_types(data):
    model = apps.get_model(data['type'])
    data['id'] = IDObfuscator.encode_id(data['id'], model)
    data['type'] = model._meta.verbose_name
    data['types'] = []
    for parent in model.mro():
        if not parent._meta.proxy:
            break
        data['types'].append(parent._meta.verbose_name)

    return data
开发者ID:CenterForOpenScience,项目名称:SHARE,代码行数:11,代码来源:util.py


注:本文中的share.util.IDObfuscator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。