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


Python IDObfuscator.encode方法代码示例

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


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

示例1: test_update_dependencies_accept

# 需要导入模块: from share.util import IDObfuscator [as 别名]
# 或者: from share.util.IDObfuscator import encode [as 别名]
    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,代码行数:27,代码来源:test_change.py

示例2: test_no_icon

# 需要导入模块: from share.util import IDObfuscator [as 别名]
# 或者: from share.util.IDObfuscator import encode [as 别名]
    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,代码行数:31,代码来源:test_graphql.py

示例3: test_get_record

# 需要导入模块: from share.util import IDObfuscator [as 别名]
# 或者: from share.util.IDObfuscator import encode [as 别名]
 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,代码行数:9,代码来源:test_oaipmh.py

示例4: test_list_with_items

# 需要导入模块: from share.util import IDObfuscator [as 别名]
# 或者: from share.util.IDObfuscator import encode [as 别名]
 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,代码行数:33,代码来源:test_sitebanners.py

示例5: test_update_dependencies_accept

# 需要导入模块: from share.util import IDObfuscator [as 别名]
# 或者: from share.util.IDObfuscator import encode [as 别名]
    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,代码行数:30,代码来源:test_change.py

示例6: refs

# 需要导入模块: from share.util import IDObfuscator [as 别名]
# 或者: from share.util.IDObfuscator import encode [as 别名]
 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,代码行数:10,代码来源:change_builder.py

示例7: test_list_records

# 需要导入模块: from share.util import IDObfuscator [as 别名]
# 或者: from share.util.IDObfuscator import encode [as 别名]
 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,代码行数:10,代码来源:test_oaipmh.py

示例8: test_ignore_generic_work_type

# 需要导入模块: from share.util import IDObfuscator [as 别名]
# 或者: from share.util.IDObfuscator import encode [as 别名]
    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,代码行数:11,代码来源:test_change.py

示例9: assert_indexed

# 需要导入模块: from share.util import IDObfuscator [as 别名]
# 或者: from share.util.IDObfuscator import encode [as 别名]
 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,代码行数:12,代码来源:test_elastic.py

示例10: test_by_id

# 需要导入模块: from share.util import IDObfuscator [as 别名]
# 或者: from share.util.IDObfuscator import encode [as 别名]
    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,代码行数:15,代码来源:test_sources_endpoint.py

示例11: test_change_agent_type

# 需要导入模块: from share.util import IDObfuscator [as 别名]
# 或者: from share.util.IDObfuscator import encode [as 别名]
    def test_change_agent_type(self, change_factory, university_of_whales):
        cs = change_factory.from_graph({
            '@graph': [{
                '@id': IDObfuscator.encode(university_of_whales),
                '@type': 'consortium'
            }]
        }, disambiguate=True)

        assert models.Institution.objects.count() == 1
        assert models.Consortium.objects.count() == 0

        (org,) = cs.accept()

        assert org.type == 'share.consortium'
        assert org.id == university_of_whales.id
        assert org.name == university_of_whales.name
        assert models.Institution.objects.count() == 0
        assert models.Consortium.objects.count() == 1
开发者ID:Stevenholloway,项目名称:SHARE,代码行数:20,代码来源:test_change.py

示例12: test_work_type_stays_nongeneric

# 需要导入模块: from share.util import IDObfuscator [as 别名]
# 或者: from share.util.IDObfuscator import encode [as 别名]
    def test_work_type_stays_nongeneric(self, change_factory, all_about_anteaters):
        new_title = 'Some about Anteaters'
        cs = change_factory.from_graph({
            '@graph': [{
                '@id': IDObfuscator.encode(all_about_anteaters),
                '@type': 'creativework',
                'title': new_title
            }]
        }, disambiguate=True)

        assert all_about_anteaters.type == 'share.article'
        assert models.Publication.objects.count() == 1

        cs.accept()
        all_about_anteaters.refresh_from_db()

        assert all_about_anteaters.type == 'share.article'
        assert all_about_anteaters.title == new_title
开发者ID:Stevenholloway,项目名称:SHARE,代码行数:20,代码来源:test_change.py

示例13: test_can_delete_work

