本文整理汇总了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'
示例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', [])
]))
])
示例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,
}
示例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
示例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
示例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},
}
}
示例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'
示例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,
}
示例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
示例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
示例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
示例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
示例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
示例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)
)
示例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