Ejemplo n.º 1
0
def index_entities(collection, iterable, sync=False):
    queue = get_queue(collection, OP_INDEX)
    queue.progress.mark_pending(len(iterable))
    entities = []
    for entity in iterable:
        if entity.id is None:
            raise InvalidData("No ID for entity", errors=entity.to_dict())

        tag_entity(entity)
        entities.append(entity)
        if len(entities) >= BULK_PAGE:
            queue.progress.mark_finished(len(entities))
            index_bulk(collection, entities, sync=sync)
            entities = []

    if len(entities):
        queue.progress.mark_finished(len(entities))
        index_bulk(collection, entities, sync=sync)
    refresh_collection(collection)
Ejemplo n.º 2
0
    def test_entity_references(self):
        db_uri = self.get_fixture_path('experts.csv').as_uri()
        os.environ['ALEPH_TEST_BULK_CSV'] = db_uri
        yml_path = self.get_fixture_path('experts.yml')
        config = load_mapping_file(yml_path)
        coll = self.create_collection()
        queue = get_queue(coll, OP_BULKLOAD)
        bulk_load(queue, coll, config.get('experts'))
        _, headers = self.login(is_admin=True)

        query = '/api/2/entities?filter:schemata=Thing&q=Climate'
        res = self.client.get(query, headers=headers)
        assert res.json['total'] == 1, res.json
        grp_id = res.json['results'][0]['id']

        res = self.client.get('/api/2/entities/%s/references' % grp_id,
                              headers=headers)
        results = res.json['results']
        assert len(results) == 1, results
        assert results[0]['count'] == 3, results
Ejemplo n.º 3
0
 def setUp(self):
     super(BulkLoadTestCase, self).setUp()
     self.coll = self.create_collection()
     self.queue = get_queue(self.coll, OP_BULKLOAD)
Ejemplo n.º 4
0
    def setUp(self):
        super(XrefTestCase, self).setUp()
        self.user = self.create_user()
        self.coll_a = self.create_collection(creator=self.user, casefile=False)
        self.coll_b = self.create_collection(creator=self.user, casefile=False)
        self.coll_c = self.create_collection(creator=self.user, casefile=False)
        db.session.commit()
        self.queue = get_queue(self.coll_a, OP_XREF)

        _, headers = self.login(foreign_id=self.user.foreign_id)
        url = '/api/2/entities'

        entity = {
            'schema': 'Person',
            'collection_id': self.coll_a.id,
            'properties': {
                'name': 'Carlos Danger',
                'nationality': 'US'
            }
        }
        self.client.post(url,
                         data=json.dumps(entity),
                         headers=headers,
                         content_type='application/json')
        entity = {
            'schema': 'Person',
            'collection_id': self.coll_b.id,
            'properties': {
                'name': 'Carlos Danger',
                'nationality': 'US'
            }
        }
        self.client.post(url,
                         data=json.dumps(entity),
                         headers=headers,
                         content_type='application/json')
        entity = {
            'schema': 'LegalEntity',
            'collection_id': self.coll_b.id,
            'properties': {
                'name': 'Carlos Danger',
                'country': 'GB'
            }
        }
        self.client.post(url,
                         data=json.dumps(entity),
                         headers=headers,
                         content_type='application/json')
        entity = {
            'schema': 'Person',
            'collection_id': self.coll_b.id,
            'properties': {
                'name': 'Pure Risk',
                'nationality': 'US'
            }
        }
        self.client.post(url,
                         data=json.dumps(entity),
                         headers=headers,
                         content_type='application/json')

        entity = {
            'schema': 'LegalEntity',
            'collection_id': self.coll_c.id,
            'properties': {
                'name': 'Carlos Danger',
                'country': 'GB'
            }
        }
        self.client.post(url,
                         data=json.dumps(entity),
                         headers=headers,
                         content_type='application/json')
Ejemplo n.º 5
0
    def setUp(self):
        super(XrefApiTestCase, self).setUp()
        self.creator = self.create_user(foreign_id='creator')
        self.outsider = self.create_user(foreign_id='outsider')

        # First public collection and entities
        self.residents = self.create_collection(
            label='Residents of Habitat Ring',
            foreign_id='test_residents',
            creator=self.creator)
        self.grant_publish(self.residents)

        self.ent = Entity.create(
            {
                'schema': 'Person',
                'properties': {
                    'name': 'Elim Garak',
                }
            }, self.residents)
        db.session.add(self.ent)

        self.ent2 = Entity.create(
            {
                'schema': 'Person',
                'properties': {
                    'name': 'Leeta',
                }
            }, self.residents)
        db.session.add(self.ent2)

        # Second public collection and entities
        self.dabo = self.create_collection(label='Dabo Girls',
                                           foreign_id='test_dabo',
                                           creator=self.creator)
        self.grant_publish(self.dabo)

        self.ent3 = Entity.create(
            {
                'schema': 'Person',
                'properties': {
                    'name': 'MPella',
                }
            }, self.dabo)
        db.session.add(self.ent3)

        self.ent4 = Entity.create(
            {
                'schema': 'Person',
                'properties': {
                    'name': 'Leeta',
                }
            }, self.dabo)
        db.session.add(self.ent4)

        self.ent5 = Entity.create(
            {
                'schema': 'Person',
                'properties': {
                    'name': 'Mardah',
                }
            }, self.dabo)
        db.session.add(self.ent5)

        # Private collection and entities
        self.obsidian = self.create_collection(label='Obsidian Order',
                                               foreign_id='test_obsidian',
                                               creator=self.creator)

        self.ent6 = Entity.create(
            {
                'schema': 'Person',
                'properties': {
                    'name': 'Elim Garak',
                }
            }, self.obsidian)
        db.session.add(self.ent6)

        self.ent7 = Entity.create(
            {
                'schema': 'Person',
                'properties': {
                    'name': 'Enabran Tain',
                }
            }, self.obsidian)
        db.session.add(self.ent7)

        db.session.commit()
        index_entity(self.ent)
        index_entity(self.ent2)
        index_entity(self.ent3)
        index_entity(self.ent4)
        index_entity(self.ent5)
        index_entity(self.ent6)
        index_entity(self.ent7)
        self.queue = get_queue(self.residents, OP_XREF)