def test_similar_entity(self): self.login(is_admin=True) url = '/api/1/entities' data = { '$schema': '/entity/person.json#', 'name': "Osama bin Laden", 'collection_id': [self.col.id] } res = self.client.post(url, data=json.dumps(data), content_type='application/json') data = { '$schema': '/entity/person.json#', 'name': "Osama ben Ladyn", 'collection_id': [self.col.id] } res = self.client.post(url, data=json.dumps(data), content_type='application/json') optimize_search() res = self.client.get('/api/1/entities/%s/similar' % res.json['id']) assert res.status_code == 200, (res.status_code, res.json) data = res.json assert len(data['results']) == 1, data assert 'Laden' in data['results'][0]['name'], data assert 'Pooh' not in res.data, res.data
def load_fixtures(self, file_name, process_documents=True): filepath = os.path.abspath(os.path.join(FIXTURES, file_name)) load_fixtures(db, loaders.load(filepath)) db.session.commit() if process_documents: for doc_id, in Document.all_ids(): analyze_document(doc_id) optimize_search()
def test_delete_source(self): source = Source.by_id(1000) res = self.client.get('/api/1/query?q="mention fruit"') assert res.json['total'] == 1, res.json delete_source(source.id) optimize_search() res = self.client.get('/api/1/query?q="mention fruit"') assert res.json['total'] == 0, res.json
def load_fixtures(self, file_name, process_documents=True): filepath = self.get_fixture_path(file_name) load_fixtures(db, loaders.load(filepath)) db.session.commit() if process_documents: for doc_id, in Document.all_ids(): analyze_document(doc_id) optimize_search()
def test_delete_source(self): collection = Collection.by_id(1000) res = self.client.get('/api/1/query?q="mention fruit"') assert res.json['total'] == 1, res.json delete_collection(collection.id) optimize_search() res = self.client.get('/api/1/query?q="mention fruit"') assert res.json['total'] == 0, res.json
def test_suggest_entity(self): self.login(is_admin=True) url = '/api/1/entities' data = { '$schema': '/entity/person.json#', 'name': "Osama bin Laden", 'collection_id': [self.col.id] } res = self.client.post(url, data=json.dumps(data), content_type='application/json') optimize_search() res = self.client.get('/api/1/entities/_suggest?prefix=osa') assert res.status_code == 200, (res.status_code, res.json) data = res.json assert len(data['results']) == 1, data assert 'Laden' in data['results'][0]['name'], data
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