# 需要导入模块: from share.util import IDObfuscator [as 别名]
# 或者: from share.util.IDObfuscator import encode [as 别名]
    def test_can_delete_work(self, client, normalized_data_id):
        preprint = factories.AbstractCreativeWorkFactory(is_deleted=False)
        preprint.administrative_change(type='share.dataset')
        assert preprint.is_deleted is False

        encoded_id = IDObfuscator.encode(preprint)
        response = client.get('/api/v2/datasets/{}/'.format(encoded_id))
        assert response.status_code == 200

        preprint.administrative_change(is_deleted=True)
        assert preprint.is_deleted is True

        response = client.get('/api/v2/datasets/{}/'.format(encoded_id))
        assert response.status_code == 403
        assert response.json() == {"errors": [{"source": {"pointer": "/data"}, "detail": "This data set has been removed.", "status": "403"}]}

        response = client.get('/api/v2/datasets/')
        assert response.status_code == 200
        assert response.json() == {'data': [], 'links': {'next': None, 'prev': None}}
开发者ID:CenterForOpenScience,项目名称:SHARE,代码行数:21,代码来源:test_generated_endpoints.py

示例14: test_get_data

# 需要导入模块: from share.util import IDObfuscator [as 别名]
# 或者: from share.util.IDObfuscator import encode [as 别名]
    def test_get_data(self, generator, model, route, controlled_values, client, Graph, ingest):
        ingest(Graph(initial))

        graph = Graph(*generator)
        Regulator().regulate(graph)
        matches = Matcher(DatabaseStrategy()).find_all_matches(graph)

        for node in graph:
            if node.type == model:
                expected = node
                expected_id = IDObfuscator.encode(matches[node])
                break
        response = client.get('/api/v2/{}/{}/'.format(route, expected_id))

        actual = json.loads(response.content.decode(encoding='UTF-8'))

        assert response.status_code == 200
        assert actual['data']['id'] == expected_id
        assert actual['data']['attributes']['type'] == expected.type
        for value in controlled_values:
            assert actual['data']['attributes'][value] == expected[camelCase_to_underscore(value)]
开发者ID:CenterForOpenScience,项目名称:SHARE,代码行数:23,代码来源:test_generated_endpoints.py

示例15: delete_works

# 需要导入模块: from share.util import IDObfuscator [as 别名]
# 或者: from share.util.IDObfuscator import encode [as 别名]
    def delete_works(self, works_qs, source_config, dry_run, superfluous, delete_related):
        works_deleted = []

        if not superfluous:
            works_qs = works_qs.filter(is_deleted=False)
        for work in works_qs.prefetch_related('sources'):
            works_deleted.append(work.id)
            # If we've heard about the work from another source, just remove this source from it instead of deleting
            if len(work.sources.all()) > 1:
                self.stdout.write('{}: {}'.format(
                    self.style.WARNING('Removing {} from {}'.format(source_config.source.name, IDObfuscator.encode(work))),
                    work.title
                ))
                if not dry_run:
                    work.sources.remove(source_config.source.user)
                    # poke it to reindex
                    work.administrative_change(allow_empty=True)
            else:
                self.stdout.write('{}: {}'.format(
                    self.style.NOTICE('Deleting work {}'.format(IDObfuscator.encode(work))),
                    work.title
                ))
                if not dry_run:
                    work.administrative_change(is_deleted=True)
        self.stdout.write('\nProcessed {} works!'.format(len(works_deleted)), style_func=self.style.SUCCESS)
        if not delete_related:
            return

        self.stdout.write('\nNow deleting related works...\n')

        related_works = AbstractCreativeWork.objects.filter(
            Q(incoming_creative_work_relations__subject_id__in=works_deleted) | Q(outgoing_creative_work_relations__related_id__in=works_deleted),
            is_deleted=False,
            sources__id=source_config.source.user_id
        ).prefetch_related('sources')

        # Traverse related works only one level deep, please
        self.delete_works(related_works, source_config, dry_run, superfluous, False)
开发者ID:CenterForOpenScience,项目名称:SHARE,代码行数:40,代码来源:enforce_set_lists.py


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