本文整理汇总了Python中aleph.model.Entity.update方法的典型用法代码示例。如果您正苦于以下问题:Python Entity.update方法的具体用法?Python Entity.update怎么用?Python Entity.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aleph.model.Entity
的用法示例。
在下文中一共展示了Entity.update方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: EntitiesApiTestCase
# 需要导入模块: from aleph.model import Entity [as 别名]
# 或者: from aleph.model.Entity import update [as 别名]
class EntitiesApiTestCase(TestCase):
def setUp(self):
super(EntitiesApiTestCase, self).setUp()
self.rolex = self.create_user(foreign_id='user_3')
self.col = Collection()
self.col.label = 'Test Collection'
self.col.foreign_id = 'test_coll_entities_api'
db.session.add(self.col)
db.session.flush()
self.ent = Entity()
self.ent.collections = [self.col]
self.ent.update({
'name': 'Winnie the Pooh',
'jurisdiction_code': 'pa',
'identifiers': [{
'scheme': 'wikipedia',
'identifier': 'en:Winnie-the-Pooh'
}]
})
db.session.add(self.ent)
db.session.commit()
def test_index(self):
index_entity(self.ent)
optimize_search()
res = self.client.get('/api/1/entities?facet=collections')
assert res.status_code == 200, res
assert res.json['total'] == 0, res.json
assert len(res.json['facets']['collections']['values']) == 0, res.json
self.login(is_admin=True)
res = self.client.get('/api/1/entities?facet=collections')
assert res.status_code == 200, res
assert res.json['total'] == 1, res.json
assert len(res.json['facets']['collections']['values']) == 1, res.json
col0 = res.json['facets']['collections']['values'][0]
assert col0['id'] == self.col.id, res.json
assert col0['label'] == self.col.label, res.json
assert len(res.json['facets']) == 1, res.json
res = self.client.get('/api/1/entities?facet=jurisdiction_code')
assert len(res.json['facets']) == 2, res.json
assert 'values' in res.json['facets']['jurisdiction_code'], res.json
def test_all(self):
res = self.client.get('/api/1/entities/_all')
assert res.status_code == 200, res
assert res.json['total'] == 0, res.json
self.login(is_admin=True)
res = self.client.get('/api/1/entities/_all')
assert res.status_code == 200, res
assert res.json['total'] == 1, res.json
assert res.json['results'][0]['id'] == self.ent.id, res.json
def test_view(self):
res = self.client.get('/api/1/entities/%s' % self.ent.id)
assert res.status_code == 403, res
self.login(is_admin=True)
res = self.client.get('/api/1/entities/%s' % self.ent.id)
assert res.status_code == 200, res
assert 'entity/entity' in res.json['$schema'], res.json
assert 'Winnie' in res.json['name'], res.json
def test_lookup(self):
args = '?scheme=wikipedia&identifier=en:Winnie-the-Pooh'
res = self.client.get('/api/1/entities/_lookup%s' % args)
assert res.status_code == 403, res
self.login(is_admin=True)
res = self.client.get('/api/1/entities/_lookup%s' % args)
assert res.status_code == 200, res
assert 'entity/entity' in res.json['$schema'], res.json
assert 'Winnie' in res.json['name'], res.json
args = args + 'xxx'
res = self.client.get('/api/1/entities/_lookup%s' % args)
assert res.status_code == 404, res
def test_update(self):
self.login(is_admin=True)
url = '/api/1/entities/%s' % self.ent.id
res = self.client.get(url)
assert res.status_code == 200, res
data = res.json
data['name'] = 'Winne the little Shit'
res = self.client.post(url, data=json.dumps(data),
content_type='application/json')
assert res.status_code == 200, res.json
assert 'little' in res.json['name'], res.json
data['name'] = ''
res = self.client.post(url, data=json.dumps(data),
content_type='application/json')
assert res.status_code == 400, res.json
def test_create(self):
self.login(is_admin=True)
url = '/api/1/entities'
data = {
'$schema': '/entity/building.json',
'name': "Our house",
'collection_id': [self.col.id],
#.........这里部分代码省略.........
示例2: CollectionsApiTestCase
# 需要导入模块: from aleph.model import Entity [as 别名]
# 或者: from aleph.model.Entity import update [as 别名]
class CollectionsApiTestCase(TestCase):
def setUp(self):
super(CollectionsApiTestCase, self).setUp()
self.rolex = self.create_user(foreign_id='user_3')
self.col = Collection()
self.col.label = 'Test Collection'
self.col.foreign_id = 'test_coll_entities_api'
db.session.add(self.col)
db.session.flush()
self.ent = Entity()
self.ent.collection = self.col
self.ent.update({
'name': 'Winnie the Pooh'
})
db.session.add(self.ent)
db.session.commit()
def test_index(self):
res = self.client.get('/api/1/collections')
assert res.status_code == 200, res
assert res.json['total'] == 0, res.json
self.login(is_admin=True)
res = self.client.get('/api/1/collections')
assert res.status_code == 200, res
assert res.json['total'] == 1, res.json
def test_view(self):
res = self.client.get('/api/1/collections/%s' % self.col.id)
assert res.status_code == 403, res
self.login(is_admin=True)
res = self.client.get('/api/1/collections/%s' % self.col.id)
assert res.status_code == 200, res
assert 'test_coll' in res.json['foreign_id'], res.json
assert 'Winnie' not in res.json['label'], res.json
def test_update(self):
self.login(is_admin=True)
url = '/api/1/collections/%s' % self.col.id
res = self.client.get(url)
assert res.status_code == 200, res
data = res.json
data['label'] = 'Collected Collection'
res = self.client.post(url, data=json.dumps(data),
content_type='application/json')
assert res.status_code == 200, res.json
assert 'Collected' in res.json['label'], res.json
res = self.client.get(url)
data['label'] = ''
res = self.client.post(url, data=json.dumps(data),
content_type='application/json')
assert res.status_code == 400, res.json
res = self.client.get(url)
data['category'] = 'banana'
res = self.client.post(url, data=json.dumps(data),
content_type='application/json')
assert res.status_code == 400, res.json
def test_delete(self):
self.login(is_admin=True)
url = '/api/1/collections/%s' % self.col.id
res = self.client.get(url)
assert res.status_code == 200, res
res = self.client.delete(url)
assert res.status_code == 200, res
res = self.client.get(url)
assert res.status_code == 404, res